gpt4 book ai didi

android - 单选按钮状态未保留在回收站 View 中

转载 作者:行者123 更新时间:2023-11-29 19:03:08 27 4
gpt4 key购买 nike

这里的问题是,每当我向上滚动回收站 View 并返回顶部时,所选单选按钮就会消失。同样,当回收者 View 卡被重复使用时,单选按钮会在新卡中显示为已选中。

下面是我在recyclerview中使用的viewholder和它的xml

radioButton.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="wrap_content"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dimen_10dp"
android:background="@drawable/pdp_card_background"
android:orientation="vertical"
android:padding="@dimen/dimen_10dp">

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

<com.android.sea.corenative.customviews.MenuIconTextView
android:id="@+id/rating_star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="AAAAA"
android:textColor="@color/star_color"
android:textSize="@dimen/txt_12sp" />

<com.android.sea.corenative.customviews.NewTextFieldNormal
android:id="@+id/review_helpful_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end"
android:text="@string/review_helpful_count"
android:textColor="@color/ratings_text_color"
android:textSize="@dimen/txt_12sp" />

</LinearLayout>

<com.android.sea.corenative.customviews.NewTextViewSemiBold
android:id="@+id/review_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen_10dp"
android:text="Not that bad for the price"
android:textColor="@color/ratings_text_color"
android:textSize="@dimen/txt_14sp" />

<com.android.sea.corenative.customviews.NewTextFieldNormal
android:id="@+id/review_author_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen_5dp"
android:lineSpacingMultiplier="1.42"
android:text="By Enovak"
android:textColor="@color/ratings_and_review_author_text"
android:textSize="@dimen/txt_12sp" />

<com.android.sea.corenative.customviews.NewTextFieldNormal
android:id="@+id/review_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="1.42"
android:text="Fort Johnson, NY | Tue, May 16, 2017"
android:textColor="@color/ratings_and_review_author_text"
android:textSize="@dimen/txt_12sp" />

<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_marginBottom="@dimen/dimen_10dp"
android:layout_marginTop="@dimen/dimen_10dp"
android:background="@drawable/dotted"
android:layerType="software" />

<LinearLayout
android:id="@+id/verified_purchase_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.android.sea.corenative.customviews.MenuIconTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="G"
android:textColor="@color/ratings_text_color"
android:textSize="@dimen/txt_12sp" />

<com.android.sea.corenative.customviews.NewTextViewSemiBold
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/dimen_3dp"
android:text="Verified Purchase"
android:textColor="@color/ratings_text_color"
android:textSize="@dimen/txt_12sp" />
</LinearLayout>

<android.support.v7.widget.RecyclerView
android:id="@+id/review_images_recyclerview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen_5dp">

</android.support.v7.widget.RecyclerView>

<com.android.sea.corenative.customviews.TextViewOpenSansRegular
android:id="@+id/review_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dimen_5dp"
android:text="description"
android:textColor="@color/ratings_text_color"
android:textSize="@dimen/txt_14sp" />
<!--android:lineSpacingMultiplier="1.3"-->

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="@dimen/dimen_10dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/dimen_10dp"
android:text="@string/review_helpful" />

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

<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/yes_radio_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/dimen_10dp"
android:buttonTint="@color/app_specific_text_color"
android:text="@string/yes" />

<android.support.v7.widget.AppCompatRadioButton
android:id="@+id/no_radio_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/dimen_10dp"
android:buttonTint="@color/app_specific_text_color"
android:text="@string/no" />

</RadioGroup>


</LinearLayout>

<TextView
android:id="@+id/rr_report_issue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/dimen_10dp"
android:text="@string/report_issue"
android:textSize="@dimen/txt_12sp"
android:textColor="@color/star_color"/>


</LinearLayout>

</LinearLayout>

