In following project here is example
I'm using with .notifyDataSetChanged();
this method .post(new Runnable(){
to scroll down after adding new item
private void addItemsToList() {
int randomVal = MIN + (int) (Math.random() * ((MAX - MIN) + 1));
mItems.add(String.valueOf(randomVal));
mListAdapter.notifyDataSetChanged();
mCompleteListView.post(new Runnable(){
public void run() {
mCompleteListView.setSelection(mCompleteListView.getCount() - 1);
}});
}
public class ReceiverThread extends Thread {
String line;
String name;
ReceiverThread(String name, String line){
this.line=line;
this.name=name;
}
public void run() {
OpenStream.this.runOnUiThread(new Runnable() {
public void run() {
addItemsToList();}}}}
BUT when I want scroll up by using finger, new programmatically added item scrolls listview to down.
How I can set off .post(new Runnable()
when I touch the screen and using finger to scroll? or what can I do to don't let listview scroll down when I touch the screen?
I've added this code, and now when I touch listview there is no scrolling to down
mCompleteListView.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
flag = true;
Log.e(MainActivity.tag,"onTouch "+flag);
}else{
flag = false;
Log.e(MainActivity.tag,"onTouch "+flag);
}
return false;
}
});