FileDocCategorySizeDatePackage
ListViewAddRemoveNoTransition.javaAPI DocAndroid 5.1 API3536Thu Mar 12 22:22:44 GMT 2015com.android.transitiontests

ListViewAddRemoveNoTransition

public class ListViewAddRemoveNoTransition extends android.app.Activity

Fields Summary
final ArrayList
numList
Constructors Summary
Methods Summary
public voidonCreate(android.os.Bundle savedInstanceState)


    
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.list_view_add_remove);

        final LinearLayout container = (LinearLayout) findViewById(R.id.container);

        final ListView listview = (ListView) findViewById(R.id.listview);
        for (int i = 0; i < 200; ++i) {
            numList.add(Integer.toString(i));
        }
        final StableArrayAdapter adapter = new StableArrayAdapter(this,
                android.R.layout.simple_list_item_1, numList);
        listview.setAdapter(adapter);

        listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
                String item = (String) parent.getItemAtPosition(position);
                for (int i = 0; i < listview.getChildCount(); ++i) {
                    TextView v = (TextView) listview.getChildAt(i);
                    if (!item.equals(v.getText())) {
                        v.setHasTransientState(true);
                    }
                }
                numList.remove(item);
                adapter.notifyDataSetChanged();
                view.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        for (int i = 0; i < listview.getChildCount(); ++i) {
                            TextView v = (TextView) listview.getChildAt(i);
                            v.setHasTransientState(false);
                        }
                    }
                }, 200);
            }

        });