卡视图单击卡移至新活动 [英] Card View Click on Card Move To New Activity

查看:58
本文介绍了卡视图单击卡移至新活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Android编程的新手,正在从事卡的布局.我想知道如何使它可点击?

I am new to Android programming and was working on a card layout. I was wondering, how do I make it clickable?

android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"

我在卡片小部件上有该标签,然后我想知道在哪里放置可点击操作?我希望能够单击该卡片,它会获得卡片的ID,然后显示一个新的Intent活动

I have that on my card widget and then I wanted to know where to put an on clickable action? I want to be able to click the card, it gets the id of the card, and then displays a new intent activity

这是我用于加载适配器的活动的代码

This is my code for the activity to load the adapter

setContentView(R.layout.activity_my);


    RecyclerView recList = (RecyclerView) findViewById(R.id.cardList);
    recList.setHasFixedSize(true);
    LinearLayoutManager llm = new LinearLayoutManager(this);
    llm.setOrientation(LinearLayoutManager.VERTICAL);
    recList.setLayoutManager(llm);

    ContactAdapter ca = new ContactAdapter(createList(30));

    recList.setAdapter(ca);

推荐答案

如果正确使用了实现,则代码应如下所示:

If you used the implementation correctly, your code should go like this:

card - is the card view you instantiated to display on your ui


card.setOnClickListener(...);

在onClickListener的实现中,您应该具有以下内容:

In your implementation of the onClickListener, you should have this:

@Override
public void onClick(Card c ,View v) {
    Intent intent = new Intent(MyActivity.this, NextActivity.class);
    startActivity(intent);
}

这几乎是您从卡片开始新活动所需的全部

that is pretty much all you need to start a new activity from the card

这篇关于卡视图单击卡移至新活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