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.