2012-09-26 60 views
1

我已经查看了google和堆栈溢出,并且无法找到答案想工作。我正在从“专业的android 4应用程序开发”一书中创建一个待办事项列表。在我的代码中唯一的错误是什么日食给我作为一个错误信息在我的代码中,一旦我可以解决这个问题我相信它应该运行良好,但我一直在盯着它一个小时现在和挫折已经得到我我无法理解代码中的错误,以及为什么我在代码中收到错误消息。类型ArrayList <R.String>中的方法add(int,R.String)不适用于参数(int,String)

它只是强调了一个词加上我在下面三个*字上的任何帮助将不胜感激每一侧的代码已经提出,由于

@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; 
     } 
    }); 

} 

}

+0

看看这个结构,看起来如果你在add函数中删除了“0”参数,它应该可以工作... – Aviral

+0

感谢您的输入,但不幸的是它没有工作:( – Leccles1

回答

7

更换

ArrayList<string> 

通过

ArrayList<String> 
+0

Dystroy thankyou aha,这样一个愚蠢的错误我(注意自我检查下次拼写) – Leccles1

+1

耶稣他们为什么不带一个更好的编辑器来指出这一点......我失踪的视觉工作室:( –

相关问题