Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

ListView is reusing views and I lose information after scrolling

In your getView method you have to check whether the row was already clicked, so your code should be something like this:

public View getView(int position, View
convertView, ViewGroup parent) {
try {
    Station item = getItem(position);
    View v = null;
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater)
        v = inflater.inflate(layoutResourceId,
    } else {
        v = convertView;

    TextView stationName = (TextView)

    if (head == position) { //first click
    } else if (terminal == position){  //second
        terminal = position;
    } else {

    ImageView line_image = (ImageView)


   return v;
} catch (Exception ex) {
    Log.e(LOG_TAG, "error", ex);
    return null;

And the code of the setOnItemClickListener:

    public void onItemClick(AdapterView<?>
parent, View view,
            int position, long id) {

        station =
        if (head ==-1) { //first click
            head = position;
        else if (terminal ==-1){  //second click
            terminal = position;

The reason for this behaviour is that when row disappears and comes back, the getView method will be called again. So in your getView method you have to take into account the state of the row. Therefore you need the state variables head and terminal in your adapter.

Categories : Android

Related to : ListView is reusing views and I lose information after scrolling
ListView scrolling animation
The ViewTransition provides a lot of interesting examples on how to animate a ListView for operations like populate (the transition for the initial items at component creation), add, remove (self-explanatory) as well as other operations. Given a ListView you define an element Transition for each operation you want to animate. The animation framework can be exploited to create compound animations,

Categories : Qt
Android - Listview only works after scrolling
i've seen some problems related to getLayoutInflater... so in your getView method i suggest you to change your LayoutInflater construction: //(...) if(convertView==null){ LayoutInflater inflater = LayoutInflater.from(context); row = inflater.inflate(R.layout.club_board_post, parent, false); //(...) hope to be helpful.

Categories : Android
Listview containing checkbox and text is getting reset on scrolling
It because of recycling use of views in ListView. You should create some HashMap: HashMap<Integer, Boolean> checked; Then in your constructor do this: checked = new HashMap<Integer, Boolean>(getCount()); After set OnCheckedChangeListener on your checkboxes, and in event method do this: checked.put(position, yourCheckBoxCheckedState); And in getView() method do this: Boolean i

Categories : Javascript
How to stop onDraw() methods causing jerky scrolling of a ListView
A few things: 1) Post more source 2) read 3) consider using an ArrayAdapter You may want to track the number of times you call create bitmap, and how garbage collection is being handled there. If you're not properly recycling your views, and yo

Categories : Android
How to dynamically show an image on certain child views of a expandable listview
You don't need to recycle views, from the looks of it. Don't do it if you don't have to. (All the docs make it sound like a requirement and all the examples use it, but it isn't required. It's just "good practice" but when a "good practice" takes 10x as long as getting the job done should take, it really isn't a good practice is it??) The concept behind recycling has to do with scrolling through

Categories : Android
Recently Add
I'm trying to create an onListItemClick even for a customized adapter. The array of items is found in res/values folder
No navigation/status bar touch listener exists, why?
z-index in Relative layout
java.lang.SecurityException: Permission Denial: getIntentSender() when using UiAutomation in a test
mvvmcross videoview URL binding
Android Emulator Unfortunately dev tools has stopped
Square Dagger error: class is exclusively members injected / cannot be scoped required
Installing a widget from an APP
How to stop onDraw() methods causing jerky scrolling of a ListView
How to find my Google Play Services Android BASE64_PUBLIC_KEY
Set style programatically does not work
How to get contacts from phonebook and sim but skype, facebook etc. in android
Where to put JUnit test in Android project
My Android Studio project keeps running my old project/application
how to avoid OUtOfMemory problems with create Bitmap
What tools use and how do continuous integration and test in Android with eclipse?
Converting drawable resource to Bitmap Android
Fragment Transaction show() does not show fragment on second time
Espresso - How to match ActionBar visibility?
Viewport setting ignored in Phonegap Android app, but only on certain phones?
how to open an activity with url scheme android
Android AsyncTask and Thread different behavior
How can one ellicit a Toast from a Service to a Fragment
GCMIntentService onRegistered not called
LinearLayout cropping but not expanding in Scrollview
Get a file from the application directory
How to set layout params using view's on touch listener?
How to disable Google Fit and revoke permissions from the app itself
Android Wear - receiving message from Wear without WearableListenerService?
How can I start new activity from another package?
© Copyright 2017 Publishing Limited. All rights reserved.