How to disable items in a List View???

Posted by Techeretic on Stack Overflow See other posts from Stack Overflow or by Techeretic
Published on 2010-04-18T13:23:03Z Indexed on 2010/04/18 13:33 UTC
Read the original article Hit count: 185

I have a list view which is populated via records from the database. Now i have to make some records visible but unavailable for selection, how can i achieve that?

here's my code

public class SomeClass extends ListActivity { 
        private static List<String> products; 
        private DataHelper dh; 
        public void onCreate(Bundle savedInstanceState) { 
                dh = new DataHelper(this); 
                products = dh.GetMyProducts();  /* Returns a List<String>*/ 
                super.onCreate(savedInstanceState); 
                setListAdapter(new ArrayAdapter<String>(this, R.layout.myproducts, 
products)); 
                ListView lv = getListView(); 
                lv.setTextFilterEnabled(true); 
                lv.setOnItemClickListener( 
                        new OnItemClickListener() { 
                                @Override 
                                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, 
                                                long arg3) { 
                                        // TODO Auto-generated method stub 
                                        Toast.makeText(getApplicationContext(), ((TextView) 
arg1).getText(), 
                                                  Toast.LENGTH_SHORT).show(); 
                                } 
                        } 
                ); 
        } 
}

The layout file myproducts.xml is as follows

<?xml version="1.0" encoding="utf-8"?> 
<TextView    xmlns:android="http://schemas.android.com/apk/res/android" 
                        android:layout_width="fill_parent" 
                    android:layout_height="wrap_content" 
                    android:padding="10dp" 
                    android:textSize="16sp"> 
</TextView> 

© Stack Overflow or respective owner

Related posts about android-widget

Related posts about listviewitem