Is there any way? two independent classes can communicate with single recyclerView...
what i mean actually i have one recyclerView and i have two objects, for instance: one class has "name" and other class has "qualification" something like that, and both classes extends from AppcompatActivity. I wanna show both these in that one particular recyclerView
The Case is:
I am using Room persistence lib. with MVVM i have one Entity class personal information and i am showing all those stuff in recyclerView and working fine. Now i have Button of objectives when i press it, it goes to different activity and have to enter some data and have to show in the same recyclerView and that objectives has its own Entity class which belongs to lets say objectivesActivity class..
in short we can say that, there are two Entity classes and two activity classes but one recyclerView which has to show both of their data..
i need more to know about your use case but my general solution is that you can create two adapter and when you want change RV you can just change your adapter.
Related
I am having a scenario in which I want to show two different items in one adapter.
Here is a scenario,
I have two lists on which I want to make a comparison, one list which is coming back end and one is coming from my local room database. Basically, I need to list the items coming from back-end, in these items which exist in my database will have different view in adapter and and if the item coming from backend does not exist in my database will have different views.
If I'll make comparison in adapter it will violate MVVM as I cannot write the business logic in the adapter.
Any suggestions with the best practice in my scenario please?
First I have build a simple android application which had only five optios to select. For this purpose I used five Buttons on main Activity. Now I have more than twenty buttons in a ScrollView to select. What is the best way to represent this kind of application (using buttons in a ScrollView? using TabHost? or with some other widget?)
The app look like this now:
Grid View or List View or Recycler View
the Adapter automatically will add buttons with the names you want, something that I did for my upcoming app.
I made a java class called data which has 'data` for my app.
it has an array of images for my GridView.
SO:
Make a class called data
Add a public final static String[] myArray array of your names, or data
Now, whenever you want to access them, use data.myArray
If you want to access one item ,use data.myArray[itemIndex]
Don't forget, indexes are zero based, not 1
Put your button inside a viewHolder class
find the id of the button in the getView if convertView is null & set the holder as a tag
NOTE : after finding the ID of the button, just leave it don't do anything or edit the text, continue reading please.
Use that array with your custom adapter
as
gridView.setAdapter(new myCustomAdapter(parameter1, parameter2,data.myArray);
use this , I just made it yesterday, added array of buttons feature now. You can just learn it or use it or commit changes.
NOTE :
You can make an array of listeners just like any primitive data type, View.OnClickListener[] and name it, initialize it.
Use grid view. it will be easy to show multiple buttons on screen using grid view.
i'm quite new to app developing and I am wondering about some good design patterns when it comes to adapters for ListViews.
I don't have any specific code (at least not simple and clear code) to accompany the question, but anyway, here is the situation.
I have an Activity in which I want to show any List of Books.
I made a CustomAdapter for this, based on layout called "row.xml." This xml includes a TextView and an ImageView.
I create my CustomAdapter in this Activity as follows:
customAdapter = new ListAdapterFullList(this, R.layout.row, bookList.getList());
Now i want to reuse this Activity to show a List of Books, but the layout needs to be different this time! It should be "row_alt.xml". Instead of a TextView and an ImageView, this list now needs to display a TextView and a RatingBar.
The problem that i am facing here is that obviously I want to reuse the Activity (since what i need to display is still a List of Books and all the other behaviour is the same), but I don't know how to handle the adapter. I can't just use this:
customAdapter = new ListAdapterFullList(this, R.layout.row_alt, bookList.getList());
because this ListAdapterFullList is not implemented to handle a RatingBar instead of an ImageView.
How can i bypass this problem? Do I need to create a different Adapter to show this layout? If so, then I will need to modify my existing Activity also, although I do not know how.
Btw, I read a lot about problems where different layouts need to be used for each row in a ListView, but this is not what I am struggling with. I want to reuse an adapter with a completely different layout for the Adapter. The rows themselves are always the same.
Thanks for the help, and apologies for the possible confusing question. You can always ask for more info!
If row.xml and row_alt.xml only have two different widget, I suggest that you create two different Adapter. If really there is a common behavior between this two Adapters, create a parent class that will implements the common behavior and make your two adapter extends this parent class. Then each Adapter implements its own [getView()](https://developer.android.com/reference/android/widget/Adapter.html#getView(int, android.view.View, android.view.ViewGroup)) method.
Then for further optimizations use the ViewHolder Pattern.
I also suggest that you take a look at RecyclerView which is the new version of ListView and don't need the ViewHolder Pattern
I have a recyclerview and I have at least 3 types of cards with different properties. Logic for switching cards layout is a non issue, but I am wondering what is the best way for me to grab the data.
I guess I can add different webservice data to a list or I can add them to an array where one column is key for type of ws.
I just need some pointers about how other people would do it. My recyclerview today has 3 cards layouts and the view resides inside a fragment. I do the WS calls in the main activity.
I at first wanted to use classes but some cards will use many properties and some few. Like a card for watch widget dosent need data. Current weather needs 3 properties and weather forecast maybe 15. I am thinking maybe I should pass an array that references type of card and then grab the data (as a key)? If I use classes I would have to make very generic names and not all cards would use all of them (not that this is hard to do, but Im thinking it looks silly).
In theory I guess looking at google now shows the different types of cards with different properties from different sources. How would you guys arrange the dataset for such usage?
Maybe you could use a parent class and extend from that the classes for every different type of card. Check the viewType in your ViewHolder and cast the item to the one that represents.
this might be a dummy question, but I am struggling trying to come up with a solution.
In my app I commonly use a ListView with a Header, and two TextViews for row. But right now for each ListView that shows different data I am creating a ListFragment. My idea is to keep only one class extending ListFragment and use that to show all ListViews in the app with the same structure (Header, and two TextView for row).
For example:
In this image I am using two separate Fragments. What Would be the best way to re-use the ListFragment