0

我的 ListView 看起来像这样:

[复选框] [文本视图]

我的问题是,当 CheckBox 被选中时,如何更改项目位置?我的意思是说,如果用户从 ListView 中检查了任何项目,那么被检查的项目会走到最后,因此它的位置会从当前变为最后。

提前致谢。

4

3 回答 3

0

这是您可以遵循的步骤。我没有测试过,但你可以试试这个。

// your value array you are binding with listview
private final String[] values;

// put default value to "n". size will be the same as for values array.
private final String[] valuesChecked; 


   onClick of Checkbox Listview



@Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        //get checkbox is checked or not
        if it is checked then{
            valuesChecked[position]="y";
        }else{
            valuesChecked[position]="n";
        }

        // short your values array by first "n" and after "y".
        // call your adapter.notifyDataSetChanged();

    }

祝你好运 :)

于 2013-09-11T12:29:34.673 回答
0

对 listView 使用自定义适配器。这是一个例子。现在从你的 ListActivity 类

final ListView lv = getListView();

lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {

    HashMap<String, Object> map = (HashMap<String, Object>)
    lv.getItemAtPosition(position);
   // get the item Position from here and make the nacessary changes
  // and update the listview again.

    }
于 2013-09-11T12:23:49.743 回答
0

在不发布任何代码的情况下,这将是您需要采取的伪步骤的简要概述

您只需更新适配器使用的数据集的顺序(通常是数组列表或对象数组),然后调用

notifyDataSetChanged()

在您的适配器上。

因此,在您的情况下,您希望将元素放在被单击的位置,并将其放在对象数组列表的末尾。

如果您发布一些代码,您可能会得到更详细的答案

于 2013-09-11T12:24:33.450 回答