当我单击保存按钮时,onClick方法无法运行。这是一个ActivityGroup。我希望保存按钮可以在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的按钮在sun活动中不起作用。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();
}
});
}
}
ActivityGroup已弃用。请考虑放弃ActivityGroup实现,转而使用Fragments。您可以通过链接Android-support-v4.jar来支持Android设备上的碎片返回Donut(Android 1.6)。有关更多信息,请参阅http://developer.android.com/guide/topics/fundamentals/fragments.html.