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

  • SEARCH
  • Home
  • 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 6535299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:21:26+00:00 2026-05-25T10:21:26+00:00

I’ve been looking on here for quite some time and I cannot find an

  • 0

I’ve been looking on here for quite some time and I cannot find an answer to my problem. There are many similar issues. But I haven’t been able to come up with any solution that works. I am very new to android/java programming so I really appreciate any help.

Background: I have an activity screen that contains 2 listviews. The first listview contains a list of names coming from a database. (This is working correctly).

Then when a user clicks on one of the names in the list, the onItemClick event fires and builds a cursor from all the data associated from the name. (Have verified that I am getting a cursor with valid results).

Problem: When I try to put the resulting cursor into a SimpleCursorAdapter to set my listadpter to, I am receiving no errors, but I’m not getting anything displayed to the screen.

I have data coming from a SQLite database. It is simply 4 columms with X number of rows. All I want to do is display everything on the list and then maybe do some analysis.

Here is my code:

public class TipCalculator_w_Database extends Activity    {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.databaseinfoscreen);

    ListView lv1 = null;
    lv1 = (ListView) findViewById (R.id.List1);
    final ListView lv2;
    lv2 = (ListView) findViewById (R.id.List2);


    final DataBase showData = new DataBase(getApplicationContext());
    showData.open();

    Cursor NameList = showData.GetAllNames();
    startManagingCursor(NameList);

    // Create an ArrayAdapter, that will actually make the Strings above
    // appear in the ListView
        int i = NameList.getCount();
        String[] FinalString = new String[i];
        int j = 0;
        while (NameList.moveToNext()) {

                FinalString[j] = NameList.getString(0);
                j++;
        }
        if(j != 0)
        {
            lv1.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_gallery_item, FinalString));  
        }
        NameList.close();
        showData.close();

        lv1.setOnItemClickListener(new OnItemClickListener() {
          public void onItemClick(AdapterView<?> parent, View view,
              int position, long id) {
              String selectedName = ((TextView) view).getText().toString();
              Context ctx= parent.getContext();
              final DataBase showData = new DataBase(getApplicationContext());
              showData.open();
            final String[] columns = new String[] { showData.KEY_ROWID, showData.KEY_NAME, showData.KEY_BILL, showData.KEY_TIP};
            final int[] to = new int[] { R.id.ID_list, R.id.Name_list, R.id.Bill_list, R.id.Tip_list};

              Cursor NewEntry = showData.GetRowByName(selectedName);
              startManagingCursor(NewEntry);

                lv2.setAdapter(new SimpleCursorAdapter(ctx, R.layout.listlayout, NewEntry, columns, to));

              showData.close();
              NewEntry.close();

    // Back Button Functionality
    Button backButton = (Button) findViewById(R.id.Back);   
    backButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
     Intent myIntent = new Intent(v.getContext(), Tipscreen.class);
     startActivityForResult(myIntent, 0);
    }
}
);
}

}

Here is my XML Files

listlayout.xml

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
        <TextView
            android:id="@+id/ID_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10px" />
        <TextView
            android:id="@+id/Name_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10px" />
           <TextView
            android:id="@+id/Bill_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10px" />
           <TextView
            android:id="@+id/Tip_list"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="10px"/> </LinearLayout>

— databaseinfoscreen.xml —

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
  <LinearLayout
      android:orientation="horizontal"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_weight="1">
<ListView android:text="List" android:id="@+id/List1" android:layout_width="wrap_content" android:textSize="18px" android:layout_height="fill_parent">
</ListView>  
  </LinearLayout>
  <LinearLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">
<ListView android:text="List" android:id="@+id/List2"  android:layout_width="wrap_content" android:textSize="18px" android:layout_height="fill_parent">
</ListView>  
  </LinearLayout>
  <RelativeLayout
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_weight="1">
     <Button android:text="@string/back" android:layout_alignParentBottom="true" android:id="@+id/Back" android:layout_width="wrap_content" android:textSize="18px" android:layout_height="40px"></Button>  
    </RelativeLayout>
</LinearLayout>

Hopefully this is enough to go off of, if there is any more information needed please let me know. I am getting all the information I need in the cursor it just isn’t being displayed. I am open to alternate means of doing this. However, I cannot make this particular class extend ListActivity since it needs to be extending activity.

Also of note. I have been able to display to that listview using the following line of code. Unfortunately this is only displays one column rather than all columns which I want.

