4

我有一个ListActivity

public class MyActivity extends ListActivity{

    protected void onCreate(Bundle savedstate){
        super.onCreate(savedstate);
        getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
        getListView().setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {


        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            Log.i("xxx", "onPrepareActionMode");
            return false;
        }


        public void onDestroyActionMode(ActionMode mode) {
            // TODO Auto-generated method stub

        }


        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            // TODO Auto-generated method stub
            return true;
        }


        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            // TODO Auto-generated method stub
            return false;
        }


        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            Log.i("xxx", "pos: "+position+", checked: "+checked);
            mode.setTitle(getListView().getCheckedItemCount()+" checked");

        }
    });
    }

}

在这里我可以看到项目被检查,但检查项目的背景没有改变。我知道如何做到这一点,让你CustomAdapter和 ingetView()设置检查视图的背景。但我相信有更简单的方法来处理它。你能告诉我是否有办法实现它吗?

附加屏幕截图

4

1 回答 1

12

好的,我通过查看其他应用程序的源代码得到了答案。将 statelist drawable 设置为列表项的背景。在选择器state_activated = true中给出背景可绘制。

于 2012-12-08T01:56:51.287 回答