How to handle dynamic view created in Recycler View - android

Actually, I am working on RecyclerView that shows some details along with images and all data comes from a database.
In my RecyclerView, I have used three diffs layout and each layout is used according to data coming from the database that means if only one image comes from database then one_image.xml layout comes to play, if two then two_imag.xml layout comes to play and if more than three then the third layout I am using.
My apps working fine for some extents but when i am trying to scroll down further, it get crashed. I come to know that the problem is on OnCreateViewHolder, meaning it doesn't get called when I go down further in Recycler View.
I searched alots on google but nothing work for me. Is it possible to call OnCreateViewHolder every time or some other way to solve this problem?
Thanks in advance

Sounds like the best option would be to use one layout file that has all three image views but just default them to visibility "gone" so they dont take up space. Then when you need to use them, set them to visibility "visible" when you are creating your viewholder.
Without seeing any actual code it hard to be more specific.

Related

best method to frequently change view inside layout

I want to add and remove some views frequently like
Recycler view,textview,seekbar,customview,imagebutton etc.!!!!
I know following methode to perform it
Add all view to layout and just play with Visibility.GONE, Visible and other..
using layout params add and remove view...
Use View.inflater to add and remove predefined XML views(I'm using)
So question is
1.Is there any other method to do it?
2. Which one you prefer and why?
When you make Visibility.GONE all the views and associated resources such as image, sound files will be kept in the memory and if you have a lot if resources that may slow down your application. I think better way would be to use Fragments.
Check out this link. Hope this helped

Create a ListView like view in a ScrollView Android

So I did some research and testing of using a listview in a scrollview, and as a lot of people may know this is supposedly bad to do, since they both scroll. It also means I can't show the complete listview as it will wrap to be smaller.
I have seen places which re change the height of the listview to fix this problem but again most people say that it isn't preferred.
What I would like to know though is what is the preferred way of making a nonscrollable listview like view? Basically I want the exact same as the listview but obviously non scrolled and the height based on its contents. I would prefer to work with the layout in as much XML as possible, and I would like to be able to send my array list to it to view on screen. Unfortunately either my search skills are quite dull, as I haven't been able to find anywhere that really explains the preferred method so I thought I would ask here.
Thanks for your help.
<>Clarification Information
I thought I would put this here in case it will help, first off I basically want to show an image, with a list of comments (each one has an author and a text) below it, the comments themselves are obtained from an array and can change. I want the whole page to be scrollable though so I can either view more comments or go back up to the image.
Using a RecyclerView and an adapter supporting multiple item types you could make a list which shows an image on top and several comments below it. Generally you'd have to check what item corresponds to each position - in your case on position 0 you have an image and in every other position you'd have a comment. Then in your adapter's onCreateViewHolder and onBindViewHolder you would check the item type and handle them differently.
You could take a look at this answer for a short example.
Let me know if you'd need any other details and/ or sample codes to get the idea. :)

Android ListView custom row overlay

I am developing an activity with a ListView in which I need to change the current row by another layout by clicking on the row, and I'm not finding any way to do as much as I look (I take hours searching for possible solutions and I have not seen any reference to this problem). I do not know if this can be done in Android, but if anyone has an idea of ​​how to do this would be appreciated.
Thanks in advance.
PS: The ListView control is normal and just want to replace a layout with a different layout. I'm using the API 15.
Use a ViewSwitcher
http://developer.android.com/reference/android/widget/ViewSwitcher.html
A ViewSwitcher is -
ViewAnimator that switches between two views, and has a factory from
which these views are created. You can either use the factory to
create the views, or add them yourself. A ViewSwitcher can only have
two child views, of which only one is shown at a time.
I suggest merging the two layouts in a single one and hide the second one. In your adapter data you should have a flag or something to indicate which layout to display. When you click a row, toggle that flag for the selected item and notifyDataSetChanged() on the adapter. This will make sure the changed layout remains even if you scroll up and down and the row goes off screen.
A more optimized solution is to have different item types in the adapter.

TextView is not Clickable on OpenGl Curl View Effect

In my application I have requirement like this.I have number of data and I need to show that data on ListView kind of layout,now I have suppose total 6pages on each pages I want to show such data.I have listed number of textview on each page.Suppose i have 7pages so i need to make book kind of layout for that i am using this Code.https://github.com/harism/android_page_curl.
with this i am able to get such effect.As mentioned in below image.
Now my issue is,As OpenGl is converting entire layout to bitmap,i am not able to handle click event of textview.Whenever i click on textview on that time ACTION_DOWN method is called.and offcourse it should be called as entire layout is converting to bitmap thus we can't handle textview click event.
for making solution of this have googled and found some trick from This issue.Here mentioned to make seperate layout for handeling click listener,but not getting what exactly i have to do,as i don't have any experience in OpenGl,so if any one have idea about this issue,any one who can guide me handle click event.
The above solutions depends on your views pages. It may not work if you use ListViews on your pages or any ScrollView, you have to retest your application performance...
What i have done to get it working, is to create an extra root parent with,FrameLayout, place on top the widget, fi.harism.curl.CurlView and add PageContainer(RelativeLayout on may app).
At run time, get the drawable of your view page (View.getDrawingCache()) , and add The real PageView(witch contains click listener) to the PageContainer. Make the PageContainer alpha to 0. You have a duplicate page (transclude) to receive the page clic, the CurlView will still handle touch events for curl.

Android List problem

I've create an application using JSON. It shows the list of some items from one link whatever i used in Codes. In my application i've using 2 layouts for display the items. First layout doesn't have any problem. But, when i go to next layout the result of first layout also show here and overrides the second layout's contents. I'm using android:list for list that. Can anyone clarify this doubt? Thanks in Advance.
Make sure your ID on your Lists are different. This could cause the problem.

Categories

Resources