android badgeview listview,listview - Android: set list view item as "selected" (highlighted) - Stac...

开发者分享在平板应用中实现类似Gmail左列选择项、右栏详细内容显示的问题。遇到点击一次高亮但需二次确认选中,且列表项选择丢失于右侧Fragment切换的情况。已尝试设置选择器和ListView属性,寻求解决方案。
摘要由CSDN通过智能技术生成

In my application I want to do something similar to gmail app on tablets, in the left to have the list of items and in the right to have a fragment with the content of that item, like for gmail app this content is being downloaded after selection. After I click on an item I want it to remain highlighted until, of course I change the selection.

I reached a point where this works but only if I click twice on the same item, so first I click, selection works and then the item goes back to its 'default' state and if I click again on it, the selector (for selected state) is visible.

This is what I have so far:

1) The selector (listitem_background.xml)

2) For the top linear layout of the list item:

android:background="@drawable/listitem_background"

(I tried setting this as listselector, as well)

3) This is the ListView:

android:id="@+id/my_list_view"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:choiceMode="singleChoice"

android:dividerHeight="1dp"

android:drawSelectorOnTop="true"

android:fadeScrollbars="true"

android:fastScrollEnabled="true"

android:focusable="true"

android:focusableInTouchMode="true"

android:scrollbarFadeDuration="100"

android:scrollbars="vertical" />

4) In the code part I tried to play with this:

@Override

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

view.setSelected(true);

...

}

[EDIT] In fact I've noticed that the selection is lost after the commit of the fragment in the right side of the screen. If I don't commit the fragment it works like a charm...

I think I need something like this in the selector:

But obviously not this...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值