0

enter image description here

Basically I want when I uncheck the box on the first item, the second item is "greyed out" and unclickable, or disabled.

@Override
    public void onItemClick(AdapterView<?> parent, View view, int position,  long id) {


        if(position == 0) { 
            //disable.enable push
            CheckBox checkBox = (CheckBox) mRoot.findViewById(R.id.cbRowCheckBox);
            checkBox.setChecked(!checkBox.isChecked());

            mPushEnabled = checkBox.isChecked();

            if (mPushEnabled) {
                //code for push enabled
                //code to let position 1 enabled, i was thinking something along th e lines,
               adapter.getposition(1).setEnabled(true);
            } else {
                //code for push disabled
                adapter.getposition(1).setEnabled(false);
            }
        } else if(position == 1) {
            //push notification settings
            //open intent
        }
    }

I was thinking that I could get the position of where the item is and just set it false to setEnabled(). Is that the right way? If so, I can't figure out how to target the item. If now, what's the best way?

user
  • 86,916
  • 18
  • 197
  • 190
DDukesterman
  • 1,391
  • 5
  • 24
  • 42
  • You should use a PreferenceActivity and the android:dependency property. Non native preferences a very very very very very very bad idea – Waza_Be Jul 23 '13 at 15:57
  • I just want to know how to disable list position 1 when position 0 s pressed..... I have all the other logic in there. I took it out so it would be a really long post – DDukesterman Jul 23 '13 at 16:05
  • That's exactly what PreferenceActivity and dependency are for.. I just wanted to be sure you cannot use them, and I am still not convinced – Waza_Be Jul 23 '13 at 17:51

2 Answers2

0

what exactly getposition does?

I think that you can't do it getting directly the View from the adapter because they are frequently reused by the listView.

i think the best way to do this is to keep track of the item position you want enabled and update the view accordingly from the getView() or bindView() method in your adapter.

Mario Lenci
  • 10,422
  • 5
  • 39
  • 50
0

Basically I want when I uncheck the box on the first item, the second item is "greyed out" and unclickable, or disabled.

When you check that CheckBox store at the adapter level the position of the next row, the one that would be disabled and call notifyDataSetChanged().

In the adapter first override the isEnabled() method and make it return false if the position parameter matches the previously stored position for the disable row(and true for any other position). This will make that row not clickable.

Then in the getView() method check if the current position is the position of a disabled row and make it look faded or how else you want.

user
  • 86,916
  • 18
  • 197
  • 190
  • notifydatasetchanged() makes it to where the checkbox is always check... when i click, it never changes – DDukesterman Jul 23 '13 at 18:56
  • @DDukesterman I don't know what you're doing especially as you look for that CheckBox in the mRoot view(?!?) instead of the view parameter. I've made a basic sample that you can find here https://github.com/luksprog/DroidPlayground/blob/master/src/com/luksprog/playground/adapter/PreferenceLikeAdapter.java . For more complex scenarios you should use a preference based activity. – user Jul 24 '13 at 09:09