Java 类型ArrayList中的add(int,R.String)方法<;R.String>;不适用于参数(int、String)
我查看了google和堆栈溢出,没有找到一个可行的答案。我遵循《专业android 4应用程序开发》一书中的教程,该教程创建了一个待办事项列表。我的代码中唯一的错误是eclipse在我的代码中给我的错误消息,一旦我可以修复它,我相信它应该运行良好,但我已经盯着它看了一个小时了,沮丧让我无法理解代码的错误以及为什么我在代码中得到错误消息 它只在我在下面代码中给出的一个单词add下加了三个*的下划线,如果您有任何帮助,我们将不胜感激,谢谢Java 类型ArrayList中的add(int,R.String)方法<;R.String>;不适用于参数(int、String),java,android,add,Java,Android,Add,我查看了google和堆栈溢出,没有找到一个可行的答案。我遵循《专业android 4应用程序开发》一书中的教程,该教程创建了一个待办事项列表。我的代码中唯一的错误是eclipse在我的代码中给我的错误消息,一旦我可以修复它,我相信它应该运行良好,但我已经盯着它看了一个小时了,沮丧让我无法理解代码的错误以及为什么我在代码中得到错误消息 它只在我在下面代码中给出的一个单词add下加了三个*的下划线,如果您有任何帮助,我们将不胜感激,谢谢 @Override public void onCreate
@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;
}
});
}
@覆盖
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//将视图充气至主屏幕
setContentView(R.layout.activity\u to\u do\u列表);
//获取对UI小部件的引用
ListView myListView=(ListView)findViewById(R.id.myListView);
final EditText myEditText=(EditText)findViewById(R.id.myEditText);
//创建待办事项的数组列表
最终ArrayList todoItems=新ArrayList();
//创建待办事项的数组列表
最终阵列适配器aa;
//创建阵列适配器以将阵列绑定到列表视图
aa=新阵列适配器(此,
android.R.layout.simple_list_item_1,todoItems);
//将阵列适配器绑定到列表视图
myListView.setAdapter(aa);
myEditText.setOnKeyListener(新视图.OnKeyListener(){
公共布尔onKey(视图v、int keyCode、KeyEvent事件){
if(event.getAction()==KeyEvent.ACTION\u向下)
if((keyCode==KeyEvent.keyCode\u DPAD\u中心)
||(keyCode==KeyEvent.keyCode\u ENTER)){
todoItems.**add***(0,myEditText.getText().toString());
aa.notifyDataSetChanged();
myEditText.setText(“”);
返回true;
}
返回false;
}
});
}
}更换
ArrayList<string>
ArrayList
借
ArrayList
更换
ArrayList<string>
ArrayList
借
ArrayList
从结构上看,如果删除add函数中的“0”参数,它应该可以工作……感谢您的输入,但不幸的是它没有工作:(从结构上看,如果删除add函数中的“0”参数,它应该可以工作……感谢您的输入,但不幸的是它没有工作:(Dystroy Thankyu啊哈,我犯了这么愚蠢的错误(下次请注意拼写检查)天哪,他们为什么不找一个更好的编辑器来指出这一点……我错过了visual studio:(Dystroy Thankyu啊哈,我犯了这么愚蠢的错误(下次请注意拼写检查)天哪,为什么他们不找一个更好的编辑器来指出这一点……我想念visual studio:(