如何在Modal Bottomsheet android中动态更改内容

如何在Modal Bottomsheet android中动态更改内容,android,android-layout,android-recyclerview,bottom-sheet,Android,Android Layout,Android Recyclerview,Bottom Sheet,我有一个底部的xml,它包含两个元素,Follow和Copy link。。当我单击Follow时,它应该被动态地更改为Unfollow。我尝试使用setText,但没有成功 请指导我如何更改底页对话的文本 这是我的底层xml文件 <LinearLayout app:layout_behavior="android.support.design.widget.BottomSheetBehavior" android:layout_width="match_parent" android:la

我有一个底部的xml,它包含两个元素,Follow和Copy link。。当我单击Follow时,它应该被动态地更改为Unfollow。我尝试使用setText,但没有成功

请指导我如何更改底页对话的文本

这是我的底层xml文件

<LinearLayout app:layout_behavior="android.support.design.widget.BottomSheetBehavior"
android:layout_width="match_parent"
android:layout_height="180dp"
android:orientation="vertical"
android:background="#ffffff"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<LinearLayout
    android:id="@+id/bottom_sheet_follow"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:clickable="true"
    android:focusable="true"
    android:orientation="horizontal"
    android:foreground="?android:attr/selectableItemBackground"
    android:padding="16dp">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:srcCompat="@drawable/ic_mode_follow_grey_24dp"
        />
    <TextView
        android:id="@+id/followTView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="16dp"
        android:text="Follow"/>
</LinearLayout>
<LinearLayout
    android:id="@+id/bottom_sheet_copy"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:clickable="true"
    android:focusable="true"
    android:orientation="horizontal"
    android:foreground="?android:attr/selectableItemBackground"
    android:padding="16dp">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:srcCompat="@drawable/ic_copy_grey_24dp"
        />
    <TextView
        android:id="@+id/copyLink"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="16dp"
        android:text="Copy link"/>
</LinearLayout>
但是,followTextView(我的意思是followTView)并没有变为Unfollow。 请告诉我哪里出了问题


提前感谢…

您可以使用布尔值完成此操作,我已使用imageview完成此操作。 也许对你有帮助

 //Initialize boolean as true by default
   public boolean showingFirst = true;

  holder.ivFavorite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (showingFirst){
                    Toast.makeText(mActivity, "Item added to favorite", Toast.LENGTH_SHORT).show();
                    holder.ivFavorite.setImageResource(R.drawable.filled_heart);
                    showingFirst = false;
                }else {
                    holder.ivFavorite.setImageResource(R.drawable.ic_favorite);
                    Toast.makeText(mActivity, "Item removed from favorite", Toast.LENGTH_SHORT).show();
                    showingFirst = true;
                }

            }
        });

只是猜测而已。您是否尝试重新安排代码?在调用“mDialog.show()”之前,可能应该首先加载click侦听器

 //Initialize boolean as true by default
   public boolean showingFirst = true;

  holder.ivFavorite.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (showingFirst){
                    Toast.makeText(mActivity, "Item added to favorite", Toast.LENGTH_SHORT).show();
                    holder.ivFavorite.setImageResource(R.drawable.filled_heart);
                    showingFirst = false;
                }else {
                    holder.ivFavorite.setImageResource(R.drawable.ic_favorite);
                    Toast.makeText(mActivity, "Item removed from favorite", Toast.LENGTH_SHORT).show();
                    showingFirst = true;
                }

            }
        });
 View bottomSheetView = View.inflate(mContext, R.layout.bottom_sheet_dialog_for_sharedposts, null);

        followBtnLayout = bottomSheetView.findViewById(R.id.bottom_sheet_follow);
        followTView = bottomSheetView.findViewById(R.id.followTView);

        followBtnLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                followTView.setText("Unfollow");
            }
        });

        mDialog = new BottomSheetDialog(mContext);
        mDialog.setContentView(bottomSheetView);
        mDialog.show();