Question

How do i setup a onListItemClick listener so that the i can return only the value from R.id.number from the adapter that ive setup below. I will later pass the value i obtain to another activity.Please Help

sd=new SimpleAdapter(MainActivity.this,alist,R.layout.item_list,new String[]{"No","Name"},new int[]{R.id.number,R.id.item_name});
                    list.setAdapter(sd);
Was it helpful?

Solution

Try this

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
                String number=((TextView)view.findViewById(R.id.number)).getText().toString();
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top