我正在使用Android facebook集成。我试图将用户名插入本地数据库。我无法在if循环之外获取用户名...如何获取函数外的字符串值.....
这是我的代码......
Session.openActiveSession(getActivity(), true, new Session.StatusCallback()
{
@Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()){
Request.executeMeRequestAsync(session,new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
if (user != null){
t=(TextView)rootView.findViewById(R.id.textView2);
p = (ProfilePictureView)rootView.findViewById(R.id.profilePictureView1);
p.setProfileId(user.getId());
s=user.getName();
Toast.makeText(getActivity(),""+s,Toast.LENGTH_LONG).show();
t.setText(s);
s1=user.getId();
}
}
});
}
}
});
if (cursor.getCount() > 0) {
while (cursor.moveToNext()) {
String contact_id = cursor.getString(cursor.getColumnIndex( _ID ));
String name = cursor.getString(cursor.getColumnIndex( DISPLAY_NAME ));
int hasPhoneNumber = Integer.parseInt(cursor.getString(cursor.getColumnIndex( HAS_PHONE_NUMBER )));
output.append("\n First Name:" + name);
Toast.makeText(getActivity(),""+name,Toast.LENGTH_LONG).show();
Cursor phoneCursor = contentResolver.query(PhoneCONTENT_URI, null, Phone_CONTACT_ID + " = ?", new String[] { contact_id }, null);
while (phoneCursor.moveToNext()) {
phoneNumber = phoneCursor.getString(phoneCursor.getColumnIndex(NUMBER));
output.append("\n Phone number:" + phoneNumber);
Toast.makeText(getActivity(),""+name+""+phoneNumber,Toast.LENGTH_LONG).show();
//String s1=t.getText().toString();
//s=user.getName();
//String s1=user.getId();
//HashMap<String, String>queryValues = new HashMap<String, String>();
//queryValues.put("user",s.toString());
//String s3=phoneNumber.toString();
//String s8;
//s8=t.getText().toString();
Toast.makeText(getActivity(),"in contacts"+s,Toast.LENGTH_LONG).show();
//queryValues.put("uid",s1.toString());
// queryValues.put("contact",s3.toString());
//db.insertuser(queryValues);
}
}
}