1

I am trying to develop an android application that can display values from multiple tables.

I have used a Base Adapter to display the values since i just need to display the queried values in a list. But when I try to display the values in the list view it is blank.

I am not sure what I have done wrong.

I am Using the below method to query the data from the database to display only the required values.

  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;

    }

The below methods are used to populate the values onto the list view.

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;
        }
    }
NikhilRcop
  • 89
  • 1
  • 10

1 Answers1

1

Try to use a cursor adapter in place of a base adapter. Moreover, beware that the position you're passing to the cursor may not be what you think.

flower_green
  • 1,124
  • 2
  • 24
  • 29
  • I dont want to use a cursor adapter since i need to change the columb from Assetid to _id in that case i will get an error with ambiguous column name. If you know any alternative could you suggest any. – NikhilRcop Jul 11 '15 at 07:58
  • 1
    To solve that problem I usually alias the column name that I want to use as an id directly in the query (eg, select *, columname as _id from table). – flower_green Jul 11 '15 at 08:00
  • Thankx did try it once again using the cursor adapter and its working now. – NikhilRcop Jul 11 '15 at 08:48