简体   繁体   中英

Android change Arraylist item value

I have an ArrayList that is being read from a Text file. The array list is being displayed in a ListView. I can add and Remove items from the arraylist without an issue. I have an issue however, where the application just crashes when ever I try to modify the ArrayList. Here is the code I'm using to modify the arrayList.

input2 = (EditText) promptView.findViewById(R.id.userInput);
input2.setText(array.get(id).toString());
alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            String value2 = input2.getText().toString();
            array.set(id, value2.toString());
            adapter.notifyDataSetChanged();
        }
})

LogCat only reports an "ArrayIndexOutOfBoundsException" error. What am I doing wrong?

You are probably mixing the id of onClick method and the id you use for indexes. Try renaming your id variable. Because the id in onClick method shows which dialog clicked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM