在我的活动中,我有viewstub来调用recycleview和recycleview中的其他布局我需要将skor从单选按钮插入到主要活动中
像这样
如果我在主布局中选择单选按钮 skor 增加
这个我的绑定我只使用文本,因为我不知道发送 skor
package com.sariazhariyah.eassessmentinteraktif;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
public class sikapadapter extends RecyclerView.Adapter<sikapadapter.ViewHolder> {
String option[];
public sikapadapter(String[] option) {
this.option = option;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
View view = inflater.inflate(R.layout.recycleview_sikap_layout,parent,false);
sikapadapter.ViewHolder aadvh = new sikapadapter.ViewHolder(view);
return aadvh;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
holder.text.setText(option[position]);
int Radioid = holder.radio.getCheckedRadioButtonId();
}
@Override
public int getItemCount() {
return option.length;
}
public class ViewHolder extends RecyclerView.ViewHolder{
TextView text;
RadioGroup radio;
public ViewHolder(@NonNull View itemView) {
super(itemView);
text = itemView.findViewById(R.id.recytexttampil);
radio = itemView.findViewById(R.id.radiogroup);
}
}
}
这是我使用viewstub的main_activity
String s1[];
s1 = getResources().getStringArray(R.array.option);
ViewStub viewStub = (ViewStub) findViewById(R.id.stub);
//call layout where contain recycleview
viewStub.setLayoutResource(R.layout.penilaian_sikap_layout);
View inflatedView = viewStub.inflate();
recycle = (RecyclerView) inflatedView.findViewById(R.id.recyclesikap);
recycle.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recycle.setLayoutManager(layoutManager);
mAdapter = new sikapadapter(s1);
recycle.setAdapter(mAdapter);