标签:
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Fruit fruit = fruitList.get(position); //Toast.makeText(this,fruit.getName(),Toast.LENGTH_SHORT).show();/*出现错误,这也是错误的写法,
提示can‘t resolve method ’make text(OnClickListener,java.lang.String,int)‘*/ Toast.makeText(MainActivity.this,fruit.getName(),Toast.LENGTH_SHORT).show(); } });
在listview的onItemClick方法中写Toast.maketext()的时候其中参数Context,不能含糊不清直接写this,而是要正确的写出MainActivity.this。
标签:
原文地址:http://www.cnblogs.com/harrain/p/5933247.html