listview +icons+ sqlite

by carmelo » Tue, 23 Mar 2010 01:51:52 GMT


Sponsored Links
 Hi! I'm trying to read datas from a db, display them into a list with
icons ( not fixed but changing in base of the value read in the db). I
know how to do this thing, reading values from a simple array:

public class DynamicDemo extends ListActivity {
TextView selection;
String[] items={"cinema", "cinema", "sport", "sport", "music", "art",
"shopping", "shopping", "music"};

//@Override
public void onCreate(Bundle icicle) {
                super.onCreate(icicle);
                setContentView(R.layout.main);
                setListAdapter(new IconicAdapter());
                selection=(TextView)findViewById(R.id.selection);
}


class IconicAdapter extends ArrayAdapter {
                IconicAdapter() {
                super(DynamicDemo.this, R.layout.row, items);
}

//@override
public View getView(int position, View convertView, ViewGroup parent)
{

        LayoutInflater inflater=getLayoutInflater();
        View row=inflater.inflate(R.layout.row, parent, false);

        //set view for text
        TextView label=(TextView)row.findViewById(R.id.label);
        label.setText(items[position]);

        //set view for icon
        ImageView icon=(ImageView)row.findViewById(R.id.icon);

        //select correct icon
        if (items[position].equals("cinema")) {
                icon.setImageResource(R.drawable.cinema);
        }
        if (items[position].equals("sport")){
                icon.setImageResource(R.drawable.sport);
        }
        if (items[position].equals("art")){
                icon.setImageResource(R.drawable.art);
        }
        if (items[position].equals("shopping")){
                icon.setImageResource(R.drawable.shopping);
        }
        if (items[position].equals("music"))    {
                icon.setImageResource(R.drawable.music);
        }
return(row);
}
}
}

But I cannot find a way to do the same thing using the cursor with the
result of the query. Anyone can help?
thanks!

--



Other Threads

1. How to modify properties of a list in a ListActivity

Hello

I have a simple ListActivity midlet. It populates the list using a
String array which is passed to the setListAdapter method.

i.e.:


String[] directoryListing = {"\etc","\dev", "writetext.txt"};

setListAdapter(new ArrayAdapter<String>(this,
                                R.layout.main, R.id.selection,
                                directoryListing));


However my question is, how is it possible to modify the properties of
the list so if I know "\etc" and "\dev" are directories and I want to
change the text colour to reflect that it is a directory how can I do
this ?

Can anyone point me to any API's ?

Thanks



--~--~---------~--~----~------------~-------~--~----~

2. Seems questioins here are rarely answered? Better place to post them?

Thank you all.

I'll keep at it.

Happy Androiding (is that a word?)!


--~--~---------~--~----~------------~-------~--~----~

3. Is it possible to set focus to a component programmatically?

4. Is it possible to set focus to a component programmatically?

5. How To Control Android To Restart

6. Data Synchronization Option is missing from the Settings

7. ReplayGain