how to retrieve data from db and display it in list?
        Posted  
        
            by raji
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by raji
        
        
        
        Published on 2010-06-14T17:06:37Z
        Indexed on 
            2010/06/14
            17:12 UTC
        
        
        Read the original article
        Hit count: 180
        
android
In the below code I am passing catID to db.getNews(catID)
super.onCreate(savedInstanceState);
    setContentView(R.layout.newslist);
    Bundle extras = getIntent().getExtras();
 int catID = extras.getInt("cat_id");
 mInflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 final ListView lv = (ListView) findViewById(R.id.category);
 lv.setAdapter(new ArrayAdapter<String>(this, R.layout.newslist, db.getNews(catID)){
  public View getView(int position, View convertView, ViewGroup parent) {
   View row;
   if (null == convertView) {
    row = mInflater.inflate(R.layout.newslist, null);
   } else {
    row = convertView;
   }
   TextView tv = (TextView) row.findViewById(R.id.newslist_text);
   tv.setText(getItem(position));
   return row;
  }
 });
the getnews(int catid) function is below:
public NewsItemCursor getNews(int catID) {
String sql = "SELECT  title FROM news WHERE catid = " + catID + " ORDER BY id ASC";
    SQLiteDatabase d = getReadableDatabase();
    NewsItemCursor c = (NewsItemCursor) d.rawQueryWithFactory(
        new NewsItemCursor.Factory(),
        sql,
        null,
        null);
    c.moveToFirst();
    d.close();
    return c;
}
But I'm getting bug as array adapter undefined... Can anyone help me to resolve this, and retrieve data to make it display in list.
© Stack Overflow or respective owner