Reputation: 752
I have following code which is quite easy to understand. I want some specific child of this listview to be non clickable.
ArrayAdapter<String> adapter =
new ArrayAdapter<String>(this,R.layout.list_item,R.id.module_name_item, testdata);
m_listview.setAdapter(adapter);
Log.i("check","1");
if(sectionAttempts.get(0).equals("0"))
{
m_listview.getChildAt(2).setEnabled(false);
m_listview.getChildAt(3).setEnabled(false);
}
else
{
if(sectionAttempts.get(2).equals("0"))
{
m_listview.getChildAt(3).setEnabled(false);
}
}
I am getting error in
m_listview.getChildAt(2).setEnabled(false);
as java.lang.NullpointerException. I tried to find the error and used Log.i("check",m_listview.getChildCount()); And it show 0. so i am guessing the listview hasnt beent created yet!! How is that possible.
What seems to be the problem? Thanx for any help in advance.
Upvotes: 5
Views: 6905
Reputation: 974
Override areAllItemsSelectable()
method. Return false to say all the items are not clickable.
@Override
public boolean areAllItemsSelectable() {
return false;
}
And then Override below method to return which item is not clickable
@Override
public boolean isEnabled(int position) {
if(position == your_item_pos) {
return false;
}
return true;
}
Upvotes: 16
Reputation: 35991
Sharing my experience, the following did the trick (view refers to the list item view):
view.setEnabled(false);
view.setOnClickListener(null);
Upvotes: 7
Reputation: 6141
Seems as if you didn't initilize your ListView. In onCreate
Use m_listview=getListView()
if you are using ListActivity or m_listview=findViewById(R.id...)
if you are using regular activity.
Upvotes: 0