views:

236

answers:

1

Hi,

I am having a listview in one of my activity.How to set foucs change listner.I tried with following block of code I am not getting result.

product_search_list = (ListView) findViewById(R.id.productlist); product_search_list.setOnFocusChangeListener(onproductchangelistener);

private OnFocusChangeListener onproductchangelistener = new OnFocusChangeListener() {

@Override public void onFocusChange(View v, boolean hasFocus) { int index= (int) ((ListView)v).getSelectedItemId(); Log.i("index",""+index);

} };

Actually on focus change of list items I want to get index of focused list item and do the necessary operations.

Thanks in advance.

Regards: Jayanth

A: 

You probably want setOnItemSelectedListener(), not setOnFocusChangeListener().

CommonsWare