我在布局中有一个卡片视图,它有两个文本视图和一个图像视图,我有一个使用卡片视图设置项目的回收器视图。我想要实现的是在点击 Card View 时启动 Bottom Sheet
这是主要活动中的代码
列表代码
List<Item> lstItem;
lstItem = new ArrayList<>();
lstItem.add(new Item("Samsung","Smartphones","QualitlstItem = new ArrayList<>();y Samsung Smartphones",R.drawable.samsung,"21000"));
lstItem.add(new Item("Lenovo","Smartphones","Quality Lenovo smartphones",R.drawable.lenovo,"15000"));
将 Recycler View Adapter 附加到 Main Activity 的代码
FragmentManager fragmentManager = getSupportFragmentManager();
RecyclerViewAdapter2 mainAdapter2 = new RecyclerViewAdapter2(lstItem,fragmentManager);
mainRecyclerView.setLayoutManager(new GridLayoutManager(this,3));
mainRecyclerView.setAdapter(mainAdapter2);
Recycler View Adapter 2代码
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class RecyclerViewAdapter2 extends RecyclerView.Adapter<RecyclerViewAdapter2.MyViewHolder> {
private Context context;
private List<Item> data;
private FragmentManager fragmentManager;
public RecyclerViewAdapter2(List<Item> data, FragmentManager fragmentManager) {
this.data = data;
this.fragmentManager = fragmentManager;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_items, parent, false);
return new MyViewHolder(view);
}
}
小怪兽爱吃肉
蝴蝶不菲
呼如林
相关分类