0
I have a Simpleadapter that I use in a listview to show data coming from the database.
Follows the code
Map<String, String> map;
for(int i = 0;i < buscaCombustivel.getCount();i++) {
map = new HashMap<String, String>();
map.put("idItem", buscaCombustivel.getString(buscaCombustivel.getColumnIndex("id")));
map.put("text1", buscaCombustivel.getString(buscaCombustivel.getColumnIndex("dataEntrada")));
map.put("desc","Litros: " + buscaCombustivel.getString(buscaCombustivel.getColumnIndex("litrosEntrada")) + " | Valor unitário: " +
buscaCombustivel.getString(buscaCombustivel.getColumnIndex("valorUnitarioEntrada")) + " | Valor total: " +
buscaCombustivel.getString(buscaCombustivel.getColumnIndex("valorTotalEntrada")) + "\n");
list.add(map);
buscaCombustivel.moveToNext();
}
SimpleAdapter adapterDropDown = new SimpleAdapter(getApplicationContext(), list, R.layout.custom_list, new String[] { "text1", desc", "idItem" }, new int[] { R.id.text1, R.id.desc, R.id.idItem });
listDados.setAdapter(adapterDropDown);
R.id.text1, used in Simpleadapter, has a property called Drawableleft in its xml. I needed to change this property depending on a certain value that comes from the database. It is possible to do this?
Yes! Usually you put an image in Drawableleft. A database image url is coming up?!
– viana
No, it’s a drawable even... android:drawableLeft="@drawable/tic14"
– Matheus Suffi
Why don’t you create a custom Adapter and define the xml you want? It’s pretty simple.
– Márcio Oliveira