RadioGroup 多行多列单选问题

xml文件:



    

        

Activity文件:

package com.example.loushi.main;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

import com.example.loushi.R;
import com.example.loushi.base.BaseActivity;
import com.example.loushi.http.PricePaiActivity;

public class PriceAreaActivity extends BaseActivity implements
		OnCheckedChangeListener {

	RadioGroup group1;
	RadioGroup group2;
	RadioGroup group3;
	private Boolean changeGroup = false;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_price_area);

		initViews();
	}

	private void initViews() {
		// TODO Auto-generated method stub
		group1 = (RadioGroup) this.findViewById(R.id.RadioGroup01);
		group2 = (RadioGroup) this.findViewById(R.id.RadioGroup02);
		group3 = (RadioGroup) this.findViewById(R.id.RadioGroup03);
		
		group1.setOnCheckedChangeListener(this);
		group2.setOnCheckedChangeListener(this);
		group3.setOnCheckedChangeListener(this);
	}

	public void onCheckedChanged(RadioGroup group, int checkedId) {
		if (group != null && checkedId > -1 && changeGroup == false) {
			if (group == group1) {
				changeGroup = true;
				group2.clearCheck();
				group3.clearCheck();
				changeGroup = false;
			} else if (group == group2) {
				changeGroup = true;
				group1.clearCheck();
				group3.clearCheck();
				changeGroup = false;
			} else if (group == group3) {
				changeGroup = true;
				group1.clearCheck();
				group2.clearCheck();
				changeGroup = false;
			}
		}
	}

	public void finish(View v) {
		Intent intent = new Intent(PriceAreaActivity.this,
				PricePaiActivity.class)
				.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		// 把一个Activity转换成一个View
		Window w = ShouYeGroupTab.group.getLocalActivityManager()
				.startActivity("PricePaiActivity", intent);
		View view = w.getDecorView();
		// 把View添加大ActivityGroup中

		ShouYeGroupTab.group.setContentView(view);
	}

	public void ok(View v) {
		// Intent intent = new Intent(PriceAreaActivity.this,
		// MainActivity.class)
		// .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		// // 把一个Activity转换成一个View
		// Window w = ShouYeGroupTab.group.getLocalActivityManager()
		// .startActivity("PriceAreaActivity", intent);
		// View view = w.getDecorView();
		// // 把View添加大ActivityGroup中
		//
		// ShouYeGroupTab.group.setContentView(view);

		group2.clearCheck();
		group1.clearCheck();
	}

}


参考:http://zhidao.baidu.com/link?url=rZJYvdWDseMiifCoWYMp6ZRwqgex-W9bcS2-dHAGdqHyBv8GONcBNAa6tMYXTjKJOw4Da3PqdfHlu-xafpAlFK

你可能感兴趣的:(Android)