How can i update listview background dynamically - android

I have tried various methods but none of them is working, what i what is changing the background image of cell of listview for this i have different images for cell. The content remain same. This is what i have tried yet.
CountryList.post(new Runnable(){
public void run() {
CountryList.invalidateViews();
}
});
// and this one also.
runOnUiThread(new Runnable() {
public void run() {
CountryList.invalidateViews();
}
});
As i dont content to be reloaded.

For this you can iterate over child components of list-view and get background of each one of them and change their background, for example get child at and so on.

Related

Set a ListView scrolled to bottom at app start? (android)

I dont want to scroll it (becz i think it takes time and perfomance to scroll). I want to set it already scrolled to bottom at the start of the activity like whatsapp.
How could this be done?
If you want your ListView to be always scrolled at the bottom even on updating, you can add these attributes to the list:
android:stackFromBottom="true"
android:transcriptMode="alwaysScroll"
Otherwise use :
listView.setSelection(adapter.getCount() - 1);
listview.setSelection(LastItemIndexInListView);
LastItemIndexInListView : size of listview - 1.
listView.post(new Runnable() {
#Override
public void run() {
listView.scrollTo(0, listView.getBottom());
}
});
Give this a shot.
listView.post(new Runnable() {
#Override
public void run() {
listView.setSelection(listView.getCount() - 1);
}
});
This should work for you

Android runOnUiThread not updating UI elements

Hi I am developing android application in which I am using grid view. I want to updated grid item dynamically.My grid item contains one title text. I tried to do it like this but it is not working for me.
((Activity)context).runOnUiThread(new Runnable()
{
public void run()
{
Debug.print("this is update progress inside thread ...");
owner.setText("Uploading...");
invalidate();
requestLayout();
}
});
So in above code its printing debug statement. But not updating my owner text which is inside grid item.
I tried this also...
Handler handler = new Handler() {
#Override
public void handleMessage(Message msg) {
owner.setText("Uploading...");
}
};
handler.sendEmptyMessage(0);
Try to refresh your adapter which you used to load the grid item.
Either you could use invalidateViews() method or adapter.notifyDataSetChanged()
This will help you to resolve your issue.
Happy coding..
So in above code its printing debug statement. But not updating my
owner text which is inside grid item.
I think it's textview does not reference to your item in grid adapter. You can check it by set tag when init and getTag() inside runonUIThread method.
Let check this textview is local or global variable. If global, it's only reference to the last item - then check the last item change?
OK if it's not. Let post full ur code.
runOnUiThread(new Runnable() {
#Override
public void run() {
Debug.print("Updating UI ...");
owner.setText("Uploading ...");
invalidate();
requestLayout();
}
});
Check if you have any Thread.sleep() in your code that might be blocking the UI.

Android ListView setVisibility not working

I have a ListView in my RelativeLayout that is supposed to be hidden during a search is executed. Therefore I implemented the following code:
mProgressView.setVisibility(View.VISIBLE);
mSearchListView.setVisibility(View.INVISIBLE);
mSearchAdapter.search(query).onSuccess(new Continuation<Set<Integer>, Object>() {
#Override
public Object then(final Task<Set<Integer>> task) throws Exception {
runOnUiThread(new Runnable() {
#Override
public void run()
mSearchAdapter.notifyDataSetChanged();
mProgressView.setVisibility(View.INVISIBLE);
mSearchListView.setVisibility(View.VISIBLE);
}
});
return null;
}
});
Unfortunately, the ListView stays visible. The ProgressView start to spin successfully but the list view remains visible. Any hints on what to do?
When you say it stays 'visible' do you mean you see data in the listview or just that some space seems to be occupied by an invisible listview?
If the latter is the case then you should try making the listview GONE as -
mSearchListView.setVisibility(View.GONE);
instead of making it invisible

ListView doesn't scroll to end, when keyboard using

My ListView should automatically scroll to end, when new message received or sent.
But when I use Android keyboard to send message from EditText below ListView, ListView resized and new message, which I want to send, appears out of screen and I have to scroll down to see it, even if keyboard disappears and ListView resizes again.
To scroll ListView I use:
listView.postDelayed(new Runnable() {
#Override
public void run() {
listView.setSelection(listView.getCount());
}
}, 100);
but is not working correctly in my case.
Does anyone know why it may occur? Is there a way, which ALWAYS scroll ListView to end?
Thanks, your help is much appreciated!
Try this insead of your code:
listView.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL);
(or set it by XML layout).
You can try to add this line of code after you set selection to your list:
listView.smoothScrollToPosition(listView.getCount());
Resulting code should look like this:
listView.postDelayed(new Runnable() {
#Override
public void run() {
listView.setSelection(listView.getCount());
listView.smoothScrollToPosition(listView.getCount());
}
}, 100);
Set android:windowSoftInputMode in manifest for the activity to adjustPan|adjustResize.

Continuously Auto-Scrolling ListView

I have a Listview in Android. I want that the Listview continuously scrolls from top to bottom by itself. It should happen infinitely
And obviously I want to capture the click on any of the items of the Listview, post that the scroll will continue
Anybody having experience with such an implementation. Please help !!
http://groups.google.com/group/android-developers/msg/753a317a8a0adf03
To scroll automatically, you can use this: listView.smoothScrollToPosition(position);
private void scrollMyListViewToBottom() {
myListView.post(new Runnable() {
#Override
public void run() {
// Select the last row so it will scroll into view...
listView.smoothScrollToPosition(myListAdapter.getCount() - 1);
// Just add something to scroll to the top ;-)
}
});
}

Categories

Resources