我收到一条错误消息“View 类型中的方法 setOnKeyListener(View.OnKeyListener) 不适用于参数 (new OnKeyListener(){})”
我该如何克服这个问题?
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_app);
ListView myListView =(ListView)findViewById(R.id.myListView);
final EditText myEditText =(EditText)findViewById(R.id.myEditText);
final ArrayList<String> toDolist =new ArrayList<String>();
final ArrayAdapter<String> aa;
aa=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,toDolist);
myListView.setAdapter(aa);
myEditText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(event.getAction()==KeyEvent.ACTION_DOWN)
if(keyCode==KeyEvent.KEYCODE_DPAD_CENTER){
toDolist.add(0,myEditText.getText().toString());
aa.notifyDataSetChanged();
myEditText.setText("");
return true;
}
return false;
}
});