Add recycleview inside selected row of parent recycleview - android

Hi I have this particular use case where in I need to populate the recycle view on selected rows or specified row, on the image below If I need to increase the number of coffee so the button will increase, also only coffee has array list the rest like Sprit and L&P does not have list. Now when I populate the button with the list of coffee, what really happen was Sprite and L&P also got added Customized Coffee Button.

Related

Android- ListView items with dynamic content

I am having one problem with ListView.
I am generating a list view with dynamic TextViews(white boxes in image) in each item.
The ListView is populated using ArrayAdapter of 'Model' class. Some items can have 2 white boxes, some can have more which depends upon the data/count from 'Model'. Also, I am using ViewHolder pattern and can maintain other states of the list item. But these boxes are added dynamically in getView() method.
So my question is, how to maintain state of these dynamically added TextViews using ViewHolder or any other method when ListView is scrolled.
I guess the no.of boxes changes on scroll, but you need the dynamic no.of boxes to be alloted in a list items?
Solution:
Set the size (i.e) no.of boxes in a list item to an integer array. (like: size[position] = 5).
The size should be set, before the list adapter or base adapter loads the list items.
Now at the end of getView() of base adapter, right the code given below
for(int i = 0; i< size[position]; i++){
//generate textview i.e white boxes here
}
I had the same problem in dynamic list, this solved the issue.
If still you have problem kindly post your the code here.
You need to have a list or some data structure in which to store the content of the data you put in from the ui, for instance a SparseArray<ModelUI>. Your ModelUI class should have some string properties to store the text from your dynamic textboxes.
Also, you need to take into account that you're handling two indexes here: one index/key in the SparseArray which is the real index in your list of Model objects and an index of the items visible in your Listview.
Let's say you have a list of 100 items, in your listview you'll always display 10; you'll always have to refer to the firstVisibleIndex from your listView.
If I understand correctly, you'd like to edit a textbox, scroll 50 items, scroll back to the edited item and see the correct text in the textbox, right?

Items in multiple columns - spinner

I'm creating an Android app and I want to put a lot of short items to Spinner. Basically, it works:
But it doesn't work as I want. As you can see, there is a lot of items which have a very short text. It means that user may be forced to scroll a lot to find an item (s)he want. What I want to do is to put items in multiple columns, but I don't know how to do it. I searched in the internet for a while and the only solutions I've found were "how to put multiple columns in 1 item" - what I want is "how to put items in multiple columns".
Thanks.
First you should create your custom spinner adapter. Then, you can put 3 textviews in a row in your list.
On the getView function of your adapter:
1)Instantiate your custom layout (which has 3 textviews)
2)Give each textview a tag like this:
String mTag1=String.valueOf((position*3)-2);
String mTag2=String.valueOf((position*3)-1);
String mTag3=String.valueOf((position*3));
yourtextview1.setTag(mTag1);
...
// in position 1 you'll get 1-2-3, for position 2 it is 4-5-6 etc.
Thus you can assign the same onClickListener to them. (You should do this in getView function too)
Finally, on the onClick listener, get the clicked item's tag, convert it to integer (which is your items position on the list), get the item on the list with this position, and set your spinner's text with it.

get text from specific position in listview android

I have a ListView with custom_row , every row has a textView1 and a textView2 , the list has now 2 records , and i have a button that is not on the list.
When i click the button i want to get the text from textView2 of the 2 records.
Is it possible?
I would take a shortcut, you ListView is being populated by an Adapter that uses a dataset. This dataset can be almost any datastructure such as Array, ArrayList, etc.
The layout you define, such as custom_row in you case only defines the structure of your view i.e. "where" items will show within on item on the list.
On the other hand, it is still your responsibility to tell the ListView "what" to show within the textView1 and textView2. You do this using the Adapter which connects the ListView to the dataset. More often than not, the ListView is a one-to-one mapping of the dataset i.e. the first item on the list is the first item in you dataset (I don't know what you are using for only two items, might be an array).
The ListView calls getCount() on the Adapter to find out how many total views there will be. It then call getView() for each view to be shown on the screen. It is in this method that you define what will actually show in a single view on the list (your custom_row).
Now you would know which entry of the dataset is supposed to populate which view in the ListView so you can just read it off there. For example, if your getView() does:
textView2.setText(getItem(position).getSomeTextField());
And the original dataset is an ArrayList named listDataSet
You could just do listDataSet.get(2).getSomeTextField()
NOTE: You will have to manage the scope of the dataset so that it's visible from wherever you are calling.
Get back your ListView (maybe already stored in an object thanks to findViewById, or by calling getListView() on your ListActivity).
Then call getItemAtPosition() on your list view, with the position you want.

How do i get text value from listview when it is clicked?

I binded one image and 3 textviews in listview. When i secelt the particular row i got image and dispaly it in a separate list but i want to get the remaining 3 textviews text of that selected row and display in another list
Are you saying you have an image with three options each represented by textViews and when the image is selected you want those options to be entered in a new list? Why not save the textViews in the OnItemSelected() method? Once the image is picked it can create 3 new textViews linked to the text from those 3 textViews and then you can add those to a list in the same way you did your original list.

Android CustomHow to get Child Views from Custom ListView enclosed within linearlayout without clicking listview

I have a custom listview with two buttons and two textViews enclosed within linearlayout. I want to iterate through the listView without clicking the listView rows. When i do
listView.getChildAt(position);
position can be any integer from 0 onwards it gives null output, what is the other way to get views from listView. Please help.
There isn't really an interface exposed for getting the view objects from a ListView. These are constantly being switched out and stored for recycling as rows scroll in and out of the visible area.
However, you can do:
listView.getItemAtPosition(position);
to get the model (item) at a given position in the list. If you need to operate on information that the user changes in your list, then you would want to first save that information back to the underlying model individually when each component changes and then later aggregate over your underlying data objects to do your calculation.

Categories

Resources