rohitsurwase / androiddesignpatterns Goto Github PK
View Code? Open in Web Editor NEWCollection of best code snippets to help everyone to simplify android app development.
License: Apache License 2.0
Collection of best code snippets to help everyone to simplify android app development.
License: Apache License 2.0
Each row have about 5-10 dynamically created textviews child. During scroll up and down, few of the created textviews disappears.
I'm following exact code with dynamic data. Here is the video link about the issue
https://screencast.com/t/lnJZIiVr79
@Override
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ReportViewHolder) {
ViewCallCardModel callCardModel = callCardReportList.get(holder.getAdapterPosition() - 1);
ReportViewHolder reportViewHolder = (ReportViewHolder) holder;
reportViewHolder.tvItemTitle.setText(callCardModel.getItemTitle());
int noOfChildTextViews = ((ReportViewHolder) holder).llItemChoice.getChildCount();
int noOfChild = callCardModel.getItemChoiceList().size();
if (noOfChild < noOfChildTextViews) {
for (int index = noOfChild; index < noOfChildTextViews; index++) {
TextView currentTextView = (TextView) ((ReportViewHolder) holder).llItemChoice.getChildAt(index);
currentTextView.setVisibility(View.GONE);
}
}
for (int textViewIndex = 0; textViewIndex < noOfChild; textViewIndex++) {
ChoiceModel choiceModel = callCardModel.getItemChoiceList().get(textViewIndex);
TextView currentTextView = (TextView) ((ReportViewHolder) holder).llItemChoice.getChildAt(textViewIndex);
currentTextView.setText(Html.fromHtml(homeActivity.getString(R.string.ItemChoiceCounter, choiceModel.getChoiceTitle(), choiceModel.getChoiceCounter())));
currentTextView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(homeActivity, ((TextView) view).getText().toString(), Toast.LENGTH_SHORT).show();
}
});
}
}
}
class ReportViewHolder extends RecyclerView.ViewHolder {
private TextView tvItemTitle, tvSubItemTitle, tvYes, tvNo;
private LinearLayout llBooleanChoice, llItemChoice, llSubItemChoice, llSubItems;
ReportViewHolder(View itemView) {
super(itemView);
tvItemTitle = itemView.findViewById(R.id.tvItemTitle);
tvSubItemTitle = itemView.findViewById(R.id.tvSubItemTitle);
tvYes = itemView.findViewById(R.id.tvYes);
tvNo = itemView.findViewById(R.id.tvNo);
llBooleanChoice = itemView.findViewById(R.id.llBooleanChoices);
llItemChoice = itemView.findViewById(R.id.llItemChoices);
llSubItemChoice = itemView.findViewById(R.id.llSubItemChoices);
llSubItems = itemView.findViewById(R.id.llSubItems);
//llBooleanChoice.setVisibility(View.GONE);
llSubItems.setVisibility(View.GONE);
int maxNoOfChild = 0;
int maxNoOfSubChild = 0;
for (int index = 0; index < callCardReportList.size(); index++) {
int maxSizeTemp = callCardReportList.get(index).getItemChoiceList().size();
if (maxSizeTemp > maxNoOfChild)
maxNoOfChild = maxSizeTemp;
}
for (int index = 0; index < maxNoOfChild; index++) {
TextView textView = new TextView(itemView.getContext());
textView.setId(index);
textView.setTextSize(14.0f);
textView.setTextColor(Color.BLACK);
textView.setPadding(10, 20, 10, 20);
textView.setGravity(Gravity.END);
textView.setClickable(true);
textView.setFocusable(true);
TypedValue typedValue = new TypedValue();
itemView.getContext().getTheme().resolveAttribute(R.attr.selectableItemBackground, typedValue, true);
textView.setBackgroundResource(typedValue.resourceId);
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llItemChoice.addView(textView, layoutParams);
}
}
}
And also when i have large number of views when i click first view the other view may be 12th or 13th also get expanded. How can i solve this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.