开发者

Sharing a static button between two Android Activities

开发者 https://www.devze.com 2023-02-04 01:04 出处:网络
Ifcreate a static button in one activityand use in another activity it shows error as 01-12 19:57:17.030: DEBUG/PhoneWindow(21860):

If create a static button in one activity and use in another activity it shows error as

01-12 19:57:17.030: DEBUG/PhoneWindow(21860): couldn't save which view has focus because the focused view com.android.internal.policy.impl.PhoneWindow$DecorView@2f5671b8 has no id.

My code is:

开发者_JAVA百科public static LoginButton bttn;
  findViewById(R.id.login).setOnClickListener(new OnClickListener(){

   public void onClick(View v) {
    // TODO Auto-generated method stub
    bttn = (LoginButton)findViewById(R.id.login);

    startActivity(new Intent(Account.this,Example.class));

   }

  });

In the second activity I use this static button as

Account.bttn.init(this, mFacebook);


After public void onClick(View v), try adding if (v.getId() == R.id.your_button_id). This way, Android knows that the onClick handler relates to your button click.

Update: try

Button bttn = (Button)findViewById(R.id.login);
bttn.setOnClickListener(new OnClickListener(){

    public void onClick(View v) { 
        startActivity(new Intent(Account.this,Example.class));
    }

});

It should be more or less like this. Are you sure there is such thing as a LoginButton ?

0

精彩评论

暂无评论...
验证码 换一张
取 消