我有一个RecycerView,它将在设备中安装apk,并与cardview排序,因为标题说我想只在第一个cardview项上显示特定的文本(RecycerView viewholder)
private Context context1;
private List<String> stringList;
IZIGaapsAppRecycleView(Context context, List<String> list) {
context1 = context;
stringList = list;
}
static class ViewHolder extends RecyclerView.ViewHolder {
CardView cardView;
ImageView imageView;
TextView textView_App_Name;
ViewHolder(View view) {
super(view);
cardView = view.findViewById(R.id.card_view);
imageView = view.findViewById(R.id.imageView);
textView_App_Name = view.findViewById(R.id.Apk_Name);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view2 = LayoutInflater.from(context1).inflate(R.layout.cardview_layout, parent, false);
return new ViewHolder(view2);
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
IZIGaapsApkInfo IZIGaapsApkInfo = new IZIGaapsApkInfo(context1);
final String ApplicationPackageName = stringList.get(position);
String ApplicationLabelName = IZIGaapsApkInfo.GetAppName(ApplicationPackageName);
Drawable drawable = IZIGaapsApkInfo.getAppIconByPackageName(ApplicationPackageName);
viewHolder.textView_App_Name.setText(ApplicationLabelName);
viewHolder.imageView.setImageDrawable(drawable);
viewHolder.cardView.setOnClickListener(view ->
Snackbar.make(view, ApplicationLabelName, Snackbar.LENGTH_LONG).setAction("ط´ط±ظˆط¹ ط¶ط¨ط·", view1 -> {
Intent openingApp = new Intent(context1, IZIGaapsMPPermissions.class);
openingApp.putExtra(IZIGaapsConst.APP_ID, ApplicationPackageName);
context1.startActivity(openingApp);
}).show());
}
@Override
public int getItemCount() {
return stringList.size();
}
我想出了自己的解决办法
简单地为get position添加了一个switch语句,并在该特定位置上执行一些额外的操作,如下所示:
private Context context1;
private List<String> stringList;
IZIGaapsAppRecycleView(Context context, List<String> list) {
context1 = context;
stringList = list;
}
static class ViewHolder extends RecyclerView.ViewHolder {
CardView cardView;
ImageView imageView;
TextView textView_App_Name;
TextView textView_specific_text;
ViewHolder(View view) {
super(view);
cardView = view.findViewById(R.id.card_view);
imageView = view.findViewById(R.id.imageView);
textView_App_Name = view.findViewById(R.id.Apk_Name);
textView_specific_text = view.findViewById(R.id.texttwo);
}
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view2 = LayoutInflater.from(context1).inflate(R.layout.cardview_layout, parent, false);
return new ViewHolder(view2);
}
@SuppressLint("SetTextI18n")
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
IZIGaapsApkInfo IZIGaapsApkInfo = new IZIGaapsApkInfo(context1);
final String ApplicationPackageName = stringList.get(position);
String ApplicationLabelName = IZIGaapsApkInfo.GetAppName(ApplicationPackageName);
Drawable drawable = IZIGaapsApkInfo.getAppIconByPackageName(ApplicationPackageName);
viewHolder.textView_App_Name.setText(ApplicationLabelName);
//added a switch statement to getting position and doing some extra stuff on that specific position
switch(position){
case 0:
viewHolder.textView_specific_text.setText(mytext);
break;
}
viewHolder.imageView.setImageDrawable(drawable);
viewHolder.cardView.setOnClickListener(view ->
Snackbar.make(view, ApplicationLabelName, Snackbar.LENGTH_LONG).setAction("ط´ط±ظˆط¹ ط¶ط¨ط·", view1 -> {
Intent openingApp = new Intent(context1, IZIGaapsMPPermissions.class);
openingApp.putExtra(IZIGaapsConst.APP_ID, ApplicationPackageName);
context1.startActivity(openingApp);
}).show());
}
@Override
public int getItemCount() {
return stringList.size();
}
}
这是我的项的代码。问题是,每个项目都显示在一整页的应用程序中。请帮我解决这个问题:
问题就在这里:我创建了世界上最简单的RecyclerView,但它只显示第一个项目。我不明白为什么。谢谢你的帮助。 item_layout.xml mainactivity.java
最后是我的适配器类
这里是ICS文件内容: 在雷鸟和Gmail中,我只能看到第一个(按顺序)事件。这是邮件客户端的正常行为吗?我应该为每个VEVENT创建单独的. ics文件,然后用单个邮件发送吗?提前感谢帮助!
我遵循了以下线程中接受的答案(来自@kcoppock)中的步骤。https://stackoverflow.com/a/15264039/3296263 或网格视图,包含两列和自动调整大小的图像 编辑:这是代码。网格视图代码: 网格项布局:main_category_list_content.xml 自定义SquareImageView类: 适配器代码: 我设置适配器的活动代码 我没有显示所有6个