我正在從數據庫中使用遊標,但是當我試圖在列表中顯示的數據,它沒有顯示使用光標在列表中的數據..如何顯示在Android的
下面的代碼是訪問使用光標從數據庫中的數據:
protected void showCustomerdetails() {
try
{
Cursor cursor = m_dbManager.getValues("customer", new String[]{"name","mobile_phone" }, null, null, null, null);
if(cursor != null)
{
cursor.moveToFirst();
int i = 0;
while(cursor.isAfterLast() == false)
{
m_uname = cursor.getString(cursor.getColumnIndex("name"));
Log.d("debug","getting the name from cursor");
m_mobnum = cursor.getString(cursor.getColumnIndex("mobile_phone"));
cursor.moveToNext();
i++;
}
}
cursor.close();
}
catch(SQLException e)
{
e.printStackTrace();
}
}
現在下面的代碼是在列表中添加的數據---你是通過迭代光標
class IconicAdapter extends ArrayAdapter<String>
{
Activity context;
IconicAdapter(Activity context)
{
super(context, R.layout.custoemrs_list);
this.context=context;
}
public View getView(int position, View convertView, ViewGroup parent)
{
View row = null;
try
{
LayoutInflater inflater=context.getLayoutInflater();
row=inflater.inflate(R.layout.custoemrs_list, null);
TextView des=(TextView)row.findViewById(R.id.custusername);
des.setText(m_uname);
TextView qty=(TextView)row.findViewById(R.id.custmobnum);
qty.setText(m_mobnum);
}
catch(Exception e)
{
e.printStackTrace();
}
return row;
}
}
如何?你能解釋嗎? – 2011-06-06 15:19:23
查看上面的更新回答 – Aleadam 2011-06-06 15:29:16
感謝您的回覆。但仍然沒有顯示... – 2011-06-07 04:55:29