android - 如何在android中使用游标显示列表中的数据

标签 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;
 }
}

最佳答案

Log.v("Cursor Object", DatabaseUtils.dumpCursorToString(cursor))

关于android - 如何在android中使用游标显示列表中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6253823/

相关文章:

java - Dagger 2重新初始化单例

安卓图像效果?

java - 如何使用 Java Stream 从列表中获取任何数据的特定索引?

Android 有没有简单的方法来备份您的 android 项目?

android - 设备所有者未在 Android M 上清除

android - 使用最新更新构建发布 apk 时出错

java - 当我返回菜单页面并添加新商品时,购物车无法容纳当前商品

java - 在 Firebase Android 中将带有子项的值转换为 Java 对象

Android DP 到 PX 的转换,在 mdpi 上 160 dp 总是 160 px 吗?

java - 使用 contentprovider 的 boolean 方法总是返回 true?