2011-10-18 30 views
0

クリック可能になるように線形レイヤーを設定し、ボタンのように動作させて新しいアクティビティを開始します。しかし、私はエラーが発生しました。ここでこれはの.java ボタンbProduct1 =(ボタン)findViewById(R.id.llproduct1)での.xmlAndroidのクリック可能なレイヤー

  <LinearLayout 
      android:id="@+id/llproduct1" 
      android:layout_width="fill_parent" android:layout_height="wrap_content" 
      android:orientation="vertical" android:clickable="true"> 
      <ImageView .... /> 
      <TextView .... /> 
      </LinearLayout> 

の一部です。 bProduct1.setOnClickListener(新View.OnClickListener()何が悪かったのか{

 @Override 
     public void onClick(View v) { 
      // TODO Auto-generated method stub 
      startActivity(new Intent("com.testing.PRODUCTDESCRIPTION")); 
     } 

+0

あなたが得るエラーは何ですか? –

+1

ClassCastException明らかに – Blackbelt

答えて

0
Button bProduct1 = (Button) findViewById(R.id.llproduct1); 

あなたがボタンにあなたのLinearLayoutをキャストすることはできません。しかし、あなたが行うことができます:?。

LinearLayout bProduct1 = (LinearLayout) findViewById(R.id.llproduct1); 
bProduct1.setOnClickListener(...) 

see this for reference

+0

ありがとう!!しかし、私はもう一つのエラーがあると思うが、まだエラーがある。 <活動のアンドロイド:名= "ProductDescription" アンドロイド:ラベル= "@文字列/ APP_NAME"> <意図-フィルタ> <アクションアンドロイド:名= "com.testing.PRODUCTDESCRIPTION" /> <カテゴリアンドロイド:name = "android.intent.category.DEFAULT" /> user996481

+0

解決済み。感謝!!! – user996481

0

"bProd uct1 =(ボタン)findViewById(R.id.llproduct1); 「

'llproduct1は' のLinearLayout !!ないボタンです。
ため、Javaコード原因のClassCastException。

のonClickメソッドが
。Viewクラスで宣言されているとのLinearLayoutとボタンの両方がViewクラスを継承しています。

ので、なぜあなたは以下のコードを修正しない。

View bProduct1 = findViewById(R.id.llproduct1); 
bProduct1.setOnClickListener(......); 
+0

ありがとうございます!しかし、私はもう一つのエラーがあると思うが、まだエラーがある。 user996481

+0

解決済みです。感謝!!! – user996481

関連する問題