值不填充在列表视图
我想开发一个可以显示多个表中的值的android应用程序。值不填充在列表视图
我已经使用Base Adapter来显示值,因为我只需要在列表中显示查询的值。但是当我尝试在列表视图中显示值时,它是空白的。
我不知道我做错了什么。
我使用下面的方法来查询数据库中的数据,只显示所需的值。
public Cursor getAssetInStore()
{
SQLiteDatabase db_database = getReadableDatabase();
Cursor c = db_database.rawQuery("SELECT asset_name,warrenty,AssetImage,asset_status FROM `Assets`,`AseetIssued` WHERE Assets.Assetid = AseetIssued.Assetissuedid AND asset_status =?" ,
new String [] {"In Storage"}, null);
return c;
}
以下方法用于将值填充到列表视图中。
private void populateAssetListView()
{
Cursor c = db_database.getAssetInStore();
AssetListView.setAdapter(new AssetListAdapter(this, c));
}
public class AssetListAdapter extends BaseAdapter
{
private Context mContext;
Cursor cursor;
public AssetListAdapter(Context context, Cursor c) {
super();
mContext = context;
cursor =c ;
}
@Override
public int getCount() {
return 0;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
//The layout is assigned to the custome created created in this case it is customeassetview the cales will be displayed as per this list
view = inflater.inflate(R.layout.assetsinstore_placeholder, null);
cursor.moveToPosition(position);
TextView Assetsstatus = (TextView) view.findViewById(R.id.Assetssatutsstore_view);
int status = cursor.getInt(cursor.getColumnIndex("asset_status"));
Assetsstatus .setText(String.valueOf(status));
TextView Assetsname = (TextView) view.findViewById(R.id.Assetstore_name_view);
String Assetname = cursor.getString(cursor.getColumnIndex("asset_name"));
Assetsname.setText(Assetname);
TextView Warrenty = (TextView) view.findViewById(R.id.Assetstore_Warrenty_view);
String CustDesignation = cursor.getString(cursor.getColumnIndex("warrenty"));
Warrenty .setText(CustDesignation);
ImageView AssetImage = (ImageView) view.findViewById(R.id.list_image);
byte[] bb = cursor.getBlob(cursor.getColumnIndex("AssetImage"));
AssetImage.setImageBitmap(BitmapConver.getPhoto(bb));
return view;
}
}
尝试使用游标适配器代替基本适配器。此外,请注意,您传递给光标的位置可能不是您的想法。
我不想使用游标适配器,因为我需要将AssedB从Assetid更改为_id,在这种情况下,我将得到一个含糊不清的列名的错误。如果你知道任何替代方案,你会建议吗? – NikhilRcop
为了解决这个问题,我通常在查询中直接使用我想用作id的列名(例如,select *,columname as _id from table)。 –
Thankx确实再次尝试使用游标适配器并立即开始工作。 – NikhilRcop
'getCount'必须返回数据集的大小。它不能返回0 – Blackbelt