我有两个方法,一个用于收集SQL数据,另一个用于将其放入listview中...似乎我无法在SQL部分中正确地形成数组,以便可以将其传递给listview。 / p>
SQL act:
public String[] getDataInArray() { // get data for list and return in array form
// TODO Auto-generated method stub
String[] columms = new String[]{ KEY_ROWID, KEY_NAME};
String[] return_colums = null;
Cursor c = currentdatabase.query(DATABASE_TABLE, columms, null, null, null, null, null);
int iRow = c.getColumnIndex(KEY_ROWID);
int iName = c.getColumnIndex(KEY_NAME);
int rowcount = 0;
for(c.moveToFirst(); !c.isAfterLast(); c.moveToNext())
{
return_colums[rowcount] = c.getString(iName) + "," + c.getString(iRow);
rowcount = rowcount + 1;
}
return return_colums;
}
listview法案:
public ListView whiskeylist;
public String[] DataArryWhiskey;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Start db view of whiskey
DBConfig whiskeyrows = new DBConfig(this);
whiskeyrows.open();
DataArryWhiskey = whiskeyrows.getDataInArray();
whiskeyrows.close();
Toast.makeText(MainScreen.this, result, Toast.LENGTH_LONG).show();
whiskeylist = (ListView)findViewById(R.id.listofWhiskey);
whiskeylist.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1 , DataArryWhiskey));
// End db view of whiskey
}// end onCreate
我一直在崩溃,有人可以帮忙见面吗? Thx提前
答案 0 :(得分:1)