Good evening everyone.
I am using SQLite and android. I am trying to match a query result with images stored in the drawable folder. I am trying to do it dynamically search and then display it into a custome listview (image + text). I am not sure how to accomplish this. I can retrieve a simple query result from the database and display the values into a listview but I dont know how to display images + text in the listview. Can anyone help me and guide me to the right path?
The following code is part of my activity
List<YAODeckHieraticBlue> valuesMainimage = datasource2.SQLDeckHieraticBlueTABLESEARCHMAINDECKIMAGE(); List<YAODeckHieraticBlue> valuesMain = datasource2.SQLDeckHieraticBlueTABLESEARCHMAINDECK(); ImageView thumbnail; thumbnail = (ImageView)findViewById(R.list.thumb); TextView name; name = (TextView)findViewById(R.list.text); name.setText(valuesMain); thumbnail.setBackgroundResource ( getResourceID ( valuesMainimage , "drawable", getApplicationContext() ) ); //if I just take out the previous section it only display Text but I am missing the Image part in the Listview ArrayAdapter<YAODeckHieraticBlue> adapterMain = new ArrayAdapter<YAODeckHieraticBlue>(this, android.R.layout.simple_list_item_1, valuesMain); setListAdapter(adapterMain);
I use the following piece of code to verify if the image exist
protected final static int getResourceID (final String resName, final String resType, final Context ctx) { final int ResourceID = ctx.getResources().getIdentifier(resName, resType, ctx.getApplicationInfo().packageName); if (ResourceID == 0) { throw new IllegalArgumentException ( "No resource string found with name " + resName ); } else { return ResourceID; } }
My table in the database looks like this:
Table Name: [Deck name Hieratic Blue]
column1:ID - Integer
column2 [Card Name] - Text
column3: Type - Text
column4: Deck_typeID - Integer
Column5: Images -Text
Note: the image column just store the name of the image file without the file extention (.png)