android Listview第一个行默认为选中状态,怎么实现按下某一行在没松开时设置其为选中行,选中行为蓝色

2024-10-31 05:29:15
推荐回答(1个)
回答1:

1. 你从 A跳转到B的时候 通过 INTENT 传一个值  intent.putStringExtart("selection", 4);
2. 然后在B接受这个值:  int selection = getExtart().getIntExtart("selection");
3. 然后设置ListView 选择这个 selection:  myListView.setselection(selection);

就OK了

----------- 补充:
刚看太快看错了,  如果是想选中ListView 某一个 TEXTVIEW, 需要这样:

ViewGroup item = (ViewGroup)mAdapter.getChild(selection);
TextView textView = item.findviewById(R.id.textView1);
textview.requestFocus();

前提是要设置这个 textview 的 focusable=true, 还有 focusableInTouchmode = true