1
I get a array with items of interest and I must set them on setText
of a particular TextView
.
I want all the items in this array to appear on the screen, horizontally. In my layout xml, I only put 1 textView to receive all the items that come in this array.
My question, do I have to mount a Listview, horizontally, to receive this array and present it on the screen? Or, I can just take the items and put them in the setText property of this Textview?
Follows the code:
@BindView(R.id.txtInterests)
TextView txt_interests;
CommunityPresenter presenter;
UserCommunity selectedUser;
List<String> interest = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setEnterTransition(new Fade());
}
setContentView(R.layout.activity_ride_request);
ButterKnife.bind(this);
presenter = new CommunityPresenter(this);
first.setText(presenter.getDay(0));
second.setText(presenter.getDay(1));
third.setText(presenter.getDay(2));
user = new SessionManager();
selectedUser = CommunityService.i(getContext()).selectedUser;
reloadView();
send_offer_request.setOnClickListener(presenter.sendRequestOnClickListener(0));
send_ask_request.setOnClickListener(presenter.sendRequestOnClickListener(1));
populateInterests();
}
private void populateInterests() {
RequestManager.UsersInterests(selectedUser.id, new FutureCallback<String>() {
@Override
public void onCompleted(Exception e, String result) {
//array com os interesses
interest = new Gson().fromJson(new JsonParser().parse(result).getAsJsonObject().get("data").toString(), new TypeToken<ArrayList<String>>() {
}.getType());
txt_interests.setText(); //preencher o TextView com os interesses
}
});
}
Hello Henrique, it is easier to give you a concrete answer if you edit your question and explain what exactly you want to appear in
txt_interests
. If it can be anything (in any format) the answer can be simplytxt_interests.setText(interest.toString());
(that will display something like[Interesse1, Interesse2, Interesse3]
).– Anthony Accioly
I did, but that’s pretty much what was in the question anyway. I wonder how it can be done so that it is presented as text on the screen, when receiving this array with the items.
– Henrique
Oi Henrique, see if the suggestion in the comment above resolves (I think that’s what Victor meant in his reply too). Of course visually a List View with an item for each interest is quite different from a Text View with all interests concatenated into a single String, but what is best depends on the application. Or your question is another?
– Anthony Accioly
@Anthonyaccioly would be a part of the question of logic, solved by "toString" and which would be better. But I managed to understand here. You can put as answer that mark. Thank you very much!
– Henrique
Hi @Henrique, no problem. I think the current answers are already dealing with what I would write, so feel free to accept the one that best fits your problem (assuming it is solved)
– Anthony Accioly