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.
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;
}
Sharing my experience, the following did the trick (view refers to the list item view):
view.setEnabled(false);
view.setOnClickListener(null);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With