アプリケーションを実行すると、ログイン アクティビティは初回と次回に 1 回だけ発生し、ログイン アクティビティのボタン クリックに基づいて 2 つの異なるアクティビティを開く必要があります。ログイン アクティビティでは、次に開いたときに最初のラジオ ボタンを有効にすると、メイン 2 レイアウトが表示され、2 番目のラジオ ボタンを有効にすると、メイン 3 レイアウトが表示されます。
public class Demo1 extends Activity {
Button b1,b2;
int count=0;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences settings = this.getSharedPreferences("MyApp",0);
boolean firstrun=settings.getBoolean("firstrun",true);
if (firstrun) {
SharedPreferences.Editor e = settings.edit();
e.putBoolean("firstrun",false);
e.commit();
setContentView(R.layout.main1);
}
else{
test();
}
b1=(Button)findViewById(R.id.button1);
b2=(Button)findViewById(R.id.button2);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
count=1;
Intent intent = new Intent(Demo1.this, ButtonActivate1.class);
startActivity(intent);
}
});
b2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
count=2;
// TODO Auto-generated method stub
Intent intent = new Intent(Demo1.this, ButtonActivate1.class);
startActivity(intent);
}
});
}
private void test() {
// TODO Auto-generated method stub
if(count==1)
{
setContentView(R.layout.main2);
}
if(count==2)
{
setContentView(R.layout.main3);
}
}
}
この例では、実行中に強制的に閉じられ、行 button.setonclicklistner.please にエラーが表示されます。この問題を解決する方法を教えてください。