我如何在解析android中获得“用户名”

时间:2016-01-04 16:59:00

标签: android parse-platform

final String username = ETsearch.getText().toString();
final ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", username);
query.findInBackground(new FindCallback<ParseUser>() {
    @Override
    public void done(List<ParseUser> objects, com.parse.ParseException e) {
        if (e == null) {
            if (objects.size() > 0) {
                //String usernameCari = objects.get(objects.size()).getUsername();
                //objects.get(1).getUsername();
                Toast.makeText(getApplicationContext(), "Username Found "+objects.toString(),
                        Toast.LENGTH_LONG).show();

            } else {
                Toast.makeText(getApplicationContext(), "Username Not Found",
                        Toast.LENGTH_LONG).show();
            }
        } else {
            Toast.makeText(getApplicationContext(), "EROR",
                    Toast.LENGTH_LONG).show();
        }
    }
});

我怎么能得到一个我搜索它的用户名?所以我可以在之前的mainActivity ty中干它。我被困在这里。 请帮忙

1 个答案:

答案 0 :(得分:0)

使用用户名

获取ParseUser
final ParseQuery<ParseUser> query = ParseUser.getQuery();
query.whereEqualTo("username", username);
query.getFirstInBackground(new GetCallback<ParseUser>() {

    @Override
    public void done(ParseUser parseUser, ParseException e) {
        // TODO Auto-generated method stub
         if (e == null) {
              String userName = parseUser.getUsername();
              String email = parseUser.getEmail();
         } else {
              Toast.makeText(getApplicationContext(), e.getMessage(),
                         Toast.LENGTH_LONG).show();
         }

    }
});