Reputation: 326
In ScrollView I have a LinearLayout. Inside this LinearLayout I can't add view with index.
Why?
example:
RelativeLayout relativeLayout = (RelativeLayout) getLayoutInflater().inflate(R.layout.android_messenger_sent_message, null);
TextView inbox_message = (TextView)relativeLayout.findViewById(R.id.sentMessage);
inbox_message.setText(conversationInfo.getBody()+" "+conversationInfo.getId());
linearLayoutGlobal.addView(relativeLayout,i);
where i
is an integer from 1 000 000 and it is getting smaller
Upvotes: 1
Views: 1781
Reputation: 16790
You cannot add to position 1 000 000 if there are no views. :) Try to use addView(relativeLayout)
instead of the indexed version.
If you need to add in reverse order, then use addView(relativeLayout, 0)
. This will keep on inserting on the head of the list, thus, tossing the aready added views behind.
Note: adding 1M views to a single scroll view will surely fail because you run out of resources. Try with a lower number or change to ListView
.
Upvotes: 3