我在我的主要活動中有一個無效返回類型的方法。如果我在方法內部創建一個Toast,它會顯示錯誤「類型不匹配:不能將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();
}
能否請您告訴我們,代碼? – Mudassir 2011-04-22 07:14:19
某些代碼片段會有幫助。 – shihpeng 2011-04-22 07:14:34
您可以發佈方法嗎? – 2011-04-22 07:14:41