2

我在视图翻转器中使用了列表视图,我希望当用户选择一个列表项时,当用户选择其他列表项或返回该“列表视图”活动时,它应该保持选中状态。这怎么可能?

4

2 回答 2

2
list.setOnItemClickListener(new OnItemClickListener() {

       public void onItemClick(AdapterView<?> arg0,
                    View arg1, int position, long arg3)
        {
            String selectedItem = list.getSelectedItem().toString();    
        });

此处 selectedItem 包含您在列表中选择的内容。

于 2012-10-03T12:58:11.107 回答
1

试试这样

simpleAdapter = new SimpleAdapter(this, docList, R.layout.your_layout,
            new String[] { "UserName", "Status"}, new int[] {
                    R.id.username, R.id.status});
    listView.setAdapter(simpleAdapter);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {

            registerForContextMenu(listView);
            listView.showContextMenu();

            tv = (TextView) arg1.findViewById(R.id.username);
            getListName = tv.getText().toString();               

            tv1 = (TextView) arg1.findViewById(R.id.status);
            getFriendUserId = tv1.getText().toString();  
        }
    });
于 2012-10-03T13:09:52.430 回答