当我运行的应用程序,登录活动应该只来一次第一次和下次,当我打开两个不同的活动应该来基于点击“登录活动”按钮。 在登录活动中,我保留了两个单选按钮,如果我下次启用第一个单选按钮时应该显示main2布局,如果我启用了第二个单选按钮,它应该显示main3布局。如何获得登录活动只有一次,当我跑第一次,下次不同活动应该
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错误这个例子表明我如何来解决这个问题。
什么错误? – 5hssba 2012-04-27 07:48:29
空指针异常 – user1083266 2012-04-27 07:52:53