Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-apps-script/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 禁用AdapterView适配器中的项目_Android_Android Listview_Android Adapterview_Onitemclick - Fatal编程技术网

Android 禁用AdapterView适配器中的项目

Android 禁用AdapterView适配器中的项目,android,android-listview,android-adapterview,onitemclick,Android,Android Listview,Android Adapterview,Onitemclick,基本上,我希望当我取消选中第一个项目的复选框时,第二个项目是“灰显”的、不可点击的或禁用的 @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if(position == 0) { //disable.enable push CheckBox checkBox = (Ch

基本上,我希望当我取消选中第一个项目的复选框时,第二个项目是“灰显”的、不可点击的或禁用的

@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
        }
    }
@覆盖
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
如果(位置==0){
//禁用。启用推送
CheckBox=(CheckBox)mRoot.findViewById(R.id.cbRowCheckBox);
checkBox.setChecked(!checkBox.isChecked());
mpushecked=checkBox.isChecked();
如果(已启用MPU){
//已启用推送的代码
//启用位置1的代码,我在想一些事情,
adapter.getposition(1).setEnabled(true);
}否则{
//推送禁用代码
adapter.getposition(1).setEnabled(false);
}
}否则如果(位置==1){
//推送通知设置
//公开意图
}
}

我想我可以得到项目所在的位置,然后将其设置为false,设置为
setEnabled()
。这样对吗?如果是这样的话,我想不出该如何定位该项目。如果现在,最好的方法是什么?

getposition到底做什么

我认为不能直接从适配器获取视图,因为listView经常重用它们

我认为最好的方法是跟踪要启用的项目位置,并从适配器中的getView()或bindView()方法相应地更新视图

基本上,我想当我取消选中第一项,第二项的框 项目已“灰显”且不可拾取,或已禁用

选中
复选框时
在适配器级别存储下一行的
位置
,该位置将被禁用并调用
notifyDataSetChanged()

在适配器中,首先重写
isEnabled()
方法,并使其返回
false
,前提是位置参数与先前存储的禁用行位置相匹配(对于任何其他位置为true)。这将使该行不可单击


然后在
getView()
方法中,检查当前位置是否为禁用行的位置,并使其看起来褪色,或者您希望如何褪色。

您应该使用PreferenceActivity和android:dependency属性。非本机首选项一个非常糟糕的想法我只想知道当按下位置0时如何禁用列表位置1。。。。。我还有其他的逻辑。我把它拿了出来,所以这将是一篇很长的帖子,这正是PreferenceActivity和dependency的用意。。我只是想确定您不能使用它们,但我仍然不确信NotifyDataSetChanged()是否能使复选框始终处于选中状态。。。当我点击时,它永远不会changes@DDukesterman我不知道你在做什么,尤其是当你在mRoot视图(?!?)而不是视图参数中查找复选框时。我做了一个基本的样品,你可以在这里找到。对于更复杂的场景,应使用基于首选项的活动。