我有一项活动,可以通过Facebook登录。登录后我想加载另一个基本上只有布局的活动。我想首先测试这个过程,如果成功继续。但是当我按下按钮时没有任何反应。知道我在这里做错了吗?活动也在清单中声明。
此LoginActivity
public class LoginActivity extends Activity implements View.OnClickListener {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_layout);
button = (Button)findViewById(R.id.loginButton);
button.setOnClickListener(this);
updateImageButton();
}
private void updateImageButton() {
if(fb.isSessionValid()){
}else{
}
}
@Override
public void onClick(View view) {
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to;2 the /me API
Request.executeMeRequestAsync(session, new Request.
GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
//TextView welcome = (TextView) findViewById(R.id.welcome);
//welcome.setText("Hello " + user.getName() + "!");
Toast.makeText(getApplicationContext(), "welcome", Toast.LENGTH_LONG).show();
Intent i = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(i);
}
}
});
}
}
});
}
}
这是HomeActivity
public class HomeActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home_layout);
}
}
答案 0 :(得分:0)
也许你的OnClickListener
没有被称为合适。请尝试以下方法:
首先进行以下更改:
public class LoginActivity extends Activity implements OnClickListener {
...
button = (Button)findViewById(R.id.loginButton);
button.setOnClickListener(this);
updateImageButton();
...
}
第二次调用onClick就像这样:
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.loginButton:
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
// make request to;2 the /me API
Request.executeMeRequestAsync(session, new Request.
GraphUserCallback() {
// callback after Graph API response with user object
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
//TextView welcome = (TextView) findViewById(R.id.welcome);
//welcome.setText("Hello " + user.getName() + "!");
Toast.makeText(getApplicationContext(), "welcome", Toast.LENGTH_LONG).show();
Intent i = new Intent(LoginActivity.this, HomeActivity.class);
startActivity(i);
}
}
});
}
break;
default:
break;
}
}