Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.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
Java 已禁用ListView的单击项_Java_Android_Eclipse_Listview_Android Listview - Fatal编程技术网

Java 已禁用ListView的单击项

Java 已禁用ListView的单击项,java,android,eclipse,listview,android-listview,Java,Android,Eclipse,Listview,Android Listview,我正在使用simpledapter绑定ListView。现在,当用户单击项目时,我想从Click()事件禁用该时间。我找到了一些关于isEnabled()的教程,但我不知道如何使用它? 请帮我解决这个问题。我正在使用自定义列表视图。 下面的代码禁用列表视图 SimpleAdapter adapter = new SimpleAdapter(this, arrlist, R.layout.topicwisequestion, new String[] { "option"

我正在使用
simpledapter
绑定
ListView
。现在,当用户单击项目时,我想从
Click()
事件禁用该时间。我找到了一些关于
isEnabled()
的教程,但我不知道如何使用它?

请帮我解决这个问题。我正在使用自定义
列表视图

下面的代码禁用
列表视图

SimpleAdapter adapter = new SimpleAdapter(this, arrlist,
            R.layout.topicwisequestion, new String[] { "option" },
            new int[] { R.id.option }) {

        public boolean areAllItemsEnabled() {
            return ignoreDisabled;
        }

        public boolean isEnabled(int position) {
            if (areAllItemsEnabled()) {
                return true;
            }
            return false;
        }
    };
    lvTWOptions.setAdapter(adapter);

    lvTWOptions.setOnItemClickListener(new OnItemClickListener() {
         public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
              // Code...   
         }
    });
simpledapter adapter=新的simpledapter(这个,arrlist,
R.layout.topicwisequestion,新字符串[]{“选项”},
新int[]{R.id.option}){
公共布尔值areAllItemsEnabled(){
返回忽略禁用;
}
公共布尔值isEnabled(整型位置){
如果(AreaAllItemsEnabled()){
返回true;
}
返回false;
}
};
lvTWOptions.setAdapter(适配器);
setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
//代码。。。
}
});

您必须扩展简单适配器,维护已单击的索引列表,实现isEnabled(int)并检查传递的整数是否在列表中。然后,您可以在单击列表项后有选择地禁用它们

添加一些代码:

public class MySimpleAdapter extends SimpleAdapter {

    private List<Integer> mDisabledRows;

    public MySimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
        super(context, data, resource, from, to);
        mDisabledRows = new ArrayList<Integer>();
    }

    public void disableRow(int index) {
        mDisableRows.clear();
        mDisabledRows.add(index);
    }

    @Override
    public boolean isEnabled(int index) {
        return !mDisabledRows.contains(index);
    }
}
公共类mysimpledapter扩展了simpledapter{
私有列表行;
public mysimpledapter(上下文,列表>数据,int资源,字符串[]from,int[]to){
超级(上下文、数据、资源、从、到);
mDisabledRows=新的ArrayList();
}
公共无效禁用行(整数索引){
mDisableRows.clear();
添加(索引);
}
@凌驾
公共布尔值isEnabled(整型索引){
return!mDisabledRows.contains(索引);
}
}
从您的
onItemClick
方法调用
adapter.disableRow(position)


我读到这一点,因为您希望在单击某行后禁用该行。如果只想禁用上次单击的行,则可以存储上次单击的索引

您必须扩展简单适配器,维护已单击的索引列表,实现isEnabled(int),并检查传递的整数是否在列表中。然后,您可以在单击列表项后有选择地禁用它们

添加一些代码:

public class MySimpleAdapter extends SimpleAdapter {

    private List<Integer> mDisabledRows;

    public MySimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) {
        super(context, data, resource, from, to);
        mDisabledRows = new ArrayList<Integer>();
    }

    public void disableRow(int index) {
        mDisableRows.clear();
        mDisabledRows.add(index);
    }

    @Override
    public boolean isEnabled(int index) {
        return !mDisabledRows.contains(index);
    }
}
公共类mysimpledapter扩展了simpledapter{
私有列表行;
public mysimpledapter(上下文,列表>数据,int资源,字符串[]from,int[]to){
超级(上下文、数据、资源、从、到);
mDisabledRows=新的ArrayList();
}
公共无效禁用行(整数索引){
mDisableRows.clear();
添加(索引);
}
@凌驾
公共布尔值isEnabled(整型索引){
return!mDisabledRows.contains(索引);
}
}
从您的
onItemClick
方法调用
adapter.disableRow(position)

我读到这一点,因为您希望在单击某行后禁用该行。如果只想禁用上次单击的行,则可以存储上次单击的索引

像这样做

