我还没有问题。现在我想知道如何通过单选按钮选择所选数据并在下一个活动中显示它。我通过 ArrayAdapter 接口从数据库中获取数据。此外,我还通过 CustomAdapter 类添加了单选按钮和 textView 作为扩展 ArrayAdapter 创建(getView)方法,并在ListView活动中创建其对象。请帮帮我。
public class CustomAdapter extends ArrayAdapter<String> {
RadioGroup radioGroup;
RadioButton radioButton;
LayoutInflater inflater;
TextView text_name;
View customview;
int selectedId;
//Context context;
public CustomAdapter(@NonNull Context context, ArrayList<String> data) {
super(context,R.layout.customadapter,data);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
try {
inflater = LayoutInflater.from(getContext());
customview = inflater.inflate(R.layout.customadapter, parent, false);
//by this above two lines and constructor we can add custom layout to listview
final String show = getItem(position);
text_name = (TextView) customview.findViewById(R.id.textView);
text_name.setText(show);
//object of radio button
radioGroup=(RadioGroup)customview.findViewById(R.id.radiogrp);
selectedId=radioGroup.getCheckedRadioButtonId();
radioButton=(RadioButton)customview.findViewById(selectedId);
customview.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
switch (selectedId){
case R.id.rAbsent:
Toast.makeText(getContext(),"absent",Toast.LENGTH_SHORT).show();
}
}
});
return customview;
}catch (Exception e){
Toast.makeText(getContext(),"error:"+e,Toast.LENGTH_LONG).show();
}
return convertView;
}