Currently im displaying a simple ListActivity which displays three texts in the order:
eBay
Yahoo
what im trying to implement is that, when the index comes to Yahoo and then when i click the down button i should be able to go to the first section which is Google. Similarly when its at Google and then i click the top button in the emulator it should go to Yahoo.
I was able to do this. <b>But<b> the problem is that the onKeyDown event is not called when i try to go eBay from Google also to Yahoo from eBay. <b>But</b> when i hit the down key when the focus is at Yahoo, the onKeyDown event is triggered and the focus takes it to the First item which is Google.
Similar is the case when i try to go from bottom to top.
my code:
Using java Syntax Highlighting
- import android.app.ListActivity;
- import android.os.Bundle;
- import android.view.KeyEvent;
- import android.widget.ArrayAdapter;
- public class SimpleListScreen extends ListActivity {
- private String[] mStrings = new String[] { "Android", "Google", "Eclipse" };
- private int mStrings_length= mStrings.length-1;
- /** Called when the activity is first created. */
- @Override
- public void onCreate(Bundle icicle) {
- super.onCreate(icicle);
- // Create an array of Strings, that will be put to our ListActivity
- // Create an ArrayAdapter, that will actually make the Strings above
- // appear in the ListView
- this.setListAdapter(new ArrayAdapter<String>(this,
- android.R.layout.simple_list_item_1, mStrings));
- }
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- // TODO Auto-generated method stub
- switch (keyCode) {
- case KeyEvent.KEYCODE_DPAD_DOWN:
- moveToTop();
- return true;
- case KeyEvent.KEYCODE_DPAD_UP:
- moveToBottom();
- return true;
- }
- return false;
- }
- public void moveToTop()
- {
- int selectionRowID = (int) this.getSelectionRowID();
- if(selectionRowID==(mStrings_length)){
- this.setSelection(0);
- }
- }
- public void moveToBottom()
- {
- int selectionRowID = (int) this.getSelectionRowID();
- if(selectionRowID==0){
- this.setSelection(mStrings_length);
- }
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
What could be the reason?
Thanks,
Nitin




