Android has the transcript mode to allow to automatically scroll a list view to the bottom when new data is added to the adapter.
Can this be somehow reversed so that new items are automatically added at the top of the list ("inverse transcript mode")
Method stackFromBottom seems about right, but does not do the auto-scrolling on input change.
Does anyone have some example code where a list is constantly adding stuff that gets always inserted at the top? Am I on the right track here?
Update
Thanks for the answers, that made me think more. Actually. I want to have new entries to appear at the top, but the screen still show the item the user is looking at. The user should actively scroll to the top to view the new items. So I guess that transcript mode is not what I want.
OnItemClickListener MshowforItem = new AdapterView. OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { ((TextView)view). setText("Hello"); } };
What is custom listview? Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
Android Custom ListView (Adding Images, sub-title)After creating simple ListView, android also provides facilities to customize our ListView. As the simple ListView, custom ListView also uses Adapter classes which added the content from data source (such as string array, array, database etc).
Hmm, well, if I was going to try this, I'd do something like the following:
List items = new ArrayList(); //some fictitious objectList where we're populating data for(Object obj : objectList) { items.add(0, obj); listAdapter.notifyDataSetChanged(); } listView.post(new Runnable() { @Override public void run() { listView.smoothScrollToPosition(0); } }
I don't know for certain that this will work, but it seems logical. Basically, just make sure to add the item at the beginning of the list (position 0), refresh the list adapter, and scroll to position (0, 0).
instead of this:
items.add(edittext.getText().toString()); adapter.notifyDataSetChanged();
you should try that (works for me):
listview.post(new Runnable() { @Override public void run() { items.add(0, edittext.getText().toString()); adapter.notifyDataSetChanged(); listview.smoothScrollToPosition(0); } });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With