选择在列表视图(刷卡-列表视图)行,停留在pssed状态$ P $重新instanciating适配器后视图、列表、适配器、停留在

由网友(心比柠檬酸)分享简介:我有一个ListView和该行的布局与设置为以下选择背景的孩子:I have a listview and the row's layout has a child with the background set to the following selector :我有一个ListView和该行的布局与设置为以下选择背景的孩子:

I have a listview and the row's layout has a child with the background set to the following selector :

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
    <shape android:shape="rectangle">
        <solid android:color="@color/pressed_panel" />
        <corners android:radius="@dimen/rounded_panel_corners" />
    </shape>
</item>
<item>
    <shape android:shape="rectangle">
        <solid android:color="#ffffff" />
        <corners android:radius="@dimen/rounded_panel_corners" />
    </shape>
</item>

而现在这种情况下发生的:

And now this scenario happens:

我实例化的适配器,并将其设置为列表视图,与下面的列表中,假设模型中的(一ListFragment内)我的第一行preSS(发生对于其他行也),只有当pressed,选择留在pressed状态,呈现出一些灰色,咄!我从一个菜单项的一些选择和触发:创建适配器的新实例,用列表模型B,并将其应用到列表视图。 而现在的问题:第一行有在pressed状态选择 I instantiate the adapter and set it to the listview, with an underlying list, let's say model A (inside a ListFragment) I press on the first row (happens for other row also), and only while pressed, the selector stays in the pressed state, showing some gray color, duh! I select from a menu some item and that triggers: creating a new instance of the adaptor, with list model B, and apply it to the listview. And now the problem: the first row has the selector in the pressed state

更多信息:通过阿布舍克V在评论提出@Questions:1.背景设置为排布置的孩子,而不是排布置自己的权利?权利!这里是布局,选择器被设置为相对ID为container_conversation

More info: @Questions raised by Abhishek V in comment: 1. Background is set to row layout's child and not the row layout itself right? Right! Here is the layout, the selector is set to the relative with id "container_conversation"

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">

<CheckBox
    android:id="@+id/checkbox_select_row"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:layout_marginLeft="18dp"
    android:button="@drawable/checkbox_round_selector"
    android:focusable="false"
    android:clickable="true"
    android:padding="8dp"/>

<FrameLayout
    android:id="@+id/row"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:descendantFocusability="blocksDescendants"
    android:orientation="vertical"
    >

    <RelativeLayout
        android:id="@+id/back"
        android:layout_width="wrap_content"
        android:layout_height="82dp"
        android:layout_gravity="right"
        android:layout_marginBottom="4dp"
        android:layout_marginRight="9dp"
        android:layout_marginTop="4dp">
            <SomeViews>
    </RelativeLayout>

    <FrameLayout
        android:id="@+id/front"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:visibility="visible"
        tools:visibility="visible">

        <RelativeLayout
            android:id="@+id/container_conversation"
            android:layout_width="match_parent"
            android:layout_height="82dp"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="9dp"
            android:layout_marginRight="9dp"
            android:layout_marginTop="4dp"
            android:background="@drawable/white_rounded_panel">
                <SomeViews>
        </RelativeLayout>

        <View
            android:id="@+id/unread_indicator"
            android:layout_width="8dp"
            android:layout_height="8dp"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="5dp"
            android:background="@drawable/orange_circle"
            android:visibility="gone"
            tools:visibility="visible" />
    </FrameLayout>
</FrameLayout>

2)点击/触摸监听器设置为排布置,或者它的孩子呢?儿童3)您使用监听器,它是的onClick,onTouch或onItemClick?ListView控件实际上是从库中复制Android的swipelistview https://github.com/47deg/android-swipelistview 。,做损害中点击设置如下:

2) Click/touch listener is set to row layout or it's child? Child 3) Which listener you are using, is it onClick, onTouch or onItemClick? The listview is actually copied from the library android-swipelistview https://github.com/47deg/android-swipelistview . The click that does the damage is set as follows:

frontView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            swipeListView.onClickFrontView(downPosition);
        }
    });

和这个点击都会通知这个监听器

and this click goes notifying this listener

BaseSwipeListViewListener swipeListener = new BaseSwipeListViewListener() {
    @Override
    public void onClickFrontView(int position) {

    }//...

感谢您!

推荐答案

您所面临的已经在这里报道的 https://github.com/47deg/android-swipelistview/issues/41 。

The issue you are facing has been reported here https://github.com/47deg/android-swipelistview/issues/41.

根据在该线程的cooment由@strgev的解决方法是 -

As per the cooment by @strgev in that thread, the fix is to -

编辑类 SwipeListViewTouchListener 中加入下面onTouch方法行:

edit class SwipeListViewTouchListener by adding the line below to onTouch method:

....
case MotionEvent.ACTION_UP: {
view.onTouchEvent(motionEvent);
...

你可以试试吗?

阅读全文

相关推荐

最新文章