Android Radio Buttons问题

时间:2011-02-01 12:02:12

标签: android

我正在使用包含一个TextView和一个单选按钮的ListView ..我使用自定义适配器方法来扩充视图..

我每个列表都有一个单选按钮....首先我选择列表1中的单选按钮,然后选择列表2的单选按钮。如果我选​​择列表2的单选按钮,则应禁用以前的选择。我想要选择列表中的单选按钮位置..

我的用户界面将采用这种方式:


列表1:

TextView RadioButton

列表:2

TextView单选按钮

我的代码:

类MultiLine扩展BaseAdapter实现了RadioGroup.OnCheckedChangeListener         {

        LayoutInflater mInflater;       
        String name;
        String TAG = "MultiLine";
        int i = -1;
        int j = -1;
        int k = -1;
        String[] VAL_CardNumber;

        public MultiLine(Context context, String[] value1) {
            try {

                mInflater = LayoutInflater.from(context);
                VAL_CardNumber = value1;


            } catch (Exception e) {
                Log.v(TAG, "dom" + e);
            }

        }

        public int getCount() {

            return VAL_CardNumber.length;
        }

        public Object getItem(int arg0) {
            return arg0;
        }

        public long getItemId(int arg0) {
            return arg0;
        }

    public View getView(int position, View convertView, ViewGroup arg2) {

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.credit_card_list_view,null);
            holder = new ViewHolder();
            holder.text = (TextView) findViewById(R.id.credit_card_listtext);
            //holder.mRadioGroup=(RadioGroup)convertView.findViewById(R.id.menu);

            //holder.icon = (ImageView) convertView.findViewById(R.id.deal_icon);

            convertView.setTag(holder);
        } else {
            holder.text = (TextView) convertView.findViewById(R.id.deal_title);
            //holder.mRadioGroup=(RadioGroup)convertView.findViewById(R.id.menu);
        }


        holder.text.setText(VAL_CardNumber[position]);

        //holder.mRadioGroup.setOnCheckedChangeListener(this);


         iconContextMenu.setOnClickListener(new IconContextMenu.IconContextMenuOnClickListener() {
                @Override
                public void onClick(int menuId) {
                    switch(menuId) {
                    case MENU_ITEM_1_ACTION:

                        Toast.makeText(getApplicationContext(), "You've clicked on menu item 1", 1000).show();
                        credit_card_edit=true;
                        Log.v("Test", "YES BOSS COMING INSIDE A");
                           //startActivity(new Intent(Credit_Card_List.this,Credit_Card_Main.class));
                        break;
                    case MENU_ITEM_2_ACTION:
                        Toast.makeText(getApplicationContext(), "You've clicked on menu item 2", 1000).show();
                        credit_card_delete=true;
                        Log.v("Test", "YES BOSS COMING INSIDE B");
                         // startActivity(new Intent(Credit_Card_List.this,Credit_Card_Main.class));
                        break;
                    case MENU_ITEM_3_ACTION:
                        credit_card_change=true;
                        Log.v("Test", "YES BOSS COMING INSIDE C");
                         // startActivity(new Intent(Credit_Card_List.this,Deal_Purchase_Checkout.class));
                        break;
                    case MENU_ITEM_4_ACTION:

                        break;  

                    }
                }
            });



        return convertView;
    }

    @Override
    public void onCheckedChanged(RadioGroup arg0, int arg1) {
        // TODO Auto-generated method stub

        list_selected_position=arg1;
        credit_card_list.getPositionForView(arg0);
        credit_card_list.getCheckedItemPosition();
        Log.v("test",""+credit_card_list.getSelectedItemPosition());
        Log.v("tes1111",""+credit_card_list.getCheckedItemPosition());

    }




    }

1 个答案:

答案 0 :(得分:1)

从我到现在为止,你应该从this得到你想要的东西。诀窍是为列表设置单击侦听器,该侦听器应检查是否选中了单击行的RadiusButton。我不知道你的XML文件是否正确,但是这个解决方案我指出它有效(抱歉不要放代码,但我也在Android项目的中间,而且很忙)。 / p>