how can i display two columns in listview. that columns data is coming from SQLite database
How can i display two columns in listview that columns data is coming from sqlite database?In that columns first column is TextView and another column is EditView. i have tried below code. But I got the following exception
unable to start the activity ComponentInfo:java.lang.NullPointerException.
the code is shown below.
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.categorynew);
lv = (ListView)findViewById(android.R.id.list);
getList();
}
public void getList()
{
int x = 0;
cur=db.rawQuery("SELECT * FROM detaillist ORDER BY symbol",null);
ArrayList<String> al = new ArrayList<String>();
ArrayList<String> al1 = new ArrayList<String>();
cur.moveToFirst();
while (cur.isAfterLast() == false) {
al.add(cur.getString(cur.getColumnIndex("symbol")));
al1.add(cur.getString(cur.getColumnIndex("position")));
cur.moveToNext();
}
cur.close();
String[] str = new String[al.size()];
strArray = al.toArray(str);
String[] str1 = new String[al1.size()];
strArray1 = al1.toArray(str1);
lv.setAdapter(new EfficientAdapter(this));
}
private static class EfficientAdapter extends BaseAdapter {
static class ViewHolder {
TextView text;
EditText text2;
}
private LayoutInflater mInflater;
public EfficientAdapter(Context context) {
mInflater = LayoutInflater.from(context);
}
public int getCount() {
return symbols.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
// convertView = mInflater.inflate(android.R.layout.simple_list_item_1, null);
convertView = mInflater.inflate(R.layout.editcategorylist, null);
holder = new ViewHolder();
holder.text = (TextView) convertView.f开发者_高级运维indViewById(R.id.symbol);
holder.text2 = (EditText) convertView.findViewById(R.id.postion);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(strArray[position]);
Log.e("text",holder.text.toString());
holder.text2.setText(strArray1[position]);
Log.e("text2",holder.text2.toString());
return convertView;
}
}
This link here has slightly different implementation but you can use bits of the tutorial and cook something of your own. A starting point if you would. It makes use of a DB and display the results in a tabular form.
http://www.anotherandroidblog.com/2010/08/04/android-database-tutorial/
精彩评论