How to move focus of list item to down item when we clicked on volume down button of android mobile.Tried this code but unable to down the focus.any help on this or any other alternative approaches to down the selector. Thanks in advance.
super.onCreate(savedInstanceState);
// 2. create array adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, // standard row layout
// provided by android
listItemArray);
// 3. Call setListAdapter
setListAdapter(adapter);
listView = getListView();
listView.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// TODO Auto-generated method stub
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_DOWN:
ListView list =(ListView)v;
for (int j=0; j < list.getChildCount(); j++){
if(list.getChildAt(j).getBackground().equals(R.color.gray)){
list.getChildAt(j).setBackgroundResource(R.color.TRANSPARENT);
list.getChildAt(j++).setBackgroundResource(R.color.gray);
}else
list.getChildAt(0).setBackgroundResource(R.color.gray);
}
break;
}
return false;
}
});
Aucun commentaire:
Enregistrer un commentaire