2017-12-27 5485 views
0

我在回收視圖中添加了5張卡片。我想在點擊它時更改卡片視圖的整個視圖。但只有最後一張牌正在改變其視圖,同時點擊其中任何5張。如何更新卡片視圖佈局點擊它時?

我想更換cardlist佈局replacecard佈局,而點擊卡片視圖 我要去的地方錯了,如果有人幫助
///這裏是我的適配器::

@Override 
    public void onBindViewHolder(MyViewHolder holder, int position) 
    { 
     ItemList itemList = items.get(position); 
     holder.companyname.setText(itemList.getCompanyName()); 
     holder.category.setText(itemList.getCategory()); 
     holder.idcomp.setText(itemList.getIdcomp()); 
     holder.udm.setText(itemList.getUdm()); 
     holder.name.setText(itemList.getName()); 
    } 

    @Override 
    public int getItemCount() { 
     return items.size(); 
    } 


    public class MyViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener 
    { 
     public TextView companyname,category,idcomp,udm,name; 
     List<ItemList> items=new ArrayList<ItemList>(); 
     Context context; 

     public MyViewHolder(View view, Context context,List<ItemList> items) 
     { 
      super(view); 
      this.items=items; 
      this.context=context; 
      companyname=(TextView)view.findViewById(R.id.companyname); 
      category=(TextView)view.findViewById(R.id.category); 
      idcomp=(TextView)view.findViewById(R.id.idcomp); 
      udm=(TextView)view.findViewById(R.id.udm); 
      name=(TextView)view.findViewById(R.id.name); 
      cardlist=(LinearLayout)view.findViewById(R.id.cardlist); 
      replacecard=(LinearLayout)view.findViewById(R.id.replacecard); 
      view.setOnClickListener(this); 


     } 

     @Override 
     public void onClick(View v) { 
      int position=getAdapterPosition(); 
      ItemList itemList= this.items.get(position); 
      cardlist.setVisibility(View.GONE); 
      replacecard.setVisibility(View.VISIBLE); 

     } 
    } 



////and XML File is 



<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_marginTop="@dimen/_10dp" 
    android:orientation="vertical" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view" 
     android:layout_width="match_parent" 
     android:layout_height="100dp" 
     android:gravity="center" 
     android:layout_margin="2dp" 
     card_view:cardCornerRadius="10dp"> 

     <LinearLayout 
      android:id="@+id/cardlist" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="horizontal" 
      android:weightSum="1"> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:layout_margin="@dimen/_10dp" 
       android:layout_weight="0.7"> 

       <TextView 
        android:id="@+id/companyname" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Copper Coil ac" 
        android:textColor="@color/red" 
        android:textStyle="bold" 
        android:textSize="18sp"/> 
       <TextView 
        android:id="@+id/category" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Category" 
        android:layout_marginTop="5dp" 
        android:textColor="@color/black" 
        android:textSize="@dimen/_15sp"/> 
       <TextView 
        android:id="@+id/idcomp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="ASN#0" 
        android:layout_marginTop="5dp" 
        android:textColor="@color/black" 
        android:textSize="@dimen/_15sp"/> 

      </LinearLayout> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:orientation="vertical" 
       android:gravity="center|start" 

       android:layout_margin="5dp" 
       android:layout_weight="0.3"> 

       <TextView 
        android:id="@+id/udm" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="UDM" 
        android:layout_marginTop="5dp" 
        android:textColor="@color/gray" 
        android:textSize="@dimen/_15sp"/> 
       <TextView 
        android:id="@+id/name" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="narendar" 

        android:textColor="@color/black" 
        android:textSize="@dimen/_15sp"/> 
      </LinearLayout> 

     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/replacecard" 
      android:layout_width="match_parent" 
      android:layout_height="100dp" 
      android:orientation="horizontal" 
      android:visibility="gone" 
      android:background="@drawable/listing_bg_active" 
      android:weightSum="1"> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:layout_margin="@dimen/_10dp" 
       android:layout_weight="0.4"> 

       <TextView 
        android:id="@+id/companyname" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Copper Coil ac" 
        android:textColor="@color/white" 
        android:textStyle="bold" 
        android:textSize="18sp"/> 
       <TextView 
        android:id="@+id/category" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="Category" 
        android:layout_marginTop="5dp" 
        android:textColor="@color/white" 
        android:textSize="@dimen/_15sp"/> 
       <TextView 
        android:id="@+id/idcomp" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:text="ASN#0" 
        android:layout_marginTop="5dp" 
        android:textColor="@color/white" 
        android:textSize="@dimen/_15sp"/> 

      </LinearLayout> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:orientation="horizontal" 
       android:gravity="center" 
       android:layout_margin="5dp" 
       android:layout_weight="0.6"> 
       <LinearLayout 
        android:id="@+id/remove" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:gravity="center" 
        android:layout_margin="5dp" 
        android:orientation="vertical"> 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@mipmap/trash"/> 
        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Remove" 
         android:layout_marginTop="2dp" 
         android:textColor="@color/white"/> 

       </LinearLayout> 
       <LinearLayout 
        android:id="@+id/edit" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:gravity="center" 
        android:layout_margin="5dp" 
        android:orientation="vertical"> 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@mipmap/edit"/> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Edit" 
         android:layout_marginTop="2dp" 
         android:textColor="@color/white"/> 
       </LinearLayout> 
       <LinearLayout 
        android:id="@+id/detail" 
        android:layout_width="wrap_content" 
        android:layout_height="match_parent" 
        android:gravity="center" 
        android:layout_margin="5dp" 
        android:orientation="vertical"> 

        <ImageView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:src="@mipmap/view"/> 

        <TextView 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:text="Detail" 
         android:layout_marginTop="2dp" 
         android:textColor="@color/white"/> 

       </LinearLayout> 
      </LinearLayout> 

     </LinearLayout> 

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






</LinearLayout> 

回答

0

更改卡的顏色-視圖。