java - ArrayList<R.String> 类型中的方法 add (int, R.String) 不适用于 arguments(int, String)

标签 java android add

我查看了谷歌和堆栈溢出,但未能找到想要工作的答案。我正在按照创建待办事项列表的“专业 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;
        }
    });

}

最佳答案

替换

ArrayList<string>

通过

ArrayList<String>

关于java - ArrayList<R.String> 类型中的方法 add (int, R.String) 不适用于 arguments(int, String),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12601961/

相关文章:

java - xsd 验证失败

java - 尝试加载独立于平台的文件

android - 我应该在哪里区分适合移动设备的网站和安卓网站?

Android折线图api

SQL Server - 添加或减去先前的值

java - Jasper report可以同时使用connection和bean吗?

java - Storm 示例甚至可以在没有 Zookeeper、Nimbus 和 Supervisor 进程的情况下运行

java - 仅使用 androidTest 代码生成单个 .jar

java - 斐波那契数列 : Sum of all numbers

javascript - 为什么将数组添加到数字返回一个字符串?