Question : Which of the following is NOT a correct constructer for ArrayAdapter?
1. ArrayAdapter(Context context)
2. ArrayAdapter (Context context, int recourse)
3. ArayAdpater (Context context , int resource, int textViewResourceId)
4. ArrayAdapter (Context context , int resource, List items)
Correct Answer : 3 Explanation: ArrayAdapter(Context context, int resource) Constructor ArrayAdapter(Context context, int resource, int textViewResourceId) Constructor ArrayAdapter(Context context, int resource, T[] objects) Constructor ArrayAdapter(Context context, int resource, int textViewResourceId, T[] objects) Constructor ArrayAdapter(Context context, int resource, List objects) Constructor ArrayAdapter(Context context, int resource, int textViewResourceId, List objects) Constructor
Question : Which of the following add a click listener to items in a listView?
1. onClickListener.
2. onItemClickListener.
3. onItemClicked.
4. onListItemClickListener
Correct Answer : 2 Explanation: Use OnItemClickListener
ListView lv = getListView(); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView> adapter, View v, int position, long arg3) { String value = (String)adapter.getItemAtPosition(position); // assuming string and if you want to get the value on click of list item // do what you intend to do on click of listview row } }); When you click on a row a listener is fired. So you setOnClickListener on the listview and use the annonymous inner class OnItemClickListener.
You also override onItemClick. The first param is a adapter. Second param is the view. third param is the position ( index of listview items).
Using the position you get the item .
Edit : From your comments i assume you need to set the adapter o listview
So assuming your activity extends ListActivtiy
setListAdapter(adapter); Or if your activity class extends Activity
4. The development tools that can be downloaded from Android SDK and AVD Manager are SDK Androidplatform, NDK-platform, emulator images, and USB drivers for handsets.