简体   繁体   English

Android更改Arraylist项的值

[英]Android change Arraylist item value

I have an ArrayList that is being read from a Text file. 我有一个从文本文件中读取的ArrayList。 The array list is being displayed in a ListView. 数组列表显示在ListView中。 I can add and Remove items from the arraylist without an issue. 我可以毫无问题地从arraylist中添加和删除项目。 I have an issue however, where the application just crashes when ever I try to modify the ArrayList. 但是,我有一个问题,当我尝试修改ArrayList时,应用程序只会崩溃。 Here is the code I'm using to modify the arrayList. 这是我用来修改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. LogCat仅报告“ ArrayIndexOutOfBoundsException”错误。 What am I doing wrong? 我究竟做错了什么?

You are probably mixing the id of onClick method and the id you use for indexes. 您可能会混合使用onClick方法的ID和用于索引的ID。 Try renaming your id variable. 尝试重命名您的id变量。 Because the id in onClick method shows which dialog clicked. 因为onClick方法中的ID显示了单击了哪个对话框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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