当我单击返回按钮后返回到活动时,主活动的RecycleView内的按钮被冻结

时间:2018-08-05 13:25:34

标签: firebase android-layout firebase-realtime-database buttonclick recyclerview-layout

我有2个活动:主要和评论。 Main Activity具有带有所有listItems的RecyclerView。每个listItem都有按钮->点赞,评论,共享和删除。

评论活动是当我单击Main Activity RecyclerView listItem上的评论按钮时打开的另一个活动。发表评论后,当我单击“后退”按钮时,它返回到“主活动”,但所有按钮均不起作用。它们的行为就像冻结了一样,不再可单击。

主要活动- enter image description here

评论活动- enter image description here

代码-主要活动(一切正常,除了我回到主要活动时,所有按钮似乎都无法在回收视图中使用

// Attach a ChildEventListener : connecting datasource to Listview UI
    mMessagesDatabaseReference.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            // Get the value from the DataSnapshot and add it to the item list
            post itemObject = dataSnapshot.getValue(post.class);
            //this is where data from database is entered into a list of objects
            postAdapterObject.add(itemObject);
            progressBar.setVisibility(View.GONE);
        }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

            post itemObject = dataSnapshot.getValue(post.class);
            postAdapterObject.add(itemObject);

            progressBar.setVisibility(View.GONE);

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

//                post itemObject = dataSnapshot.getValue(post.class);
                //postAdapterObject.add(itemObject);

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });

我的listItem填充器布局的XML代码-

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/listItemColor"
        android:orientation="vertical">

    // code of other layout items here

 <!--Layout for like comment and buttons starts -->

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <Button
            android:id="@+id/like"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Like"
            android:textAllCaps="true"
            android:textColor="@color/common_google_signin_btn_text_light_default"
            android:textSize="14dp" />

        <Button
            android:id="@+id/comment"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Comment"
            android:textAllCaps="true"
            android:textColor="@color/common_google_signin_btn_text_light_default"
            android:textSize="14dp" />

        <Button
            android:id="@+id/share"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Share"
            android:textAllCaps="true"
            android:textColor="@color/common_google_signin_btn_text_light_default"
            android:textSize="14dp" />

        <Button
            android:id="@+id/delete"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:background="#FFFFFF"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Delete"
            android:textAllCaps="true"
            android:textColor="@color/common_google_signin_btn_text_light_default"
            android:textSize="14dp" />
    </LinearLayout>

//rest of the code

主要活动的XML代码-

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorBackground"
    android:descendantFocusability="beforeDescendants"
    android:focusableInTouchMode="true"
    tools:context=".MainActivity">

// other code

    <ListView
        android:id="@+id/listViewLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:layout_marginTop="10dp"
        android:layout_below="@id/filter"
        android:layout_above="@id/buttonBar"
        android:dividerHeight="10dp"
        android:divider="@android:color/transparent"
        android:layout_marginBottom="10dp" />

// other code

请告诉我,我要去哪里了

0 个答案:

没有答案