0

Hi This is my code..

....
public void QuerySQL(String SQL) {

    try {

        Statement statement = connect.createStatement();
        rs = statement.executeQuery(SQL);
        List<Map<String, String>> data = null;
        data = new ArrayList<Map<String,String>>();

        while(rs.next()) {
            Map<String, String> datanum = new HashMap<String, String>();
            datanum.put("A", rs.getString("RoomNumber"));
            datanum.put("B", rs.getString("RoomStatus"));
            datanum.put("C", rs.getString("RoomType"));
            data.add(datanum);
        }
        String[] from = {"A","B","C"};
        int[] views = {R.id.txt_number,R.id.status,R.id.txt_type};
        ADAhere = new SimpleAdapter(this, data, R.layout.layout_list_item, from, views);
        listViewStats.setAdapter(ADAhere);
    } catch (Exception e) {
        Toast.makeText(Main.this, e.getMessage().toString(),Toast.LENGTH_LONG).show();
    }   
}
....

This is an android project that get a string from the sql server database. All of things already working properly. The thing is I want to put the Image instead of string. And the Image is already in the drawable hdpi project folder.

For example the "RoomStatus" in database have 4 types. Clean, Dirty, Occupied, Closed. I need to get the picture from the drawable hdpi R.drawable.clean, R.drawable.dirty, R.drawable.occupied, R.drawable.closed. But I dont get the idea how to put the picture based on the string get from the database. Any help I'll really appreciate. Thx in advance

lalalala
  • 563
  • 8
  • 23
  • Hey, have you tried creating your own custom adapter? I'd recommend starting from here: https://developer.android.com/training/material/lists-cards.html – Alex Hart Jun 26 '15 at 14:50
  • I'm already trying to create simple adapter but only with the string. So right now I'm gonna trying with the picture. But I don't have any idea how to put the picture based on the string that I get from database – lalalala Jun 26 '15 at 15:01

1 Answers1

0

SimpleAdapter supports only textviews whereas you need to show images. So you should go for customadapter extending BaseAdapter class.

And for dynamically retrieving drawables you can use this link

Community
  • 1
  • 1
Sowmia Sundararajan
  • 1,613
  • 2
  • 14
  • 17