I am using customadapter to set data for list which contains a text view, imageview and a layout with some buttons. the buttons layout will be invisible initially. When we click on list item the layout has to appear with user able to click a button. This work fine as long as ImageView is static.
But our build will fetch image from url and set it to view. Here the refresh issue arises. The Layout is unable to be view.
List refreshes when re apply any external even such as Track ball or scroll.
Please help me regarding this.....
Without actual code, it's hard to tell what the problem is, but have you tried calling invalidate() (inside UI thread) or postInvalidate() (outside UI thread) on the layout or any view you need to redraw? This forces the view to call onDraw() again.
Related
I have a situation involving animation of listview's item appearances.
I have a few views in a ScollView , the last of which is the listview. I have attached an appearence animation of the row (a fade in animation).
The problem I have is that when the screen is loaded , the getView() of listview already executes for the initial items , even though the listview is not currently in view.
Hence when a user scroll downs , he sees the list plainly.
I am unsure how to go about this situation . Is there any callback that can be invoked when a row from a listview becomes visible on screen ? .
Yes there is a callback (OnScrollChangeListener), first visible index and last visible index etc. You can achieve what you are trying to using combination of these.
But you need to try that yourself first. No one can simply write a code for you.
You can learn about listview here
What I am trying to do is populate a listView with views/elements that could be a textview/imageview. Potentially, these textviews are expandable. I want the listview to resize and wrap the content if the textview is expanded.
There are several solutions out there already:
1. Make the elements of the ListView element invisible so that the view in ListView is already the size you want. In this case, create the text view with the original long string and then collapse it.
2. Resize the element in the adapter then call notifyDataSetChanged();
However I'm looking for a solution where the view in ListView automatically resizes, even when its visible. I have tried using Solution #2 and while it works for changing values inside the view such as a string, it doesn't resize the view altogether unless the view is scrolled off screen then comes back into view.
The relevant part of my code is as follows:
holder.text.setTrim(!holder.text.getTrim());
holder.text.setText();
holder.text.requestFocusFromTouch();
notifyDataSetChanged();
holder.text.invalidate();
vi.invalidate();
vi.requestLayout();
I put this inside an OnClickListener inside an adapter's getView function.
Anyone have any solutions?
PS. Has anyone tried doing a method with multiple adapters? This one doesnt seem to work too well for me because I have potentially hundreds of elements.
Edit:
So I've come up with part of a stupid solution that is absolutely ridiculous. The behavior makes no sense. Below (primaryTextView is the same text as above eg. holder.primaryTextView == holder.text)
holder.primaryTextView.setTrim(!holder.primaryTextView.getTrim());
if(!holder.primaryTextView.getTrim()){
holder.primaryTextView.setVisibility(View.GONE);
}
else{
holder.primaryTextView.setVisibility(View.VISIBLE);
}
notifyDataSetChanged();
vi.invalidate();
This allows you to expand the view while viewing it but does not allow you to shrink the view once the text is collapsed. Furthermore, View.GONE and View.VISIBLE are NOT interchangable. Finally, the textView does not even dissapear in the event that View.GONE is triggered. Perhaps this might be a clue?
it doesn't resize the view altogether unless the view is scrolled off screen then comes back into view.
It is working, but you are not refreshing the listview, when you scroll off & return, listview recreates the updated view.
You should notifyDataSetChanged(); adapter.notifyDataSetChanged();
Nevermind found the problem:
In my layout, I was using height="0dp" instead of "wrap_content"
I have a ListView declared inside a layout. When I addFooterView(v) it does NOT display. What are the possible reasons for this? Is there some setting in ListView or my Adapter to make this display immediately? It does eventually display but only after reinitializing the view, adapter and all.
Update: It seems that resetting the adapter finally makes it appear .... Obviously not something that I should have to do everytime I call addFooterView(v).
The view containing the ListView is inside a View maintained by PageViewer so not sure if that effects this or not.
Add the footer view before you set the adapter is the only thing we can replicate with when we are not able to see your code.
I know Android execute 2 times (or sometimes even more) the getView() method of the adapter in order to draw the ListView correctly. I would like to know (or get notified) when it stops execute that method.
Why? The rows of my list are animated when user swipes on one of them. If the user swipes before Android has finished execute getView(), the animation is executed on the first row instead of the row touched by the user.
You can load ListView in background AsyncTask. And during that time you can show progress dialog on the screen so user is not able to do any action on your screen.
Check this Reference :
Load ListView in background AsyncTask
Hope this helps you.
Thanks.
There is no last getView()
When you are scrolling in a list, for each item that will become visible a getView() will be called. EVEN when it has already been on screen. I believe you are not detecting the list view item click properly.
i have a image view and on top of it i have a button. now what i want is when i click on the button i should get a list of images on same Activity.actually i am trying to make a list in button,s onClick event. event gets fired but it does not show the list. anybody can have any idea how shall i achieve this i am also making my layout programmatically.
thanks alot
Without seeing some code it's hard to give a definite answer, but these are a few possibilities.
Create the listview together with the button, but set it's visibility to View.GONE or View.INVISIBLE. In the button's onClick method, set it to View.VISIBLE.
Alternatively, do the listview creation in the button's onClick (which I gather is what you're doing?), making sure you don't forget to add it to your layout. I have no idea why this does not work for you. Show some code or use the debugger to step through it and find out where it goes wrong.