0

I am stuck in a situation where I need to get the ID of checked Radiobutton. I know where the problem is but I can not solve it so Please suggest me on base of my code.

@Override
public View getView(int position, View convertView, ViewGroup parent) {     
    ViewHolder holder=null;

    bean=arrayListCountry.get(position);

    LayoutInflater inflater=(LayoutInflater)context.getSystemService(Service.LAYOUT_INFLATER_SERVICE);
    if(convertView==null)
    {
        convertView=inflater.inflate(R.layout.custom_layout_listview, null);
        holder=new ViewHolder();
        holder.textCountryName=(TextView)convertView.findViewById(R.id.textView1);
        holder.radioCountry=(RadioButton)convertView.findViewById(R.id.radioButton1);
        RelativeLayout relativeLayout=(RelativeLayout)convertView.findViewById(R.id.relativeCustomLayout);
        relativeLayout.addView(convertView);
        convertView.setTag(holder);
        convertView.setTag(R.id.textView1,holder.textCountryName);


    }
    else
        holder=(ViewHolder)convertView.getTag();

    holder.radioCountry.setTag(position);

    holder.textCountryName.setText(bean.getCountryName());
    holder.radioCountry.setChecked(bean.getIsSelected());

    holder.radioCountry.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            // TODO Auto-generated method stub

            int pos=(Integer)buttonView.getTag();

            Country_Bean country_Bean=arrayListCountry.get(pos);


            coubean.setIsSelected(buttonView.isChecked());


            //buttonView.setChecked(bean.getIsSelected());

            Toast.makeText(context, "POs:"+pos+"\ncountry:"+bean.getCountryName()+"\ncountry_check:"+bean.getIsSelected()+"\nbuttonCheck:"+buttonView.isChecked(), Toast.LENGTH_SHORT).show();
        }
    });

    return convertView;
}

Please tell me how can I get the specific radiobutton. I also want to know why getView normally used and how can we manually call that method. Thank you in advanced.

4

2 に答える 2

1

ここに画像の説明を入力してください

私は自分の側からやって、参考のために完全なソースコードをAndroidブログに投稿しました。

http://amitandroid.blogspot.in/2013/03/android-custon-single-choice-lsitview.html

于 2013-03-07T11:19:32.720 に答える
0

RadioGroupを試しましたか?RadioButtonそれは多くのsのためのコンテナです。getCheckedRadioButtonId()というメソッドもあります。


それ以外は、入力規則に従わないようです。私はそれに関して非常に厳格であり、私の中のコード文法-ナチスについて謝罪します。

Beanがメンバー変数の場合は、mBeanを使用します。

bean=arrayListCountry.get(position);

になります:

mBean=arrayListCountry.get(position);

Country_Beanはクラスの固有名ではありません。

Country_Bean

になります:

CountryBean

スコープ変数名country_Beanも間違っています。

country_Bean

になります:

countryBean

また、Eclipseを使用している場合は、自動フォーマットを使用してみてください。コードがよりきれいになります(CTRL + SHIFT + F)。

于 2013-03-07T10:07:24.883 に答える