首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在回收器视图中获取多个搜索栏的进度

在回收器视图中获取多个搜索栏的进度
EN

Stack Overflow用户
提问于 2019-01-03 00:22:57
回答 1查看 381关注 0票数 0

因此,我正在显示一个带有图像和人名的recylerview。下面是一个搜索栏,用户可以移动它来对该人进行评分。

现在我想将每个搜索栏的评分(=进度)存储在一个列表中。然而,现在它只存储列表中最后一个搜索栏的评分。

所以它现在只存储最后一个搜索栏的进度。我希望当用户点击按钮时,每个搜索栏的当前评级值都存储在一个列表中。非常感谢。

这就是我的layout_listitem:

代码语言:javascript
复制
<?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:padding="3dp"
    android:id="@+id/parent_layoutREC"
    android:orientation="horizontal"
    android:layout_marginTop="13dp"
    android:gravity="center">

    <de.hdodenhof.circleimageview.CircleImageView
        android:paddingTop="2dp"
        android:paddingLeft="2dp"
        android:layout_width="73dp"
        android:layout_height="73dp"
        android:id="@+id/kunde_imageREC"
        android:src="@mipmap/ic_launcher"/>

    <TextView
        android:layout_marginLeft="40dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Canada"
        android:id="@+id/kunde_nameREC"
        android:textColor="#000"
        android:textSize="19sp"
        android:textStyle="bold"/>

</LinearLayout>



    <SeekBar
        android:layout_marginRight="35dp"
        android:layout_marginLeft="35dp"
        android:layout_marginTop="8dp"
        android:id="@+id/seek_Bar"
        android:max="10"
        android:progress="5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
<TextView
    android:gravity="center"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="0          1          2          3          4          5"
    android:textSize="20sp"/>

这是我的RecyclerViewAdapter类:

代码语言:javascript
复制
public class RecyclerViewAdap extends 
RecyclerView.Adapter<RecyclerViewAdap.ViewHolder> {
private static final String TAG = "RecyclerViewAdap";
private ArrayList<String> mImageUrl = new ArrayList<>();
private ArrayList<String> mKundeNamen = new ArrayList<>();
public ArrayList<Integer> mBewertungen = new ArrayList<>();
private Context mContext;
public String bewertung;
private TextView progressSeekbar;

public RecyclerViewAdap(ArrayList<String> imageUrl, ArrayList<String> kundeNamen, Context context) {
    mImageUrl = imageUrl;
    mKundeNamen = kundeNamen;
    mContext = context;
}

public class ViewHolder extends RecyclerView.ViewHolder {

    CircleImageView imageView;
    TextView kundeName;
    LinearLayout parentLayout;
    SeekBar seekBar1;

    public ViewHolder(@NonNull View itemView) {
        super(itemView);
        imageView = itemView.findViewById(R.id.kunde_imageREC);
        kundeName = itemView.findViewById(R.id.kunde_nameREC);
        parentLayout = itemView.findViewById(R.id.parent_layoutREC);

        seekBar1 = itemView.findViewById(R.id.seek_Bar);
        progressSeekbar = itemView.findViewById(R.id.progress_seekbar);

        seekBar1.setOnSeekBarChangeListener(seekBarChangeListener);
        //int progress = seekBar1.getProgress();
        //String.valueOf(Math.abs((long)progress)).charAt(0);
        //progressSeekbar.setText("Bewertung: " +
        //        String.valueOf(Math.abs((long)progress)).charAt(0) + "." + String.valueOf(Math.abs((long)progress)).charAt(1));

    }
}

@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_listitem, parent, false);
    ViewHolder holder = new ViewHolder(view);
    Log.d(TAG, "onCreateViewHolder: ");
    return holder;
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
    Glide.with(mContext)
            .load(mImageUrl.get(position))
            .into(holder.imageView);
    holder.kundeName.setText(mKundeNamen.get(position));
    holder.parentLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(mContext, mKundeNamen.get(position), 
Toast.LENGTH_SHORT).show();
        }
    });
    holder.seekBar1.setTag(position);
}

@Override
public int getItemCount() {
    return mImageUrl.size();
}


SeekBar.OnSeekBarChangeListener seekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {

    @Override
    public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        // updated continuously as the user slides the thumb

        progressSeekbar.setText(String.valueOf(progress));


    }


    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
        // called when the user first touches the SeekBar
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        // called after the user finishes moving the SeekBar
        if (seekBar.getTag().toString().equals("1")) {
            mBewertungen.add(seekBar.getProgress());
            if (mBewertungen.size() == 2) {
                mBewertungen.remove(0);
                Toast.makeText(mContext, "onProgressChanged: " + mBewertungen.toString(), Toast.LENGTH_SHORT).show();
            }
        }
        if (seekBar.getTag().toString().equals("2")) {
            mBewertungen.add(seekBar.getProgress());
            if (mBewertungen.size() == 3) {
                mBewertungen.remove(1);
                Toast.makeText(mContext, "onProgressChanged: " + mBewertungen.toString(), Toast.LENGTH_SHORT).show();
            }
        }
    }
};

}

这是显示Recyclerview的活动:

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
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"
tools:context=".BewertungEsserActvity"
android:orientation="vertical"
app:layoutManager="LinearLayoutManager"
android:background="@drawable/gradient_background">

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

    <include
        android:id="@+id/toolbar"
        layout="@layout/toolbar" />

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="14dp"
        android:text="Bewerte deine Gäste"
        android:textColor="@color/colorDarkGrey"
        android:textSize="30sp"
        android:textStyle="bold" />

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/colorBlack"
        android:layout_marginBottom="10dp"/>

    <androidx.recyclerview.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/recycler_view">
    </androidx.recyclerview.widget.RecyclerView>

    <ProgressBar
        android:visibility="invisible"
        android:id="@+id/progressbar_4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="13dp" />
    <Button
        android:layout_marginRight="66dp"
        android:layout_marginLeft="66dp"
        android:id="@+id/bewerten_Btn"
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:layout_marginTop="10dp"
        android:background="@drawable/btn_background_profil"
        android:padding="10dp"
        android:text="Bewerten"
        android:textAllCaps="false"
        android:textColor="@color/colorWhite"
        android:textSize="16sp"
        android:textStyle="normal" />

    <View
        android:layout_marginBottom="10dp"
        android:layout_marginTop="34dp"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/colorBlack" />

</LinearLayout>

</ScrollView>

EN

回答 1

Stack Overflow用户

发布于 2019-01-03 03:51:56

您可以通过多种方式完成此操作:

1-你可以将搜索条的值作为属性存储在你的模型中,并在OnSeekBarChangeListener上更新该属性,当用户点击按钮时,从适配器获取数据源,然后在其上运行一个循环,并调用该属性的getter。

2-你可以在你的适配器中以List<>的形式存储搜索栏的值,每当用户点击这个按钮时,它就会从适配器中获取列表。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54009745

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档