2011-10-18 7 views
0

나는 선형 레이어를 클릭 가능하게 설정했으며 버튼처럼 동작하고 새로운 활동을 시작하려고합니다. 그러나 나는 오류가있어. 여기가 된 .java 버튼 bProduct1 = (버튼) findViewById를 (R.id.llproduct1) 인Android 클릭 가능한 레이어

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

.XML의 일부이고; 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'.

의 onclick 방법은 View 클래스에 선언
그러므로 자바 코드 원인 ClassCastException이..이 아니라 버튼!
있는 LinearLayout하고있는 LinearLayout과 버튼 모두보기 클래스를 상속하고 있습니다.

은 왜 당신은 아래의 코드를 수정하지 않습니다.

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

감사합니다. 하지만 난 하나 더 오류가있어, 여전히 오류가 있다고 생각합니다. <인 텐트 필터><액션 android : name = "com.testing.PRODUCTDESCRIPTION"/> user996481

+0

해결되었습니다. 감사!!! – user996481