当我单击“保存”按钮时,onClick方法无法运行。 这是一个ActivityGroup.I holp,保存按钮可以在sun活动中运行或收听
public class DisasterActivity extends ActivityGroup {
RadioGroup radioGroup;
RadioButton tab_mydisaster;
RadioButton tab_upload;
RadioButton tab_view;
FrameLayout container;
Button save;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.disaster);
initview();
setClick();
container.addView(getLocalActivityManager().startActivity("mydisaster",
new Intent(this, MyDisaster.class)).getDecorView());
}
void initview() {
radioGroup = (RadioGroup) findViewById(R.id.tab);
tab_mydisaster = (RadioButton) findViewById(R.id.tab_mydisaster);
tab_upload = (RadioButton) findViewById(R.id.tab_upload);
tab_view = (RadioButton) findViewById(R.id.tab_view);
container = (FrameLayout) findViewById(R.id.container);
save = (Button) findViewById(R.id.save);
}
void setClick() {
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
LocalActivityManager manager = getLocalActivityManager();
Window window = null;
Intent intent = null;
container.removeAllViews();
switch (checkedId) {
case R.id.tab_mydisaster:
intent = new Intent(DisasterActivity.this, MyDisaster.class);
window = manager.startActivity("mydisaster", intent);
break;
case R.id.tab_upload:
intent = new Intent(DisasterActivity.this, UpLoadImg.class);
window = manager.startActivity("uploadimg", intent);
break;
case R.id.tab_view:
intent = new Intent(DisasterActivity.this,
ViewBriefActivity.class);
window = manager.startActivity("viewbreaf", intent);
break;
}
container.addView(window.getDecorView());
}
});
}
}
ActivityGroup的Button在sun Activity中不起作用。 save.setOnClickListener的onclick meath无法运行..
public class MyDisaster extends Activity{
ActivityGroup parent;
Button save;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.data_manage);
parent=(ActivityGroup)getParent();
save=(Button)parent.findViewById(R.id.save);
save.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(parent, "Test", Toast.LENGTH_SHORT).show();
}
});
}
}
答案 0 :(得分:0)
ActivityGroup已弃用。请考虑放弃您的ActivityGroup实现并改为使用Fragments。你可以通过链接android-support-v4.jar来支持Android设备上的Fragment回到Donut(Android 1.6)。有关详细信息,请参阅http://developer.android.com/guide/topics/fundamentals/fragments.html。