I have an arraylist containing 100 words. I want to assign each word to an individual textview of RecyclerView, but all the textviews of my Recyclerview show the same data, i.e the last word.
for(String s:arraylist){
viewholder.textview.setText(s);
}
Above is my Adapter Code for RecyclerView. How should I resolve this?
Try this:
viewholder.textview.setText(arraylist.get(position));
Instead of
for(String s:arraylist){
viewholder.textview.setText(s);
}
Use following below code for Set the values in textview from the ArrayList in `RecyclerView.
viewholder.textview.setText(arrayList.get(position));
I hope this may help you,
Related
I am getting list of data from server and setting in spinner through setAdapter, but what data is coming on 3rd position I want to set that as default(0th position). Ex. {Mango, Banana, apple} ; in spinner apple should be default instead of Mango
else if
(mListener.getSelection().get(0).
getGenLovs().get(i).getLovId().
equalsIgnoreCase(File_Key.AB_CUST_TITLE))
{
binding.spinTitle.setAdapter(new
GenLovsSpinner(getContext(),
mListener.getSelection().get(0).
getGenLovs().get(i).getValDes()));
}
I have tried this
String cls=
String.valueOf(mListener.getSelection().
get(0).getGenLovs().get(i).getValDes().get(3));
binding.spinTitle.setSelection(Integer.parseInt(cls),true);
Here when I am using above code I am getting NumberFormatException
binding.spinTitle.setSelection(Integer.parseInt(cls),true);
use this insted of above line
binding.spinTitle.setSelection(Integer.valueOf(cls));
See you are setting up any list or array to spinner adapter.
If you want to set particular as default then try this for example :-
Let you are setting dataList to spinner adapter
after setAdapter() for selection
either spinner.setSelection(dataList.indexOf("apple"),true) or
spinner.setSelection(2,true) as your third data has index 2
Just give binding.spinTitle.setSelection(2);
try this
Use the following: spinnerObject.setSelection(position).
I do not know the number. of textview which should be created at runtime. List of Textviews are getting from server. I am creating textviews using below function. Since i am new to android i unable to get text from all textviews. Please suggest me the solution
private void textview(String text)
{
TextView txt_view= new TextView(this);
txt_view.setText(text);
linearLayout.addView(txt_view);
}
Please suggest me the solution i m stuck in getting the text from many textview
Above image is my form, what i want to get text from all views which are created dynamically and store to firebase
add your TextView to HashMap with a unique key
and match your key and get value from map, it will surely help you. after that at time of fetching data use for loop and get data using that unique key
Just get it from your TextView object, like this:
txt_view.getText().toString();
Use same object of TextView to gt text of it. txt_view.getText().toString();
You can get same TextView object by finding childs of LinearLayout.
How about to store them in an ArrayList and iterate over it to get all and maniupulate them afterwards.
ArrayList<TextView> alTextViews = new ArrayList<>();
private void textview(String text) {
TextView txt_view= new TextView(this);
alTextView.add(txt_view);
txt_view.setText(text);
linearLayout.addView(txt_view);
}
with
alTextView.get(0).getText().toString();
you'll get the text
I have a recyclerView in my app. I have 2 fields in it(image_view, price_text_view). The value of price_textview looks like Rs.8000. Now I wanted to keep scrolling until I find an item on the recyclerview whose price is more that Rs.4000(>4000). Can someone please help me with the matcher etc.?
I can't give you whole code here but can give you some logic for implementing this.
this can be done by For loop. And using ArrayList or Array you are passing in your Adapter.
Now lets assume you are passing Arralist to your Adapter say "arrayLst". and from your qustion I assume you are using ArrayList with HashMap.
so your ArraList would be like.
ArrayList<HashMap<String,String>> arrayList = new ArrayList<HashMap<String,String>>();
now do something like this.
for(int i = 0; i<arrayList.size; i++){
if(Integer.valueOf(arraylist.get(i).get("prise_tag")) > 4000){
yourlayoutManager.smoothScrollTo(i);
break;
}
}
I hope this will help you somehow.
I am new in android programming.
I am creating a app where I supposed to use multiple textviews. Number of TextViews go on changing according to number of records fetched from database.
Here, i was trying to number textviews as textView1, textView2, textView3,...
but as i am unaware about the number of records, i can not define them statically
is there any way to do so dynamically
like we do in PHP
e.g
$count = 1;
if(condition)
{
textView.$count;
$count++;
}
Thanx in advance.
You should create a List of TextViews and populate it dynamically
List<TextView> list = new LinkedList<TextView>();
Find the total number of record at runtime and create the TextView in a loop for each textView and finally ad it to the current layout.
For example:
for(int i=0;i<data.size;i++){
TextView tv=new TextView(this);
tv.setText(data.get(i));
currentLayput.addView(tv);
}
where data is some vector or Arraylist in which you can store the data from database.
Hey. I have the following code:
final String text = (String) lt.getItemAtPosition(position);
db.removeCategory(text);
What I want to do is to remove a item from a ListView. The problem I have is that I only can remove the item that is in the first position of the list.
Is like the getItemAtPosition(0);
Why's that? Can somebody help?
Thanks
Bind your array to ArrayAdapter and use its remove method to remove particular object. Refer this link to get some understanding of how it works.
Remove ListView items in Android
Why don't you add items into a collection or data datable and then bind it to ListView.
In ste removal phase you delete the item from the collection/data table instead direct one from the ListView.