1

I have a recyclerview which will get installed apk in device and sort them with cardview as the header says I want to show a specific text only on first cardview item (recyclerview viewholder)

Here's my code:

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();
}

}

Any help will greatly appreciated

pourya011
  • 91
  • 2
  • 13
  • https://stackoverflow.com/a/26573338/7104450 check this link – Shashank Verma Dec 19 '17 at 09:38
  • 1
    you can simply keep that view invisible or gone for the item other than 0th position – Vivek Mishra Dec 19 '17 at 09:59
  • @VivekMishra dont know why but you throw an frequency in my brain with your simple answer and made me to make some changes and now its working perfect ,upvoting you,also ill update the question with changes i made maybe it become useful to others – pourya011 Dec 19 '17 at 10:38

1 Answers1

0

i came over with my own solution

simply added a switch statement to getting position and doing some extra stuff on that specific position like this:

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();
}

}
pourya011
  • 91
  • 2
  • 13