Getting stored data from database into ListView.

前端 未结 1 1989
孤独总比滥情好
孤独总比滥情好 2020-12-17 03:44
package one.two;


import java.util.ArrayList;
import java.util.List;

import android.app.ListActivity;
import android.database.Cursor;
import android.inputmethodser         


        
相关标签:
1条回答
  • 2020-12-17 04:16

    You are not populating the list with the data you retrieved. And, you should use SimpleCursorAdapter in these cases:

    private void getData() {
    
        db.open();
    
        List<String> items = new ArrayList<String>();
    
         Cursor c = db.getAllEntry();
         c.moveToFirst(); 
    
         ListAdapter adapter=new SimpleCursorAdapter(this,
                         R.layout.view_list, c,
                         new String[] {"date", "title"},
                         new int[] {R.id.toptext, R.id.bottomtext});
         setListAdapter(adapter);
    
         setListAdapter(entries);
    
         db.close(); 
    }
    

    In this case I'm guessing your table has a column named date and another named title. Take a look at this example for further reference: SimpleCursorAdapters and ListViews

    0 讨论(0)
提交回复
热议问题