user4342924
user4342924

Reputation:

How to make a listView having three items per Row the items are Image Buttons, and the Text corresponding to that Image Button

I want to create the following Layout.

I want to create the layout Looks like this Image, that uses ListView, I have Created an Activity but that doesn't shoes me the items, only shows blank listView

My Code is:

public class HomeScreen_Activity extends ListActivity {
    static final ArrayList<HashMap<String,ImageButton>> list = new ArrayList<HashMap<String,ImageButton>>();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
        SimpleAdapter myAdapter = new SimpleAdapter(
                this,
                list,
                R.layout.home_sreen,
                new String[]{"1st","2nd","3rd"},
                new int[]{R.id.image1,R.id.image2,R.id.image3}
        );
        populateList();
        setListAdapter(myAdapter);

    }

    private void populateList(){
        for(int i = 0; i<10 ; i++){
            HashMap map = new HashMap();
            map.put("1","@drawable/cat_1");
            map.put("2","@drawable/cat_1");
            map.put("3","@drawable/cat_1");
            list.add(map);
        }


    }
}

Upvotes: 2

Views: 153

Answers (2)

Esha
Esha

Reputation: 76

Create a Layout in your XML file, then within the list view add that file as a tool.

Upvotes: 1

pantalaimon314
pantalaimon314

Reputation: 11

Try populating the list before you create your SimpleAdapter.

Upvotes: 1

Related Questions