I'm trying to use LayoutInflater in a loop, but each time one of these guys is instantiated, I need to modify at least 2 TextViews found within each instantiation. What i currently have at the moment instantates appropriately and adds the inflated xml view just like I want it to, but the result is that only the first instatiaton's resources are getting modified, and therefore it just gets overwritten many times.
LayoutInflater inflater;
TextView eTitle;
for(String[] episode : episodes) {
//Log.d("Episodes", episode[0] + " / " + episode[2]);
inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.episode_list_item, listView);
eTitle = (TextView) findViewById(R.id.episode_list_item_title);
eTitle.setText(episode[2]);
}
Example output of my list:
where its supposed to look like this:
what do i need to do to ensure that im getting the corresponding unique textview id's from my inflated layouts?
Why don't you use ListView instead?
LayoutInflater inflater = inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
for(String[] episode : episodes) {
View view = inflater.inflate(R.layout.episode_list_item, null);
mTitle = (TextView) view.findViewById(R.id.episode_list_item_title);
mTitle.setText(episode[2]);
listView.addView(view);
}
I am assuming you have a few TextView
s in your LinearLayout
. One point is they can't have the same id
s. So suppose you have 4 TextView
, then give each different id
s, say tv1
, tv2
etc.
Now in your onCreate
method, initialize all these textViews as:
myTextView1= (TextView)findViewByid(R.id.tv1);
etc etc...
In the function where you get the "episodes" try this:
`myTextView1.setText(episodes[0]);
myTextView2.setText(episodes[1]);
You don't have to use any inflater
because its already there in the activities layout
file, which is automatically done in onCreate
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With