0

I am developing an android application in which i have to place 5 items with 5 icons in a list.Has anyone implemented it before?

If Yes,Can he help me how to implement it?

Thanks tushar

Sam
  • 1,509
  • 3
  • 19
  • 28
Tushar
  • 5,907
  • 15
  • 49
  • 81

1 Answers1

0

you can try from this
Dynamic ListView in Android app

 public class ListViewDemo extends ListActivity {


//LIST OF ARRAY STRINGS WHICH WILL SERVE AS LIST ITEMS
ArrayList<String> listItems=new ArrayList<String>();

//DEFINING STRING ADAPTER WHICH WILL HANDLE DATA OF LISTVIEW
ArrayAdapter<String> adapter;

//RECORDING HOW MUCH TIMES BUTTON WAS CLICKED
int clickCounter=0;

@Override
public void onCreate(Bundle icicle) {

super.onCreate(icicle);
setContentView(R.layout.main);
adapter=new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
listItems);
setListAdapter(adapter);
}

//METHOD WHICH WILL HANDLE DYNAMIC INSERTION
public void addItems(View v) {
listItems.add("Clicked : "+clickCounter++);
adapter.notifyDataSetChanged();
}
}

android.R.layout.simple_list_item_1 is default list items layout supplied by android and >you can use this stock layout for non complex things.

listItems is an array list which holds the data shown in the ListView and all the >insertion and removal should be done on listItems the changes in list should reflect in >the view and thats handled by ArrayAdapter adapter which should be notified using

adapter.notifyDataSetChanged();

Adapter is instantiated with 3 paramters the context which could be your >activity/listactivity the layout of you individual list item and lastly the list which is >the actual data to be displayed in the list.

Community
  • 1
  • 1
Nikunj Patel
  • 21,853
  • 23
  • 89
  • 133