我有以下代碼以前的工作。然後後,我開始對另一個活動的工作(實現ListActivity,並通過擴展ArrayAdapter提供每行自定義視圖),我開始獲取的RuntimeException:setOnClickListener抱怨說,我應該使用setOnItemClickListener
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ezport/com.ezport.EzportActivity}: java.lang.RuntimeException: Don't call setOnClickListener for an AdapterView. You probably want setOnItemClickListener instead
這裏是代碼
package com.ezport;
import android.app.Activity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.view.View.OnClickListener;
public class EzportActivity extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
View view_orders_button = findViewById(R.id.view_orders_button);
view_orders_button.setOnClickListener(this);
View submit_invoice_button = findViewById(R.id.submit_invoice_button);
submit_invoice_button.setOnClickListener(this);
View help_button = findViewById(R.id.help_button);
help_button.setOnClickListener(this);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.view_orders_button:
Intent order_intent = new Intent(this, OrderActivity.class);
startActivity(order_intent);
break;
case R.id.submit_invoice_button:
//Intent i = new Intent(this,)
break;
case R.id.help_button:
Intent help_intent = new Intent(this, HelpActivity.class);
startActivity(help_intent);
break;
}
}
}
什麼了我做錯了?
的'ListView'這個活動? – havexz
有沒有這方面的運氣?我有同樣的問題 – amadib