Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6698133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:32:30+00:00 2026-05-26T06:32:30+00:00

I am new to Android development. I am using ListView to list some data

  • 0

I am new to Android development. I am using ListView to list some data from SQLite database.
my Main.xml file looks like:

<?xml version="1.0" encoding="utf-8"?>
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/inspections"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
            <!-- Header -->
    <LinearLayout android:id="@+id/header"
        android:background="#ff347c12"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        >
        <TextView android:id="@+id/item1"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:width="100dip"
            android:height="30dip"
            android:text="Id"
        />
        <TextView android:id="@+id/item2"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:text="Customer"
            android:width="100dip"
            android:height="30dip"
        />
        <TextView android:id="@+id/item3"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:text="Contract"
            android:width="100dip"
            android:height="30dip"
        />
        <TextView android:id="@+id/item4"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:text="Inspector"
            android:width="100dip"
            android:height="30dip"
        />
    </LinearLayout>

    <!-- List Divider -->
    <View android:layout_width="fill_parent"
        android:layout_height="1dip"
        android:background="?android:attr/listDivider" />

    <!-- ListView (grid_items) -->
    <LinearLayout android:id="@+id/layout"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent">
        <ListView android:id="@+id/listview"
            android:layout_height="fill_parent"
            android:layout_width="fill_parent">
        </ListView>
    </LinearLayout>
</LinearLayout>

I am using grid_item.xml which is used to hold data of each row, it looks like:

<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
        <TextView android:id="@+id/item1"
            android:text="row_id"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:width="20dip"
        />
        <TextView android:id="@+id/item2"
            android:text="col_1"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:width="100dip"
        />
        <TextView android:id="@+id/item3"
            android:text="col_2"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:width="100dip"
        />
        <TextView android:id="@+id/item4"
            android:text="col_3"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:width="100dip"
        /> </LinearLayout>

Code:

public class Inspections extends Activity{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        try
        {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.inspections);

            LoadInspections();
        }
        catch (Exception e) {
            CommonMethods.ShowMessageBox(this, e.toString());
        }
    }

    private void LoadInspections()
    {
        try
        {
            DBAdapter db = new DBAdapter(this);
            db.open();
            Cursor cur = db.GetInspections();
            if(cur.moveToFirst())
            {
                startManagingCursor(cur);
                ListView lv = (ListView)findViewById(R.id.listview);
                // create the grid item mapping
                String[] from = new String[] {"_id", "customer", "contract", "inspector"};
                int[] to = new int[] {R.id.item1, R.id.item2, R.id.item3, R.id.item4 };

                // fill in the grid_item layout
                SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.grid_item, cur, from, to);

                lv.setAdapter(adapter);  
                Log.d("Inspection", "Records found " + cur.getString(1) + "/ "+ cur.getString(2)+ "/ "+ cur.getString(3));
            }
            else
            {
                Log.d("Inspection", "No reords");
            }

            db.close();
        }
        catch(Exception ex)
        {
            Log.d("Inspection", "Error: "+ ex.toString());
        }
     }
}

Problem:
There is something wrong with LoadInspections(), the list-view show no data but only the HEADER-ROW. The cursor is retrieving data, check this line:

Log.d("Inspection", "Records found " + cur.getString(1) + "/ "+ cur.getString(2)+ "/ "+ cur.getString(3));

The log window is displaying the data.

I tried my best to find the answer on stackoverflow but could not succeeded.
Thanks in advance for your valuable time & help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:32:31+00:00Added an answer on May 26, 2026 at 6:32 am

    I was trying different things & when i removed the “Header” & “List Divider” sections from my main.xml it worked. Very Strange??

    So my main.xml now looks like:

    <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/inspections"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
    
        <!-- ListView (grid_items) -->
        <LinearLayout android:id="@+id/layout"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent">
            <ListView android:id="@+id/mylistview"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent">
            </ListView>
        </LinearLayout>
    </LinearLayout>
    

    Can somebody comment on this strange behavior of listview?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to android development. I'm trying to have my string.xml file add
I'm new to Eclipse and I'm using for some Android development. Eclipse is making
I am new to Android development. I am using a x-platform development tool which
I am very new to Android application development. I successfully added some backgrounds to
I am new to Android Development and I would really appreciate some advise on
I am new to Android development. I have created an Activity with the ListView
I am new to android development, making a simple game and using onKeyDown(.....) function
I'd like to hack on my new Android phone using a Linux development environment.
I'm pretty new to Android development and would appreciate some help. All I want
I'm new to Android development, and I was wondering if anyone knew either how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.