ReviewCardViewHolder.java

    public class ReviewCardViewHolder extends RatingsReviewViewHolder {
TextView reviewStar, reviewHelpfulCount, reviewHeader, reviewAuthor;
TextView reviewTimeStamp, reviewDesc;
LinearLayout verifiedPurchaseLayout;
RecyclerView imgRecyclerView;
final AppCompatRadioButton yesRadioBtn, noRadioBtn;
TextView reportIssue;

public ReviewCardViewHolder(View itemView) {
super(itemView);
reviewStar = (TextView) itemView.findViewById(R.id.rating_star);
reviewHelpfulCount = (TextView) itemView.findViewById(R.id.review_helpful_count);
reviewHeader = (TextView) itemView.findViewById(R.id.review_header);
reviewAuthor = (TextView) itemView.findViewById(R.id.review_author_name);
reviewTimeStamp = (TextView) itemView.findViewById(R.id.review_time);
reviewDesc = (TextView) itemView.findViewById(R.id.review_description);
verifiedPurchaseLayout = (LinearLayout) itemView.findViewById(R.id.verified_purchase_layout);
imgRecyclerView = (RecyclerView) itemView.findViewById(R.id.review_images_recyclerview);
imgRecyclerView.setHasFixedSize(true);
yesRadioBtn = itemView.findViewById(R.id.yes_radio_btn);
noRadioBtn = (AppCompatRadioButton) itemView.findViewById(R.id.no_radio_btn);
reportIssue = itemView.findViewById(R.id.rr_report_issue);

LinearLayoutManager horizontalLayoutManagaer = new LinearLayoutManager(mContext) {
@Override
public boolean canScrollHorizontally() {
return false;
}

@Override
public void setOrientation(int orientation) {
super.setOrientation(0);
}
};
imgRecyclerView.setLayoutManager(horizontalLayoutManagaer);
}

public void bind(RatingsAndReviewItem item) {
final Review data = (Review) item.getValue();
AttributeRating attributeValue = data.getAttributeRating().get(0);
reviewStar.setText(ratingsAndReviewPresenter.drawOverAllRatingStar(attributeValue.getAttributeValue()));
ratingsAndReviewPresenter.setCustomTextVal(reviewHelpfulCount, mContext.getString(R.string.review_helpful_count), data.getHelpfulCount());
reviewHeader.setText(data.getReviewSummary());

Author author = data.getAuthor();
reviewAuthor.setText("By " + author.getScreenName());
String authCity = "", authState = "";
if (author.getCity() != null && !author.getCity().isEmpty()) {
authCity = author.getCity() + ", ";
}
if (author.getState() != null && !author.getState().isEmpty()) {
authState = author.getState() + " | ";
}
String timeStamp = authCity + authState + data.getPublishedDate();
reviewTimeStamp.setText(timeStamp);
reviewDesc.setText(data.getReviewContent());

if (author.getBuyer()) {
verifiedPurchaseLayout.setVisibility(View.VISIBLE);
} else {
verifiedPurchaseLayout.setVisibility(View.GONE);
}


if (data.getIsReviewHelpful() != null && data.getIsReviewHelpful().equalsIgnoreCase("yes")) {
yesRadioBtn.setChecked(true);
}else{
yesRadioBtn.setChecked(false);
}

if (data.getIsReviewHelpful() != null && data.getIsReviewHelpful().equalsIgnoreCase("no")) {
noRadioBtn.setChecked(true);
}else{
noRadioBtn.setChecked(false);
}

yesRadioBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(((RadioButton)view).isChecked() ) {
data.setIsReviewHelpful("yes");
}
ratingClickInterface.setRatingHelpfulStatus(true,data);
}
});

noRadioBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(((RadioButton)view).isChecked() ) {
data.setIsReviewHelpful("no");
}
ratingClickInterface.setRatingHelpfulStatus(false,data);
}
});


}
}

最佳答案

尝试删除 RadioGroup。 RadioGroup 使这两个单选按钮互斥。

关于android - 单选按钮状态未保留在回收站 View 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48149424/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com