Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Cardslib-如何在CardRecyclerView上为自定义卡的按钮事件设置操作_Android_Xml_Android Recyclerview_Android Cardview_Cardslib - Fatal编程技术网

Android Cardslib-如何在CardRecyclerView上为自定义卡的按钮事件设置操作

Android Cardslib-如何在CardRecyclerView上为自定义卡的按钮事件设置操作,android,xml,android-recyclerview,android-cardview,cardslib,Android,Xml,Android Recyclerview,Android Cardview,Cardslib,我正在尝试使用Cardslib创建一个带有自定义布局行的RecyclerView,当我单击这些行上的按钮时,这些行将展开。我按照定制指南创建了定制布局和定制卡片类,卡片确实像这样正确显示 但我不知道如何设置此卡上视图元素的单击事件 在activity_main.xml中,我有一个CardRecyclerView: <it.gmariotti.cardslib.library.recyclerview.view.CardRecyclerView android:layout_widt

我正在尝试使用Cardslib创建一个带有自定义布局行的RecyclerView,当我单击这些行上的按钮时,这些行将展开。我按照定制指南创建了定制布局和定制卡片类,卡片确实像这样正确显示
但我不知道如何设置此卡上视图元素的单击事件

在activity_main.xml中,我有一个CardRecyclerView:

<it.gmariotti.cardslib.library.recyclerview.view.CardRecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    card:list_card_layout_resourceID="@layout/my_cardview_layout"
    android:id="@+id/my_recyclerview"/>
但是,如果我设置
card:list\u card\u layout\u resourceID=“@layout/my\u material\u card\u layout”
在recyclerview和

public MyMaterialCard(Context context) {
super(context, R.layout.my_material_card_layout);}
它们不会显示为卡片:


已经为此工作了2天,但仍然无法使这些按钮正常工作(尝试使用Cardslib材质卡,但当添加扩展时,什么也没有发生)。非常感谢您的帮助,谢谢

在主活动上,添加函数setOnClickListener:

对于(int i=0;i
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<it.gmariotti.cardslib.library.view.ForegroundLinearLayout
    android:id="@+id/card_main_layout"
    style="@style/card.native.main_layout_foreground"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

<ImageView
    android:layout_width="match_parent"
    android:layout_height="210dp"
    android:id="@+id/mycard_image"
    android:src="@drawable/sea"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Title"
    android:id="@+id/mycard_title"
    android:paddingTop="24dp"
    android:paddingLeft="20dp"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="Subtitle"
    android:id="@+id/mycard_subtitle"
    android:paddingLeft="20dp" />

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="@dimen/actions_padding"
    android:paddingLeft="@dimen/actions_padding_left"
    android:paddingRight="@dimen/actions_padding_left">

    <TextView
        android:id="@+id/mycard_suppaction1"
        android:text="SHARE"
        android:background="?android:selectableItemBackground"
        android:layout_width="wrap_content"
        style="@style/card.native.actions"
        android:layout_height="wrap_content"/>


    <TextView
        android:id="@+id/mycard_suppaction2"
        android:text="LEARN MORE"
        android:background="?android:selectableItemBackground"
        android:layout_width="wrap_content"
        style="@style/card.native.actions"
        android:layout_height="wrap_content"/>
</LinearLayout>

</it.gmariotti.cardslib.library.view.ForegroundLinearLayout>


<FrameLayout
    android:id="@+id/card_content_expand_layout"
    style="@style/card.native.main_contentExpand"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    >
</FrameLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ArrayList<Card> cards = new ArrayList<Card>();

    //CardViewNative cardView = (CardViewNative) findViewById(R.id.myMaterialCardView);

    for(int i = 0; i<3; i++) {

        MyMaterialCard card = new MyMaterialCard(this);


        CardExpand expand = new CardExpand(getApplicationContext());
        //Set inner title in Expand Area
        expand.setTitle(" Hidden content");
        card.addCardExpand(expand);
        card.setId("" + i);

        cards.add(card);
    }

    CardArrayRecyclerViewAdapter mCardArrayAdapter = new CardArrayRecyclerViewAdapter(this, cards);

    //Staggered grid view
    CardRecyclerView mRecyclerView = (CardRecyclerView) this.findViewById(R.id.my_recyclerview);
    mRecyclerView.setHasFixedSize(false);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));

    //Set the empty view
    if (mRecyclerView != null) {
        mRecyclerView.setAdapter(mCardArrayAdapter);
    }

}
public class MyMaterialCard extends Card {

ImageView mImage;
TextView mTitle;
TextView mSubtitle;
TextView mActionButton1;
TextView mActionButton2;

public MyMaterialCard(Context context) {
    super(context, R.layout.my_cardview_layout);
}

public MyMaterialCard(Context context, int innerLayout) {
    super(context, innerLayout);
}

@Override
public void setupInnerViewElements(ViewGroup parent, View view) {

    mImage = (ImageView) view.findViewById(R.id.mycard_image);
    mTitle = (TextView) view.findViewById(R.id.mycard_title);
    mSubtitle = (TextView) view.findViewById(R.id.mycard_subtitle);
    mActionButton1 = (TextView) view.findViewById(R.id.mycard_suppaction1);
    mActionButton2 = (TextView) view.findViewById(R.id.mycard_suppaction2);

    mActionButton1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(getContext(), "action 1", Toast.LENGTH_SHORT).show();

        }
    });

    ViewToClickToExpand viewToClickToExpand =
            ViewToClickToExpand.builder()
                    .setupView(mActionButton2);
    setViewToClickToExpand(viewToClickToExpand);
}}
public MyMaterialCard(Context context) {
super(context, R.layout.my_material_card_layout);}
        MyMaterialCard card4 = new MyMaterialCard(this);
        card.setOnClickListener(new Card.OnCardClickListener() {
            @Override
            public void onClick(Card card, View view) {
                Toast.makeText(view.getContext()," Click on ActionArea ",Toast.LENGTH_SHORT).show();
            }
        });


        CardExpand expand = new CardExpand(getApplicationContext());
        //Set inner title in Expand Area
        expand.setTitle(" Hidden content");
        card.addCardExpand(expand);
        card.setId("" + i);

        cards.add(card4);
    }