我正在使用游标从数据库中获取,但是当我试图在列表中显示数据时,它没有显示..
以下代码用于使用游标从数据库访问数据:
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;
}
}
最佳答案
Log.v("Cursor Object", DatabaseUtils.dumpCursorToString(cursor))
关于android - 如何在android中使用游标显示列表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6253823/