如何更新卡片视图布局点击它时?

我在回收视图中添加了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>

回答:

更改卡的颜色-视图。

以上是 如何更新卡片视图布局点击它时? 的全部内容, 来源链接: utcz.com/qa/266944.html

回到顶部