I want to save data in recyclerview using ArrayList dynamically, but I'm having a problem.
Every time I add data in recycler view, it replaces the previous data and shows only the last data I have entered.
I'm passing that value using SharedPreference to next activity like this
builder.setNeutralButton("Save", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
SharedPreferences sp = getSharedPreferences(mypreference,0);
SharedPreferences.Editor editor = sp.edit();
size = sp.getInt("size",size);
size = size+1;
editor.putString("name"+size , scanResult);
editor.putInt("size" , size);
editor.commit();
finish();
}
});
This is the activity where I'm adding data in ArrayList;
Results.java
ArrayList<String> data = new ArrayList<>();
pref = getSharedPreferences(mypreference,MODE_PRIVATE);
int size = pref.getInt("size",0);
String scanResult = pref.getString("name"+size,"");
data.add(scanResult);
listView_result = findViewById(R.id.listResult);
LinearLayoutManager layoutManager = new
LinearLayoutManager(getApplicationContext());
listView_result.setLayoutManager(layoutManager);
ResultAdapter adapter = new ResultAdapter(Results.this, data);
listView_result.setAdapter(adapter);
This the adapter for recyclerview
ResultAdapter.java
public class ResultAdapter extends RecyclerView.Adapter<ResultAdapter.ViewHolder> {
private Context context;
private ArrayList<String> code;
ResultAdapter(Context context , ArrayList<String> code) {
this.context = context;
this.code = code;
}
#NonNull
#Override
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_text , parent , false);
return new ViewHolder(v);
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position)
{
holder.txt.setText( code.get(position));
}
#Override
public int getItemCount() {
return code.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
TextView txt;
ViewHolder(View itemView) {
super(itemView);
txt = itemView.findViewById(R.id.textView_list);
}
}
}
int size = pref.getInt("size",0);
String scanResult = pref.getString("name"+size,"");
data.add(scanResult);
Above should be
int size = pref.getInt("size",0);
for (int i = 0; i < size; ++i) {
String scanResult = pref.getString("name"+i,"");
data.add(scanResult);
}
Related
hi I want to make a recycler view in two different fragments in which one fragment has limit recycler view list which is shown only 4 lists and another fragment in which all the list item is shown, thanks in advance.
main class code,
private void populatelist() {
List<reviewModel> reviewModelList = new ArrayList<>();
for (int i = 1; i < 20; i++) {
int imges = R.drawable.ic_userlogin;
String names = "User Name is " + i;
String dates = "New Dates is " + i;
String detail = "User details about is " + i;
reviewModel models = new reviewModel(names, dates, detail, 4, imges);
reviewModelList.add(models);
}
setupRecycle(reviewModelList);
}
private void setupRecycle(List<reviewModel> reviewModelList) {
if (adaptOverView == null)
adaptOverView = new reviewAdapt(this, 5);
adaptOverView.setReviewList(reviewModelList);
LinearLayoutManager layout = new LinearLayoutManager(this);
layout.setSmoothScrollbarEnabled(true);
recyclerOverView.setLayoutManager(layout);
recyclerOverView.setHasFixedSize(true);
recyclerOverView.setAdapter(adaptOverView);
}
adapter class code,
private Context mContext;
private List<reviewModel> reviewList;
private int limit;
public void setReviewList(List<reviewModel> list){
this.reviewList = list;
this.notifyDataSetChanged();
}
public reviewAdapt(Context mContext, int limit) {
this.mContext = mContext;
this.limit = limit;
}
public reviewAdapt(Context mContext, List<reviewModel> reviewList, int limit) {
this.mContext = mContext;
this.reviewList = reviewList;
this.limit = limit;
}
#NonNull
public ViewHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(mContext).inflate(R.layout.review_design, parent, false);
ViewHolder holder = new ViewHolder(view);
return holder;
}
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
if (position < limit) {
reviewModel model = reviewList.get(position);
Log.d("TAG", "onBindViewHolder_Limit: "+limit);
Log.d("TAG", "onBindViewHolder_Position_Is_InLimit: "+position);
holder.textViewName.setText(model.getName());
holder.textViewDate.setText(model.getDate());
holder.ratingBarRecycle.setRating(model.getRatingBar());
holder.textViewDetails.setText(model.getDetails());
holder.imageViewRecycle.setImageResource(model.getImg());
}
}
#Override
public int getItemCount() {
return reviewList.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView textViewName, textViewDate, textViewDetails;
RatingBar ratingBarRecycle;
ImageView imageViewRecycle;
public ViewHolder(#NonNull View itemView) {
super(itemView);
textViewName = itemView.findViewById(R.id.name_review);
textViewDate = itemView.findViewById(R.id.date_review);
textViewDetails = itemView.findViewById(R.id.details_review);
ratingBarRecycle = itemView.findViewById(R.id.review_ratingsBar);
imageViewRecycle = itemView.findViewById(R.id.profile_image);
}
}
}
As per my understanding , You are using limit variable for restricting listing size for fragment. But you are not using it rightly. If I am not wrong, Try to restrict item count for in adapter as below -
#Override
public int getItemCount() {
return limit;
}
I'm creating an android app, in which I'm using recyclerView and the row of recyclerView is having editText.
This is my ReadingAdapter class
public class ReadingAdapter extends RecyclerView.Adapter<ReadingAdapter.ViewHolder> implements AdapterView.OnItemSelectedListener {
Context context;
String valOpenReading, valClosReading, valConsumption;
private List<ReadingData> readingList;
static String[] arrValOpenRead, arrValClosRead, arrValConsumption;
public ReadingAdapter(Context context, List<ReadingData> readingList) {
this.context = context;
this.readingList = readingList;
arrValOpenRead = new String[readingList.size()];
arrValClosRead = new String[readingList.size()];
arrValConsumption = new String[readingList.size()];
}
#Override
public ReadingAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.reading_sheet_layout, parent, false);
return new ReadingAdapter.ViewHolder(view);
}
#Override
public void onBindViewHolder(final ReadingAdapter.ViewHolder holder, final int position) {
ReadingData tempData = readingList.get(position);
holder.pdtName.setText(tempData.pdtName);
holder.keyId.setText("Key "+tempData.keyId);
holder.etClosRead.addTextChangedListener(new TextWatcher() {
boolean ignore = false;
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void afterTextChanged(Editable s) {
if (ignore)
return;
ignore = true;
valOpenReading = holder.etOpenRead.getText().toString();
arrValOpenRead[position] = valOpenReading;
valClosReading = s.toString().equals("") ? "0": s.toString();
arrValClosRead[position] = valClosReading;
if (!valOpenReading.equals("")) {
if (Integer.parseInt(valClosReading) < Integer.parseInt(valOpenReading)) {
Toast.makeText(context, "Check once! closing reading should be more than opening reading!", Toast.LENGTH_LONG).show();
valConsumption = "0";
holder.consumption.setText("");
} else {
valConsumption = (Integer.parseInt(valClosReading) - Integer.parseInt(valOpenReading))+"";
arrValConsumption[position] = valConsumption;
holder.consumption.setText(valConsumption);
}
} else
Toast.makeText(context, "Please fill the opening reading!", Toast.LENGTH_SHORT).show();
ignore = false;
}
});
}
#Override
public int getItemCount() {
return readingList.size();
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
public class ViewHolder extends RecyclerView.ViewHolder{
TextView pdtName, keyId, consumption;
EditText etOpenRead, etClosRead;
public ViewHolder(View view) {
super(view);
pdtName = (TextView)view.findViewById(R.id.txt_list_pdt_supp);
keyId = (TextView)view.findViewById(R.id.key_set);
etOpenRead = (EditText)view.findViewById(R.id.open_val_set);
etClosRead = (EditText)view.findViewById(R.id.clos_val_set);
consumption = (TextView)view.findViewById(R.id.consumption_val);
}
}
}
This is my ReadingData.java
public class ReadingData {
String pdtName, keyId, openReading, closReading, consumption;
public ReadingData(String pdtName, String keyId) {
this.pdtName = pdtName;
this.keyId = keyId;
}
}
Here, if I enter value in the starting items of the recyclerView then as I scroll up the items to the bottom of the list, the last item will have that value.
Please ignore the quality of image as we can't upload above of 2MiB of snap.
Here the views are recycled as the list is scrolled. How to prevent the copying values to the other item in the list.
And that Toast is also repeated several times. How to stop this.
update:
By the suggetion of LQ Gioan through the SO question How ListView's recycling mechanism works , I got the logic how ListView actually works with recycling of views.
But I'm not sure whether the recyclerView also works same.
But here in my case, how can I implement this process. pls someone help me here.
RecyclerView reuse views, in fact it only generate the as many as views that is visible on the screen. so it's expected if you can see a value you set for other rows
The solution would be set all attributes of the view that you are changing to default or whatever the row should present from your data set
So put addTextChangedListener insode ViewHolder constructor(you can get position by calling getAdapterPosition()) for better performance and set the editText value inside onBindViewHolder method from your data set
Your Activity Code:
ListView listview = (ListView) findViewById(R.id.list_view);
listview.setItemsCanFocus(true);
Adapter adapter = new Adapter (YourActivity.this, YourArrayList);
listview .setAdapter(adapter);
Adapter class
public class Adapter extends BaseAdapter {
// Declare Variables \\
Context mContext;
LayoutInflater inflater;
Activity act;
String[] temp;
public Adapter(Context context, ArrayList<String> list) {
mContext = context;
inflater = LayoutInflater.from(mContext);
act = (Activity) context;
//-------Temp String Array-------\\
temp = new String[this.count];
for (int i = 0; i < this.count; i++) {
temp[i] = list.get(i);
}
//---------------------------\\
}
public class ViewHolder {
TextView optionTitle;
EditText optionText;
int ref;
}
#Override
public int getCount() {
return list.size;
}
#Override
public Object getItem(int position) {
return temp[position];
}
#Override
public long getItemId(int position) {
return position;
}
public View getView(final int position, View view, ViewGroup parent) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.lv_items_add_ques_options_mcq, null);
holder.optionTitle = (TextView) view.findViewById(R.id.add_ques_opts_count_mcq_tv);
holder.optionText = (EditText) view.findViewById(R.id.add_ques_opts_title_mcq_et);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
holder.ref = position;
holder.optionTitle.setText(getCharForNumber(position) + ":");
holder.optionText.setText(temp[position]);
holder.optionText.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
}
#Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
}
#Override
public void afterTextChanged(Editable arg0) {
temp[holder.ref] = arg0.toString().trim();
}
});
return view;
}
public void getList() {
StaticValues.arrayListOptions = new ArrayList<String>(Arrays.asList(temp));
StaticValues.arrayListOptionsCount = new ArrayList<String>();
for (int i = 0; i < count; i++) {
StaticValues.arrayListOptionsCount.add(String.valueOf(i+1));
Log.e("err_al", StaticValues.arrayListOptions.get(i));
Log.e("err_al", StaticValues.arrayListOptionsCount.get(i));
}
}
private String getCharForNumber(int i) {
char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
if (i > 25) {
return null;
}
return Character.toString(alphabet[i]);
}}
Recyclerview has 4 items i.e; textView1, textView2, EditText1 and Checkbox1.
Recyclerview has got 24 rows as well. EditText is invisible on initial stage thenit will be visible only when the corresponding checkbox checked by the user. EditText accepts only numbers.
The app is working fine so far this much.
Now I need to get value of all EditTexts and need to display it on another Textview which is not in the part of Recyclerview?
Recyclerview Screenshot- Output Link
Code Samples.
ExamFragment.java
public class ExamFragment extends Fragment {
RecyclerView recyclerView;
ExamFragmentAdapter adapter;
ArrayList<tblChapters> datalistChapters = new ArrayList<>();
TextView txtQcount,txtQCounttotal;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v= inflater.inflate(R.layout.fragment_exam, container, false);
txtQCounttotal=(TextView) v.findViewById(R.id.txtQCounttotal);
txtQcount=(TextView) v.findViewById(R.id.txtQCount);
recyclerView=(RecyclerView)v.findViewById(R.id.recycler_view);
conn = new ConnectionClass(); //connection initialisation
datalistChapters = conn.getChaptersAndCount(modeid, subjectid);
adapter = new ExamFragmentAdapter(datalistChapters, getActivity());
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
return v;
}
}
ExamFragmentAdapter.java
public class ExamFragmentAdapter extends RecyclerView.Adapter<ExamFragmentAdapter.MyViewHolder> {
private LayoutInflater inflater;
MyViewHolder holder;
Context mContext;
ArrayList<tblChapters> chapterList=new ArrayList<>();
public ExamFragmentAdapter(ArrayList<tblChapters> chapterList, Context context) {
inflater = LayoutInflater.from(context);
this.chapterList = chapterList;
mContext=context;
}
#Override
public ExamFragmentAdapter.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = inflater.inflate(R.layout.chapter_list_row, parent, false);
holder = new MyViewHolder(view, new MyCustomEditTextListener());
return holder;
}
#Override
public void onBindViewHolder(final ExamFragmentAdapter.MyViewHolder holder, final int position) {
holder.title.setTextColor(Color.BLACK);
holder.slno.setTextColor(Color.BLACK);
holder.noOfQst.setTextColor(Color.BLACK);
holder.noOfQst.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
holder.noOfQst.setGravity(Gravity.CENTER);
holder.title.setText(chapterList.get(position).getTitle()); // Setting Chapter title
holder.slno.setText(String.valueOf(position + 1)+"."); //Setting sl no
holder._myCustomEditTextListener.updatePosition(position);
holder.noOfQst.setText(chapterList.get(position).getNoofQstns()); //Setting no of qstn
if (chapterList.get(position).isVisibled()) {
holder.noOfQst.setVisibility(View.VISIBLE);
} else {
holder.noOfQst.setVisibility(View.INVISIBLE);
}
//in some cases, it will prevent unwanted situations
holder.cbox.setOnCheckedChangeListener(null);
//if true, your checkbox will be selected, else unselected
holder.cbox.setChecked(chapterList.get(position).isSelected());
holder.cbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
//set your object's last status
chapterList.get(position).setSelected(isChecked);
chapterList.get(position).setVisibled(isChecked);
//if checkbox checked display EditText(No of qstns), else hide it.
if (holder.cbox.isChecked()) {
holder.noOfQst.setVisibility(View.VISIBLE);
holder.noOfQst.requestFocus();
holder.noOfQst.setText("10");
chapterList.get(position).setNoofQstns(holder.noOfQst.getText().toString());
/* txtQcount.setText("0");
if (txtQcount.getText().toString().equals("")) {
txtQcount.setText("0");
}
txtQcount.setText(Integer.valueOf(txtQcount.getText().toString())+Integer.parseInt(holder.noOfQst.getText().toString()));*/
}
else {
holder.noOfQst.setVisibility(View.INVISIBLE);
holder.noOfQst.setText(""); //remove entered value when uncheck
chapterList.get(position).setNoofQstns("");
}
}
});
}
// we make TextWatcher to be aware of the position it currently works with
// this way, once a new item is attached in onBindViewHolder, it will
// update current position MyCustomEditTextListener, reference to which is kept by ViewHolder
private class MyCustomEditTextListener implements TextWatcher
{
private int position;
private String oldval;
public void updatePosition(int position) {
this.position = position;
}
#Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
// no op
}
#Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
chapterList.get(position).setNoofQstns(charSequence.toString());
int j = i;
j = i2;
j = i3;
}
#Override
public void afterTextChanged(Editable editable) {
}
}
#Override
public int getItemCount() {
return chapterList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
TextView title;
CheckBox cbox;
TextView slno;
EditText noOfQst;
public MyCustomEditTextListener _myCustomEditTextListener;
public MyViewHolder(View itemView,MyCustomEditTextListener myCustomEditTextListener) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.txtTitle);
cbox = (CheckBox) itemView.findViewById(R.id.cboxChapter);
slno = (TextView) itemView.findViewById(R.id.txtRowSlno);
noOfQst = (EditText) itemView.findViewById(R.id.etNoOfQstns);
this._myCustomEditTextListener = myCustomEditTextListener;
try {
if (noOfQst.getVisibility() == View.VISIBLE) {
holder.noOfQst.setVisibility(View.INVISIBLE);
//adding textchange listener to no of qstn(EditText)
noOfQst.addTextChangedListener(myCustomEditTextListener);
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
You can register an AdapterDataObserver for the recycler view adapter.
For each item in the adapter when it's updated (user updates the EditText), the adapter can call notifyItemChanged(int position, Object payload). the observer will receive the payload in its onItemRangeChanged (int positionStart, int itemCount, Object payload) callback, you can pass whatever you want in the payload object so that you accumulate the values of all the EditTexts.
You can also unregister the observer in your Activity/Fragment onStop by calling unregisterAdapterDataObserver
I am using a cardview with recyclerview with hardcoded values such as string arrays. But now i want to add new cardview on each button click with user enter values and user select image and keep remain all cardviews on app exit.I mean to say that cardview should be added one by one only.Any solution plz guide me.
cardview Adapter class
public class CardViewDataAdapter extends RecyclerView.Adapter<CardViewDataAdapter.ViewHolder> {
private static ArrayList<FeddProperties> dataSet;
private static Context context;
public CardViewDataAdapter(Context context, ArrayList<FeddProperties> os_versions) {
this.context = context;
dataSet = os_versions;
}
#Override
public CardViewDataAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View itemLayoutView = LayoutInflater.from(viewGroup.getContext()).inflate(
R.layout.card_view, null);
// create ViewHolder
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
#Override
public void onBindViewHolder(CardViewDataAdapter.ViewHolder viewHolder, int i) {
FeddProperties fp = dataSet.get(i);
viewHolder.vehicleNumber.setText(fp.getTitle());
viewHolder.iconView.setImageResource(fp.getThumbnail());
viewHolder.feed = fp;
}
#Override
public int getItemCount() {
return dataSet.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
public TextView vehicleNumber;
public ImageView iconView;
public FeddProperties feed;
public ViewHolder(View itemLayoutView) {
super(itemLayoutView);
vehicleNumber = (TextView) itemLayoutView
.findViewById(R.id.vehiclenumber);
iconView = (ImageView) itemLayoutView
.findViewById(R.id.iconId);
itemLayoutView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), InformingUser.class);
v.getContext().startActivity(intent);
((MainActivity) context).getSupportFragmentManager().beginTransaction().replace
(R.id.containerView, new InformingUser()).commit();
//Toast.makeText(v.getContext(), "os version is: " + feed.getTitle(), Toast.LENGTH_SHORT).show();
}
});
}
}
Java file....
private void initContrls()
{
SharedPreferences prefs = context.getSharedPreferences(MY_PREFS_NAME, 0);
vehiclecatory = prefs.getString("vehicle_category", "");
vehicletype = prefs.getString("vehicle_type", "");
String versions = prefs.getString("city", "")+" "+prefs.getString("dis", "")+" "+prefs.getString("number", "");
String vehicleCompany = prefs.getString("company", "")+" "+prefs.getString("model", "");
if(vehiclecatory.equals("1"))
{
if (vehicletype.equals("1"))
{
icons = R.drawable.contwowheel;
}
else if (vehicletype.equals("2"))
{
icons = R.drawable.comfourwheel;
}
else if (vehicletype.equals("3"))
{
icons = R.drawable.comheavy;
}
}
else if (vehiclecatory.equals("2"))
{
if (vehicletype.equals("1"))
{
icons = R.drawable.nontwowheel;
}
else if (vehicletype.equals("2"))
{
icons = R.drawable.nonfourwheel;
}
else if (vehicletype.equals("3"))
{
icons = R.drawable.nonheavy;
}
}
os_versions = new ArrayList<FeddProperties>();
for (int i = 0; i < 2; i++) {
FeddProperties feed = new FeddProperties();
feed.setTitle(versions);
feed.setVehicleCompany(vehicleCompany);
feed.setThumbnail(icons);
os_versions.add(feed);
}
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new LinearLayoutManager(context));
mAdapter = new CardViewDataAdapter(context,os_versions);
recyclerView.setAdapter(mAdapter);
}
here there is an example to add cardview dinamically
In this example cardview are create with for:
for (int index = 0; index < 20; index++) {
DataObject obj = new DataObject("Some Primary Text " + index,
"Secondary " + index);
results.add(index, obj);
}
but you can inser into onClick action :)
I have a problem to updae my recycle when updating scroll up/down.
I have 3 (Custom ítems with respect views) but my onBindViewHolder only calls 2, when I try down list, my list not update correctly aparently It makes a cut (0.2 sec)
I don't know why not update correctly with 3 (ítems with 3 images)
My holder : (Why count 2?) but I when down, count 3 ...
public class CAPusheenAdapter_Fragment_0_7 extends RecyclerView.Adapter<CAPusheenAdapter_Fragment_0_7.ViewHolder> {
private ArrayList<CustomItem_0_ALL> pusheenArrayList;
private int itemLayout;
private Context context;
DBHelper db ;
RecyclerView recyclerView;
public CAPusheenAdapter_Fragment_0_7(ArrayList<CustomItem_0_ALL> data, int itemLayout, Context context, RecyclerView recyclerView){
setHasStableIds(true);
this. pusheenArrayList = data;
this. itemLayout = itemLayout;
this. context = context;
db = new DBHelper(context);
this. recyclerView = recyclerView;
}
public class ViewHolder extends RecyclerView.ViewHolder {
public ArrayList<TextView> allTextViews;
//public TextView text1,text2,text3,text4,text5,text6,text7;
public LinearLayout l1;
public ViewHolder(View itemView) {
super(itemView);
int numOfTextViews=6;
allTextViews = new ArrayList<TextView>(); allTextViews.add(0,null);
l1 = (LinearLayout)itemView.findViewById(R.id.l1);
for(int i=1;i<=numOfTextViews;i++){
allTextViews.add(i,Config.getViewsComplext(context,itemView, "text" + i));
}
itemView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//final int itemPosition = Fragment_0.recyclerView.getChildPosition(view); // todo SOO COOL LINE !
final int itemPosition = recyclerView.getChildPosition(view); // todo SOO COOL LINE !
//Toast.makeText(context, "No plantejada", Toast.LENGTH_SHORT).show();
//MainActivity.FragmentReutil2(new Class[]{Fragment_0_4_1.class}, 0, context);
}
});
}
}
#Override
public CAPusheenAdapter_Fragment_0_7.ViewHolder onCreateViewHolder(ViewGroup parent, int i) {
View itemLayoutView = LayoutInflater.from(parent.getContext()).inflate(itemLayout, parent, false);
Config.totalConfigFull2(context, itemLayoutView);
ViewHolder viewHolder = new ViewHolder(itemLayoutView);
return viewHolder;
}
#Override
public void onBindViewHolder(CAPusheenAdapter_Fragment_0_7.ViewHolder viewHolder, int position) {
CustomItem_0_ALL pusheen = pusheenArrayList.get(position);
ArrayList<String> texts = new ArrayList<>();
texts.add(0,null);
texts.add(1,pusheen.getText1());
texts.add(2,pusheen.getText2());
texts.add(3,pusheen.getText3());
texts.add(4,pusheen.getText4());
texts.add(5,pusheen.getText5());
texts.add(6,pusheen.getText6());
for ( int i = 1 ; i < viewHolder.allTextViews.size() ; i+=1 ){
if(texts.get(i).length()>0){
viewHolder.allTextViews.get(i).setText(texts.get(i));
viewHolder.allTextViews.get(i).setVisibility(View.VISIBLE);
}else{
viewHolder.allTextViews.get(i).setVisibility(View.GONE);
}
}
//viewHolder.l1.setBackgroundResource(pusheen.getImg());
int w =Config.getWigthHeightScreen(context)[0];
int h =Config.getWigthHeightScreen(context)[1];
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(w, (int) (h/2.5));
viewHolder.l1.setBackgroundResource(pusheen.getImg());
viewHolder.l1.setLayoutParams(lp);
}
#Override
public int getItemCount() {
return this.pusheenArrayList.size();
}
}
Note : only call/count elements from screen not call out elements, only call when you move list up/down
I found problem :
This is the problem : and solution
AsyncTask loading image RecyclerView