Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to use a query result to match an image resource?

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to use a query result to match an image resource?

    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)
    Last edited by SANOZUKE; July 27th, 2014 at 12:35 PM.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: How to use a query result to match an image resource?

    Thread moved.

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

    Please post your code correctly per the above link.

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to use a query result to match an image resource?

    is the issue resolved??

  4. #4
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: How to use a query result to match an image resource?

    It looks like you are on the right track, however you will need to create a custom ArrayAdapter to handle a list view with Images and Text. The process is:
    • Create a layout xml that defines the cell
    • Create a class that extends ArrayAdapter and overrides getView
    • Inflate the layout in getView and finally
    • Assign the custom ArrayAdapter to the ListView's setListAdapater


    There is a good tutorial here that goes through this is in depth.

Similar Threads

  1. drag and drop word to match image
    By stresstedout in forum What's Wrong With My Code?
    Replies: 191
    Last Post: March 3rd, 2014, 03:41 PM
  2. JDBC - any query and the corresponding result set
    By moekler in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 19th, 2012, 05:15 PM
  3. The requested resource () is not available.
    By freakycoder in forum Web Frameworks
    Replies: 0
    Last Post: July 10th, 2012, 12:44 AM
  4. update query is firing first then insert query
    By salmondavid88 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 8th, 2011, 10:15 AM
  5. [SOLVED] Resource Injection
    By newbie in forum JDBC & Databases
    Replies: 2
    Last Post: March 22nd, 2011, 04:27 PM

Tags for this Thread