Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable an item in my ListView

I have a ListView set in my AlertDialog in Android and i'm trying to add separators as heading titles to help organize the information. I figured out how to display them... but they are still selectable by the user which isn't good.

Is there a way to disable an item to be selectable in an Android ListView? I found an method isEnabled(int position) to see if an item is enabled or not but none to see if its disabled.

like image 524
jfisk Avatar asked Aug 16 '11 06:08

jfisk


3 Answers

Just Now i have implemented it

ListView list=new ListView(this);
list.getChildAt(0).setEnabled(false);
like image 152
Tofeeq Ahmad Avatar answered Oct 13 '22 05:10

Tofeeq Ahmad


override this in ur code to disable the focus.

         @Override
         public boolean isEnabled(int position) {
            return false;
           }
like image 34
Randroid Avatar answered Oct 13 '22 05:10

Randroid


I've found a lot of comments saying that

setEnabled(false)
setClickable(false)
setFocusable(false)

would work, but the answer is NO

The only workaround for this approach is doing:

view = inflater.inflate(R.layout.row_storage_divider, parent, false);
view.setOnClickListener(null);
like image 41
cesards Avatar answered Oct 13 '22 04:10

cesards