ListAdapter adapter = new SimpleCursorAdapter(MyList, Layout, c,
new String[] { "Name", "Score" }, to)
{
public boolean areAllItemsEnabled()
{
return false;
}

public boolean isEnabled(int position)
{
return false;
}
};
定义一个布尔变量

boolean ignoreDisabled = false;
然后在AllitemSenable区域:

public boolean areAllItemsEnabled() {
    return ignoreDisabled;
}
然后在我被逮捕的开始:

public boolean isEnabled(int position) {
    if (areAllItemsEnabled()) {
        return true;
    }
}
或者第二种方法是在适配器类中定义以下代码

private int mLastClicked;
public void setLastClicked(int lastClicked){
    mLastClicked = lastClicked;
}
然后

public boolean areAllItemsEnabled() {
    return false;
}

public boolean isEnabled(int position) {
    // return false if position == position you want to disable
}
使用isEnabled方法添加上次单击事件的位置

为了进一步的参考,你可以检查这个

希望这对你有帮助

像这样做

ListAdapter adapter = new SimpleCursorAdapter(MyList, Layout, c,
new String[] { "Name", "Score" }, to)
{
public boolean areAllItemsEnabled()
{
return false;
}

public boolean isEnabled(int position)
{
return false;
}
};
像这样做

ListAdapter adapter = new SimpleCursorAdapter(MyList, Layout, c,
new String[] { "Name", "Score" }, to)
{
public boolean areAllItemsEnabled()
{
return false;
}

public boolean isEnabled(int position)
{
return false;
}
};
定义一个布尔变量

boolean ignoreDisabled = false;
然后在AllitemSenable区域:

public boolean areAllItemsEnabled() {
    return ignoreDisabled;
}
然后在我被逮捕的开始:

public boolean isEnabled(int position) {
    if (areAllItemsEnabled()) {
        return true;
    }
}
或者第二种方法是在适配器类中定义以下代码

private int mLastClicked;
public void setLastClicked(int lastClicked){
    mLastClicked = lastClicked;
}
然后

public boolean areAllItemsEnabled() {
    return false;
}

public boolean isEnabled(int position) {
    // return false if position == position you want to disable
}
使用isEnabled方法添加上次单击事件的位置

为了进一步的参考,你可以检查这个

希望这对你有帮助

像这样做

ListAdapter adapter = new SimpleCursorAdapter(MyList, Layout, c,
new String[] { "Name", "Score" }, to)
{
public boolean areAllItemsEnabled()
{
return false;
}

public boolean isEnabled(int position)
{
return false;
}
};

我使用了下面的代码并解决了我的问题。它非常简单。无需使用任何额外代码。
我所做的是,我已经把条件检查的立场,然后根据它,我禁用点击的项目。

我的代码:

    int pos;
    SimpleAdapter adapter = new SimpleAdapter(this, arrlist, R.layout.topicwisequestion, new String[] { "option" }, new int[] { R.id.option }) {

                public boolean isEnabled(int position) {
                    if (position != 0) {
                        if (position == pos) {
                            return false;
                        } else {
                            return true;
                        }
                    } else {
                        return true;
                    }
                }
            };

            lvTWOptions.setAdapter(adapter);

            lvTWOptions.setOnItemClickListener(new OnItemClickListener() {

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

                    pos = position;
                }
            });
int-pos;
simpledapter adapter=new simpledapter(this,arrlist,R.layout.topicwisequestion,新字符串[]{“option”},新int[]{R.id.option}){
公共布尔值isEnabled(整型位置){
如果(位置!=0){
如果(位置==位置){
返回false;
}否则{
返回true;
}
}否则{
返回true;
}
}
};
lvTWOptions.setAdapter(适配器);
setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
pos=位置;
}
});

我使用了下面的代码并解决了我的问题。它非常简单。无需使用任何额外代码。
我所做的是,我已经把条件检查的立场,然后根据它,我禁用点击的项目。

我的代码:

    int pos;
    SimpleAdapter adapter = new SimpleAdapter(this, arrlist, R.layout.topicwisequestion, new String[] { "option" }, new int[] { R.id.option }) {

                public boolean isEnabled(int position) {
                    if (position != 0) {
                        if (position == pos) {
                            return false;
                        } else {
                            return true;
                        }
                    } else {
                        return true;
                    }
                }
            };

            lvTWOptions.setAdapter(adapter);

            lvTWOptions.setOnItemClickListener(new OnItemClickListener() {

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

                    pos = position;
                }
            });
int-pos;
simpledapter adapter=new simpledapter(this,arrlist,R.layout.topicwisequestion,新字符串[]{“option”},新int[]{R.id.option}){
公共布尔值isEnabled(整型位置){
如果(位置!=0){
如果(位置==位置){
返回false;
}否则{
返回true;
}
}否则{
返回true;