I am requesting user information (first name, last name):

VKRequest username = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS,"first_name,last_name")); 

And how can I display the received answer in TextView ?

Help please, I'm still new to programming and on stackoverflow for the first time :)

  • Clarify what the problem is? You do not know how to insert the resulting line in TextView or how to get this very line? - Kirill Stoianov
  • @KirillStoianov; How to insert the resulting string into a TextView. - Tural Walker
  • myTextView.setText ("yourString"); - Kirill Stoianov
  • @KirillStoianov, no, it’s not quite that, I have a String, and the contents of this string should be replaced with the response received. - Tural Walker

4 answers 4

If I understand correctly, then you make a request for users, that is, a list of users comes to your VKRequest username , I suppose something similar to this:

 response: [{ id: 210700286, first_name: 'Lindsey', last_name: 'Stirling', city: { id: 5331, title: 'Los Angeles' }, photo_50: 'https://pp.vk.me/...f6e/4-funfNRMwg.jpg', verified: 1 }] 

Maybe your request should look like this.

 final VKRequest request = VKApi.users().get(VKParameters.from(VKApiConst.FIELDS, "first_name,last_name")); request.executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { VKApiUserFull user = ((VKList<VKApiUserFull>)response.parsedModel).get(0); //устанавливаем имя пользователя в TextView yourTextView.setText(user.first_name); } }); 
  • Thank you more!) Understood, it all worked)) - Tural Walker

From Request username, you need to get in String first_name and last_name then pass them to TextView

 //находите textView TextView textView = (TextView) findViewById(R.id.colorText); //устанавливаете нужный текст textView.setText("Ваши string first_name и last_name"); 
  • And how to get in String first_name and last_name? - Tural Walker
 TextView tvUserName = (TextView) findViewById(R.id.tvUserName); tvUserName.setText("имя пользователя"); 

    In my application, I get the data as follows:

      private void getMeInfo() { VKApi.users().get().executeWithListener(new VKRequest.VKRequestListener() { @Override public void onComplete(VKResponse response) { try { JSONObject r = response.json.getJSONArray("response").getJSONObject(0); Intent intent = new Intent(); intent.putExtra("provider", "vkontakte"); intent.putExtra("access_token", access_token.accessToken); intent.putExtra("uid", r.getString("id")); intent.putExtra("email", ""); intent.putExtra("first_name", r.getString("first_name")); intent.putExtra("last_name", r.getString("last_name")); setResult(RESULT_OK, intent); } catch (JSONException ignored) { } finish(); } @Override public void onProgress(VKRequest.VKProgressType progressType, long bytesLoaded, long bytesTotal) { super.onProgress(progressType, bytesLoaded, bytesTotal); } @Override public void onError(VKError error) { new AlertDialog.Builder(VkontakteActivity.this).setMessage(error.errorMessage).show(); } @Override public void attemptFailed(VKRequest request, int attemptNumber, int totalAttempts) { } }); }