Reputation: 4446
I wanna disable all list items
in a ListView
excluding the 1st position item.
That means every time the 1st item can be clicked not the all.
How can I do this. Is there any way. Give me some sample code.
Upvotes: 0
Views: 2234
Reputation: 4446
I got my answer. only I have to use two override methods in custom adapter,
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int position) {
return true;
}
Upvotes: 2
Reputation: 1932
here you have to create custom adapter from listView items and use different color for first item and rest of the items in getView method of custom adapter then the disable click event of other items excluding first position
Upvotes: 0
Reputation: 19788
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:listSelector="@android:color/transparent" />
ListView lv = ...
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
if(position == 1)
{
view.setBackgroundColor(Color.GREEN);
}
}
});
Upvotes: 1