lv2.setAdapter(new ArrayAdapter<String>(ctx, android.R.layout.simple_gallery_item, FinalString));

Where FinalString is simply a full column of data from the database that was manipulated into an array.

Thanks for the 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-25T10:21:27+00:00Added an answer on May 25, 2026 at 10:21 am

    Well since no one responded, I figured I’d answer this myself.

    Here are the steps, I’ve got this working for a different project so I’ll summarize. I can go into more detail if anyone needs it.

    XML:

    <ListView android:text="List" android:id="@+id/android:list" android:layout_width="wrap_content" android:scrollbars="horizontal" android:textSize="18px" android:layout_height="fill_parent" android:minHeight="120px">
    </ListView>  
    

    Step 1: Create a Cursor and populate using DB functions (not shown)

        String dbCount = showData.getTotalCount();
        Cursor GetAllData = showData.GetAllData();
        startManagingCursor(GetAllData);
    

    Step 2: Create an ArrayList that comprises a bunch of get values and fill the list with items from the cursor.

            int i = GetAllData.getCount();
    
            ArrayList<DB_Get_Values> dbList = new ArrayList<DB_Get_Values>();
    
            while (GetAllData.moveToNext()) {
                DB_Get_Values w = new DB_Get_Values(GetAllData.getString(0), GetAllData.getString(1), GetAllData.getString(2));
                dbList.add( w );
                j++;
            }
    

    Step 3: Create an adapter class that will be used to control the display of the listview

              DBAdapter T_Adapter = new DBAdapter( 
                    this,
                    dbList ); 
            setListAdapter( T_Adapter );
            GetAllData.close();
    

    DB_Get_Values Class: Full of Getters

    public class DB_Get_Values {
    
      public String P_Key = "";
      public String Mac_addr = "";
      public String SDK_VRS = "";
    
     public DB_Get_Values( String P_Key, String Mac_addr, String SDK_VRS) 
      {
        this.P_Key = P_Key;
        this.Mac_addr = Mac_addr;
        this.SDK_VRS = SDK_VRS;
     }
      public String get_Mac_addr() {
        return Mac_addr;
      }
      public String get_P_Key() {
        return P_Key;
      }
      public String get_SDK_VRS() {
            return SDK_VRS;
          }
    }
    

    Class DBAdapter: Get’s the values to put into the listview and allows for programatically controlling the display.

    class AdapterView extends LinearLayout {        
            public AdapterView(Context context, 
                    DB_Get_Values list ) {
                super( context );
    
                this.setOrientation(HORIZONTAL);        
    
                LinearLayout.LayoutParams PkeyParams = 
                    new LinearLayout.LayoutParams(40, LayoutParams.WRAP_CONTENT);
                PkeyParams.setMargins(1, 1, 1, 1);
    
                TextView Pkey = new TextView( context );
                Pkey.setText( list.get_P_Key() );
                Pkey.setTextSize(14f);
                Pkey.setTextColor(Color.WHITE);
                addView( Pkey, PkeyParams);
    
                LinearLayout.LayoutParams MacAddrParams = 
                    new LinearLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT);
                MacAddrParams.setMargins(1, 1, 1, 1);
                TextView MacAddr = new TextView( context );
                MacAddr.setText( list.get_Mac_addr() );
                MacAddr.setTextSize(14f);
                MacAddr.setTextColor(Color.WHITE);
                addView( MacAddr, MacAddrParams);
    
                LinearLayout.LayoutParams SDK_VRSParams = 
                    new LinearLayout.LayoutParams(20, LayoutParams.WRAP_CONTENT);
                SDK_VRSParams.setMargins(1, 1, 1, 1);
                TextView SDK_VRS = new TextView( context );
                SDK_VRS.setText( list.get_SDK_VRS() );
                SDK_VRS.setTextSize(14f);
                SDK_VRS.setTextColor(Color.WHITE);
                addView( SDK_VRS, SDK_VRSParams);
    }
    }
    public class DBAdapter extends BaseAdapter {
    
        private Context context;
        private List<DB_Get_Values> list;
    
        public DBAdapter(Context context, List<DB_Get_Values> list ) {
            this.context = context;
            this.list = list;
        }
    
        public int getCount() {
            return list.size();
        }
    
        public Object getItem(int position) {
            return list.get(position);
        }
    
        public long getItemId(int position) {
            return position;
        }
    }
    

    Step 5: You are now done! Change the parameters in AdapterView class to modify how it looks. Hopefully this helps someone.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.