Android PopupWindow RadioGroup RadioButton 的使用

关于PopupWindow已经很多了,在这里不多做介绍了。项目需要做个测试。也没有什么好说明的 ,代码也简单。

package ru.org.piaozhiye; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.Gravity; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.PopupWindow; import android.widget.RadioButton; import android.widget.RadioGroup; public class MainActivity extends Activity { /** Called when the activity is first created. */ private Button popbutton = null; private View popUpView; private PopupWindow controlWin; private RadioGroup radioGroup; private RadioButton speedAdd1; private RadioButton speedSub1; private RadioButton speed15x; private RadioButton speed20x; private RadioButton speedNormal; private String TAG = "MainActivity"; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); popbutton = (Button) findViewById(R.id.popuptest); popUpView = getLayoutInflater().inflate(R.layout.speed, null); controlWin = new PopupWindow(popUpView, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); radioGroup = (RadioGroup) popUpView.findViewById(R.id.speed_groud); speedAdd1 = (RadioButton) popUpView.findViewById(R.id.add1); speedSub1 = (RadioButton) popUpView.findViewById(R.id.sub1); speedNormal = (RadioButton) popUpView.findViewById(R.id.normal); speed15x = (RadioButton) popUpView.findViewById(R.id.speed15); speed20x = (RadioButton) popUpView.findViewById(R.id.speed20); // 值得注意的是 PopupWindow 需要事件来触发,否则会出错,这里就使用 button click 来触发 popbutton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { controlWin.showAtLocation(v, Gravity.BOTTOM, 0, 0); controlWin.update(0, 0, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); } }); radioGroup.setOnCheckedChangeListener(new SpeedGrouplistener()); } class SpeedGrouplistener implements RadioGroup.OnCheckedChangeListener { public void onCheckedChanged(RadioGroup group, int checkedId) { // TODO Auto-generated method stub if (checkedId == speedAdd1.getId()) { speedAdd1.setChecked(true); controlWin.dismiss(); Log.e(TAG, "add1"); } if (checkedId == speedNormal.getId()) { speedNormal.setChecked(true); controlWin.dismiss(); Log.e(TAG, "normal"); } if (checkedId == speed15x.getId()) { speed15x.setChecked(true); controlWin.dismiss(); Log.e(TAG, "speed15"); } if (checkedId == speed20x.getId()) { speed20x.setChecked(true); controlWin.dismiss(); Log.e(TAG, "speed20"); } if (checkedId == speedSub1.getId()) { speedSub1.setChecked(true); controlWin.dismiss(); Log.e(TAG, "sub1"); } } } } 

project :http://download.csdn.net/source/3348276

你可能感兴趣的:(android,String,null,Class,button,RadioButton)