0 Replies - 3004 Views - Last Post: 01 January 2014 - 03:53 AM

#1 timbats  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-January 14

Listview onClickListener always sending 4

Posted 01 January 2014 - 03:53 AM

My application will respond to a user selection on a listview, and then pass the selected item to another activity. But, no matter what listview item is selected, this code will pass index=4.

setListAdapter(new MyAdapter(this,
        android.R.layout.simple_list_item_1, R.id.textView1, 

ListView lv = getListView();
   lv.setOnItemClickListener(new OnItemClickListener()
      public void onItemClick(AdapterView<?> adapter, View v, int position,
            long arg3) 
            Intent i = new Intent(getApplicationContext(), Challengeview.class);
            i.putExtra("index", ""+position);

And the 'Challengeview.class' that the intent is sent to

String value = getIntent().getStringExtra("index");

From here, the 'value' is used to refer to an array index. Logcat is giving the following error:

java.lang.ArrayIndexOutOfBoundsException: length=4; index=4

Titles Array, as stored in values:

<?xml version="1.0" encoding="utf-8"?>
    <string-array name="titles">


Is This A Good Question/Topic? 0
  • +

Page 1 of 1