我的主要活动中有一个返回类型为 void 的方法。如果我在方法内创建一个 Toast,它会显示错误“类型不匹配:无法将 void 转换为 toast”。谁能解释什么是问题并帮助我解决问题?
public class HelloList<View> extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES));
ListView lv=getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> arg0,android.view.View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
// Toast.makeText(getApplicationContext(), ((TextView) arg1).getText(),Toast.LENGTH_SHORT).show();
System.out.println(arg2);
String s="position is "+arg2;
Toast.makeText(getApplicationContext(),s,Toast.LENGTH_SHORT).show();
}
});
registerForContextMenu(lv);
/*int i=lv.getCheckedItemPosition();
Toast.makeText(getApplicationContext(),,Toast.LENGTH_SHORT).show();*/
}
public void onCreateContextMenu(ContextMenu menu, android.view.View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(0x7f030000, menu);
}
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case 0x7f030000:
editNote(info.id);
return true;
default:
return super.onContextItemSelected(item);
}
}
public void editNote(long id) {
Toast m=Toast.makeText(this, "asdasd", 3);
m.show();
}