1

我查看了谷歌和堆栈溢出,但无法找到想要工作的答案。我正在关注“专业 android 4 应用程序开发”一书中的教程,该教程创建了一个待办事项列表。我的代码中唯一的错误是 eclipse 在我的代码中给我的错误消息,一旦我能解决这个问题,我相信它应该可以正常运行,但我已经盯着它看了一个小时,我很沮丧无法理解代码有什么问题以及为什么我在代码中收到错误消息。

它只强调了我在下面的代码中提出的一个单词 add ,单词的每一侧都有三个 * 任何帮助将不胜感激,谢谢

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Inflate the view to the main screen
    setContentView(R.layout.activity_to_do_list);

    // Get the references to the UI widgets
    ListView myListView = (ListView) findViewById(R.id.myListView);
    final EditText myEditText = (EditText) findViewById(R.id.myEditText);

    // create the array list of to do items
    final ArrayList<string> todoItems = new ArrayList<string>();

    // Create the array list of to do items
    final ArrayAdapter<string> aa;

    // Create the Array Adapter to bind the array to the list view
    aa = new ArrayAdapter<string>(this,
            android.R.layout.simple_list_item_1, todoItems);

    // Bind the array adapter to the List View
    myListView.setAdapter(aa);

    myEditText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_DOWN)
                if ((keyCode == KeyEvent.KEYCODE_DPAD_CENTER)
                        || (keyCode == KeyEvent.KEYCODE_ENTER)) {
                    todoItems.***add***(0, myEditText.getText().toString());
                    aa.notifyDataSetChanged();
                    myEditText.setText(" ");
                    return true;
                }
            return false;
        }
    });

}

}

4

1 回答 1

7

代替

ArrayList<string>

经过

ArrayList<String>
于 2012-09-26T12:43:39.767 回答