2017-07-01 10 views
0

私はcardViewとその中にtextViewというデータを表示しています。 of this textViewアプリケーションクラッシュ。テキストクリックで表示アプリケーションノート応答

.xmlファイルは

 <android.support.v7.widget.CardView 
     android:id="@+id/spcard_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center" 
     android:layout_margin="@dimen/card_margin" 
     android:elevation="3dp" 
     card_view:cardCornerRadius="@dimen/card_album_radius"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 


     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 

      <ImageView 
       android:id="@+id/spthumbnail" 
       android:layout_width="match_parent" 
       android:layout_height="@dimen/album_cover_height" 
       android:background="?attr/selectableItemBackgroundBorderless" 
       android:clickable="true" 
       android:scaleType="fitXY" 
       android:layout_alignParentTop="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 

      <TextView 
       android:id="@+id/sptitle" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:paddingLeft="@dimen/album_title_padding" 
       android:minLines="3" 
       android:paddingRight="@dimen/album_title_padding" 
       android:paddingTop="@dimen/album_title_padding" 
       android:textColor="@color/album_title" 
       android:textSize="@dimen/album_title" 
       android:layout_below="@+id/spthumbnail" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentStart="true" /> 

      <TextView 
       android:id="@+id/spcount" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@id/sptitle" 
       android:paddingBottom="@dimen/songs_count_padding_bottom" 
       android:minLines="2" 
       android:paddingLeft="@dimen/album_title_padding" 
       android:paddingRight="@dimen/album_title_padding" 
       android:textSize="@dimen/songs_count" /> 

      <ImageView 
       android:id="@+id/spoverflow" 
       android:layout_width="@dimen/ic_album_overflow_width" 
       android:layout_height="@dimen/ic_album_overflow_height" 
       android:layout_alignParentRight="true" 
       android:layout_below="@id/spthumbnail" 
       android:layout_marginTop="@dimen/ic_album_overflow_margin_top" 
       android:scaleType="centerCrop" 
       android:src="@drawable/ic_dots" /> 
     </RelativeLayout> 
<LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:weightSum="2"> 
    <Button 
     android:id="@+id/spdetailsbuynow" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="buy now" 
     android:textColor="#ffffff" 
     android:background="@drawable/spdetailsbutton"/> 
    <Button 
     android:id="@+id/spdetailsaddcart" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="add cart" 
     android:textColor="#ffffff" 
     android:layout_alignParentRight="true" 
     android:background="@color/orange_500"/> 
</LinearLayout> 
     </LinearLayout> 

    </android.support.v7.widget.CardView> 

され、エラー・ログには、

java.lang.IllegalStateExceptionです:ため 親や祖先コンテキストに(ビュー)真の方法を見つけることができませんでしたandroid:onClick属性は で定義されています。表示クラスandroid.widget.LinearLayout

+0

javaコードを投稿 – Anil

+0

関連コードとlogcatも投稿する必要があります。 – MikeT

+1

より明確にしてください。あなたはtextViewをクリックしようとしていますか?または、ボタンをクリックしてテキストをtextViewに表示する必要がありますか?また、あなたのJavaクラスでどのように実装しているかを示してください。 – Opiatefuchs

答えて

-2
use like this: 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:background="@color/off_white_bg" 
android:orientation="vertical" 
android:layout_height="match_parent"> 


<android.support.v7.widget.CardView 
    android:id="@+id/spcard_view" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_gravity="center" 
    android:layout_margin="@dimen/card_margin" 
    android:elevation="3dp" 
    card_view:cardCornerRadius="@dimen/card_album_radius"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical"> 


    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <ImageView 
      android:id="@+id/spthumbnail" 
      android:layout_width="match_parent" 
      android:layout_height="@dimen/album_cover_height" 
      android:background="?attr/selectableItemBackgroundBorderless" 
      android:clickable="true" 
      android:scaleType="fitXY" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <TextView 
      android:id="@+id/sptitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="@dimen/album_title_padding" 
      android:minLines="3" 
      android:paddingRight="@dimen/album_title_padding" 
      android:paddingTop="@dimen/album_title_padding" 
      android:textColor="@color/album_title" 
      android:textSize="@dimen/album_title" 
      android:layout_below="@+id/spthumbnail" 
      android:layout_alignParentLeft="true" 
      android:layout_alignParentStart="true" /> 

     <TextView 
      android:id="@+id/spcount" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/sptitle" 
      android:paddingBottom="@dimen/songs_count_padding_bottom" 
      android:minLines="2" 
      android:paddingLeft="@dimen/album_title_padding" 
      android:paddingRight="@dimen/album_title_padding" 
      android:textSize="@dimen/songs_count" /> 

     <ImageView 
      android:id="@+id/spoverflow" 
      android:layout_width="@dimen/ic_album_overflow_width" 
      android:layout_height="@dimen/ic_album_overflow_height" 
      android:layout_alignParentRight="true" 
      android:layout_below="@id/spthumbnail" 
      android:layout_marginTop="@dimen/ic_album_overflow_margin_top" 
      android:scaleType="centerCrop" 
      android:src="@drawable/ic_dots" /> 
    </RelativeLayout> 
<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="2"> 
<Button 
    android:id="@+id/spdetailsbuynow" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="buy now" 
    android:textColor="#ffffff" 
    android:background="@drawable/spdetailsbutton"/> 
<Button 
    android:id="@+id/spdetailsaddcart" 
    android:layout_width="0dp" 
    android:layout_height="wrap_content" 
    android:layout_weight="1" 
    android:text="add cart" 
    android:textColor="#ffffff" 
    android:layout_alignParentRight="true" 
    android:background="@color/orange_500"/> 
</LinearLayout> 
    </LinearLayout> 

</android.support.v7.widget.CardView> 

</LinearLayout> 
+0

これは何のためのものなのか、何を変更すればよいのか、投稿コードは助けにならない – jagapathi

+1

質問コードに違いは見えません... – Opiatefuchs

+0

あなたのJavaクラスのpatelでの実装方法を教えてください。 –

関連する問題