Image in listview with SqlLite / Drawable

1

I have an App that performs a search on business phones in a SQLLite database. It is working normally, but I need to insert image in some of these companies. The database field would be just the name of the image and the image would be in the res / drawable folder ... I will not use blob field. How do I show this image in imageview in my results listview. See my code below

String mostraTexto = params.getString("palavrachave");  // parametro para busca

    Cursor cursor = db.rawQuery("select nome,liberado,imagem,cidade,CIDADES._id,telefone,ddd,tipo,cid_nome,TELEFONES._id from TELEFONES INNER JOIN CIDADES ON TELEFONES.cidade = CIDADES._id where telefone like '%" + mostraTexto + "%' or nome like '%" + mostraTexto + "%' order by cid_nome,nome", null);


    String[] from = {"nome","telefone","cid_nome","ddd"};
    int[] to = {R.id.txt_nome, R.id.txt_telefone, R.id.txt_cidade, R.id.txt_ddd, R.dr};

    //vamos contas os resultados
    int id[]=new int[cursor.getCount()];
    if (cursor.getCount() < 1)
    {           
     AlertDialog.Builder dialogo = new AlertDialog.Builder(Resultado.this);
     dialogo.setTitle("Aviso");
     dialogo.setMessage("Nenhuma resultado na sua pesquisa!");
     dialogo.setNeutralButton("Ok", null);
     dialogo.show();
    }
    if (cursor.getCount() > 0) 
    {

    android.support.v4.widget.SimpleCursorAdapter ad =
            new android.support.v4.widget.SimpleCursorAdapter(
                    getBaseContext(),R.layout.buscar_ltw,cursor, from, to, 0);

    ListView ltw_listar = (ListView)findViewById(R.id.ltw_listar);

        ltw_listar.setAdapter(ad);
    
asked by anonymous 02.10.2014 / 19:41

1 answer

1

use this snippet to get the image id

   String mDrawableName = "myImageName";
int id = mContext.getResources().getIdentifier(mDrawableName , "drawable", mContext.getPackageName());

and to set the image is like

imageview.setImageResource(id);
    
03.10.2014 / 20:37