您好我正在开发一个Android中,我从数据库中加载数据并在列表视图中显示它。 我的代码如下从SQLite显示两列在列表视图中相同的字符串android
public class rel extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.refill);
//Creating an object called mydbhelper
Dbms mydbhelper = new Dbms(this);
//Loading the database in writable format
SQLiteDatabase db=mydbhelper.getWritableDatabase();
String[] id= new String[]{"_id","medicine","hs"};
//Cursor
Cursor c = db.query("medicines",id,null,null,null, null,null);
startManagingCursor(c);
String[] from = new String[]{"medicine"};
int[] to = new int[] { R.id.textlist1};
// Now creating an array adapter and set it to display using my row
SimpleCursorAdapter notes =new SimpleCursorAdapter(this, R.layout.notes_row, c, from, to);
setListAdapter(notes);
}
什么我想要实现的是显示一个列表视图“医学-HS”中医药是从一列和HS是从数据库的另一列。例如 XYZ-HS1 ABC-HS2 作为列表视图内容
如何实现这一目标? 现在我能够得到的只有医药
请给你的那种建议
}
这给了一个错误数据库中不存在这样的字段。更清楚地阅读问题并理解事情在内部如何工作,然后再试图展示你的聪明才智。 – 8A52