android ListView ,setSelection() has no effect after setFlags(...FULLSCREEN) - android

Now I have this problem when:
In my Asynctask, I have a ProgressDialog over this Listview that is constantly updated and scrolling automatically (I use something like mListview.setSelection(mData.size()-1); to scroll it )
I want it to be fullscreen when it's not finished or canceled, which I think is pretty easy by Window dialogWindow = mProgressDialog.getWindow();
dialogWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
I also want it to stop being fullscreen( i.e. I want the status bar shown) when it's finished. And I want the first item in the Listview shown as well.
-------------------- This 's when the problem occurrs.--------------------
I use like
dialogWindow.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
and it's working well. The status bar appears.
then I use mListview.setSelection(0), which I suppose can bring the me first item.
HOWEVER, it has no effect at all. Any idea how this happens or how to solve it? Any help would be greatly appreciated. Thank you!

you can try this method, it maybe helpful to you..
http://developer.android.com/reference/android/widget/ListView.html#smoothScrollToPosition(int)
public void smoothScrollToPosition (int position)
Since: API Level 8
Smoothly scroll to the specified adapter position. The view will scroll such that the indicated position is displayed.
Parameters
position Scroll to this adapter position.

You have to use
mListview.clearFocus();
before calling
mListview.requestFocusFromTouch();
mListview.setSelection(0);
in a post method of mListView.

Related

How to prevent blinking if any of the item is changed in recyclerview

I am working on an android application in which I am showing some data using recyclerview. First time the data is getting shown perfectly. Now the changes should be reflect in list as any value of the item view get changed. I have used notifyDataSetChanged() to notify adapter about changes. The items view are blinking when they get changed, so user get to know about this effect, how to remove this blinking effect. I've tried using notifyItemRangeChanged() but getting the same blinking effect with this one as well. Please let me know if anyone know about this issue.
Thanks a lot in advanced.
Use the below code, this will disable the animation effect, hope this helps
ItemAnimator animator = recyclerView.getItemAnimator();
if (animator instanceof SimpleItemAnimator) {
((SimpleItemAnimator) animator).setSupportsChangeAnimations(false);
}

EditText suggestion bar flickers when focus go to listview and back to edit text

I have chat list view and send message edit text below it. When message got sent, i add it to listView and then refresh the adapter. Unfortunately whenI did that, the list does not scroll up even after I set listView.setSelected(adapter.getcount()). After investigating this I found that listview does not get focus. so I set the focus first by lstMessages.requestFocus(); then lstMessages.setSelection(adapter.getCount());, then get the focus back to the edittext. the problem now is that the suggestion bar above the edittext disappears when focus lost and appear when focus gets back causing flickering and very bad ux. Any solution or suggestion for the full issue ?
Please don't tell me to hide the suggestion bar, I don't want to disable this feature for users plus it does not work in all devices.
Thanks in advance.
I guess you should try to post to the ListView like this. Try to call smoothScrollToPosition. If that does not works, try setSelection
lstMessages.post( new Runnable() {
#Override
public void run() {
lstMessages.smoothScrollToPosition(position) ;
}
});

Android - dynamically update GridView views

I've got a GridView with a custom Adapter, displaying thumbnails of pictures to the user. I can select and deselect pictures (I use setAlpha(0.25) on the views to notify the user of the change), and that's all well and fine.
Now what I want to do next, is have a button on top of the gridview that clears the whole selection, i.e. call setAlpha(1.0) on all views that were changed. So far I can reset my elements in the adapter, and I can setAlpha to 1, but the view doesn't update unless I scroll it out of the display, and then get back to it, or notify the adapter of changes, which redraws all my views, which does not look too pretty if only one element was selected.
I already dynamically set and reset individual elements through the GridView's onClickListener, but can't do this for more. I even tried calling performClick on all selected items through my button, but again it only displays the changes after the views have been out of the screen and are shown again.
Here's how I simulate the clicks:
for (int i = 0; i < mAdapter.getCount(); i++) {
PictureForSelection tempPic = (PictureForSelection) mAdapter.getItem(i);
if (tempPic.isPicSelected()) {
//tempPic.setIfSelected(false);
gridview.performItemClick(mAdapter.getView(i, null, null), i, i);
}
}
EDIT:
Conclusion - don't simulate clicks like this :)
So now I skip click simulation and use this:
gridview.getChildAt(i).setAlpha((float) 1.0);
In general it does exactly what I wanted it to do, except for one case:
If I have for example 3 pictures selected, one is off screen, one is partly shown, and one is fully shown, the ones shown (even partially) don't update their views.
If all the selected pictures are displayed it works flawlessly, but if some are out of the display, the rest do not update until the adapter's getView() gets called by Android. Still, thanks #mmlooloo for getting me so far.
If anyone knows a way around this, please do share :)
After setting your alpha you can call imageview.invalidate(); this causes your imageview to redraw itself.
if notifyDataSetChanged() is not working you can try like this.
i'm not sure whether this works,
1.onclick of the button you set the gridView.setAdapter(null);
2. Then set a new CustomAdapter object to gridview with default values.

How to disable dropdown list auto-opening in AutoCompleteTextView when notifyDataSetChanged() called?

Here's my problem:
In my android app I use AutoCompleteTextView and refresh items list for each 5 seconds. Refreshing is working, when I call notifyDataSetChanged(). But when I type here something and it'll give me the list of matching items and then I close it manually, when another thread is refreshing the list and calling notifyDataSetChanged() dropdown list is showing automatically (even if I closed it before). And it's really annoying, because if list is long it takes whole screen and after closing it'll appear in another 5 secounds.
I tried dismissDropDown() just after calling notifyDataSetChanged(), but it doesn't have any effect. It looks like dropdown is showing with a little delay. It's also not good way to fix it, because if user hasn't closed the list it'll close after a refresh. Also tried to take focus away - still no effect.
So I need a method to:
update my items list (via notifyDataSetChanged()) without automatically showing dropdown list, but if dropdown was already showed don't close it.
Hope you can help,
cheers
I did it, finally. I post here a solution, maybe someone will use this.
To check if dropdown is visible:
final boolean isVisible = autocomplete.isPopupShowing();
Next, call notifyDataSetChanged(),
Finally:
new Handler().post(new Runnable(){
#Override
public void run() {
if(!isVisible){
autocomplete.dismissDropDown();
}
}
});
This works perfectly.
I have also this problem, I think it seems to be a bug, i solved this by the following way
First of all set your AutoCompleteTextView focusable property to false.
Second change your AutoCompleteTextView focusable property to true in onTouch event of that view.For that you have to implement onTouchListener to the AutoCompleteTextview.
Whenever you touching on that AutoCompleteTextView, you should change focusable property to true otherwise keep it focusable to false. So that the dropdown list is never appear when the view is in unfocusable state.
It shows dropdown list automatically, only when the view is in focusable state which is annoying to user, otherwise it works good.

get a small list when clicked on a button

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.

Categories

Resources