2017-06-27 36 views
-1

有人可以给我一个建议,我怎么才能得到一个标题。因为我得到所有的标题,我不能选择一个。这是我的代码:翻新1.9获取标题

LoginService loginService = 
     RetrofitClient.createService(LoginService.class, userEmail, userPassword); 
      loginService.basicLogin(new Callback<User>() 

{ 
    @Override 
    public void success (User user, Response response){ 

    List<retrofit.client.Header> tokens = response.getHeaders(); 

    Log.e(LOG_TAG, "x-auth-token is" + xAuthToken)); 

    Toast.makeText(getApplicationContext(), "Your are in", Toast.LENGTH_SHORT).show(); 
    Intent intent = new Intent(getApplicationContext(), BetweenActivity.class); 
    startActivity(intent); 
} 
+0

如何迭代'tokens'列表来查找必要的元素? –

+0

感谢您的咨询! :) –

回答

0

如果你想使用的第一个标记,你可以使用:

retrofit.client.Header firstToken; 
if (tokens.size() > 0) { 
    firstToken = tokens.get(0); 
} 

如果你想通过标记来迭代找到特定的一个,你可以使用:

retrofit.client.Header token = null; 
for (retrofit.client.Header tmpToken : tokens) { 
    if (tmpToken.foo()) { 
     token = tmpToken; 
     break; 
    } 
} 
+0

谢谢你帮助我:)我不知道,那简单就是。 –

+0

@BartoszBunzlau你能接受这个答案,如果它解决了你的问题;-) –

+0

我不能acctept这个答案,因为我没有足够的声誉。当我得到足够的分数时,我会接受!非常感谢 –