2011-12-04 1 views
2

私は前に働いた次のコードを持っています。私は別のアクティビティ(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; 
     } 
    } 
} 

です私は間違っている?

+0

は、あなたがこの活動に 'ListView'を追加して使用しますか? – havexz

+0

これに何か運がありますか?私は同じ問題を抱えている – amadib

答えて

1

これを試してみてください:これは私の作品

Button button1 = (Button)findViewById(R.id.button); 
button1.setOnClickListener(this); 

をし、それはあなたの問題を解決するかもしれないが、それは仕事ができることwouldntはなぜ他の私が見ていないでしょう良いコードのように見えます。

+0

私はそれを試して、それは動作します。しかし、それはコードの別の部分であった可能性もあります。とにかく、助けてくれてありがとう。 –

0

私はちょうど同じ問題を抱えていましたが、コードは前にコンパイルして正常に動作していました。

実際には、XMLレイアウトファイルで項目を並べ替えたことが実際に起こりました。 After(Eclicpe)Menu - Project - Clean私はもう一度元気だった。

0

特定のビューにキャストする必要があります。あなたがのImageButtonを使用しているならば、と言う代わりに、この

View help_button = findViewById(R.id.help_button); 

この

ImageButton help_button = (ImageButton)findViewById(R.id.help_button); 
関連する問題