사용자 지정 목록이 있고 각 행에 라디오 그룹이 아닌 이미지, 텍스트보기 및 라디오 버튼이 있습니다. 하나의 라디오 버튼 만 선택합니다. 선택한 라디오 버튼과 같은 행에있는 이미지를 가져오고 싶습니다. 그럼이 이미지로 배경을 설정해주세요. 도와주세요.선택한 라디오 버튼의 같은 행에 이미지를 가져 오는 방법은 무엇입니까?
//rowadapter
public class rowadapter extends ArrayAdapter<String> {
private final Activity context;
int layoutResourceId;
private final String[] web;
private final Integer[] imageId;
int selectedPosition = -1;
SharedPreferences sharedPref;
public rowadapter(Activity context,String[] web, Integer[] imageId) {
super(context,R.layout.item_listview, web);
this.context = context;
this.web = web;
this.imageId = imageId;
sharedPref = context.getSharedPreferences("position",Context.MODE_PRIVATE);
}
public View getView(final int position, View row, ViewGroup parent)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
backgroundholder holder = null;
View rowView=row;
rowView= inflater.inflate(R.layout.item_listview, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
final ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(web[position]);
imageView.setImageResource(imageId[position]);
holder = new backgroundholder();
holder.radiobutton = (RadioButton)rowView.findViewById(R.id.radiobutton);
holder.radiobutton.setChecked(position == selectedPosition);
holder.radiobutton.setTag(position);
int checkedpos=sharedPref.getInt("position",-1);
if(checkedpos==position)
{
holder.radiobutton.setChecked(true);
}
holder.radiobutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view)
{
selectedPosition = (Integer)view.getTag();
RadioButton radio = (RadioButton)view;
if(radio.isChecked())
{
Editor editor=sharedPref.edit();
editor.putInt("position", selectedPosition);
editor.commit();
}
Intent i=new Intent(getContext(), Preferences.class);
context.startActivity(i);
notifyDataSetInvalidated();
}
});
return rowView;
}
static class backgroundholder
{
RadioButton radiobutton;
}
}
//object class
import android.widget.RadioButton;
public class Item {
String txt;
Integer drawable;
RadioButton radiobutton;
boolean checked;
public Item(String txt,Integer drawable,RadioButton radiobutton)
{
this.txt=txt;
this.drawable=drawable;
this.radiobutton=radiobutton;
}
public String gettxt()
{
return txt;
}
public Integer getInteger()
{
return drawable;
}
public boolean ischecked()
{
return checked;
}
public void setchecked(boolean checked)
{
this.checked=checked;
}
}
선형 레이아웃을'horizontal'를 하나에 모두 추가 줄 – Siva
나는 대답을 이해하지 못한다. – user3631823
XML 파일에서 어떤 레이아웃을 사용하고 있습니까? 여기에 xml 파일을 게시하십시오 – Siva