Reputation: 163
I've got a simple function that takes a JSONObject and, extracting the relevant data from the object, creates a new view, adding it to an existing linear layout. The code is as follows:
private void createFriendFilter(JSONObject j) {
final int size = 40;
try{
String name = j.getString("DISPLAY_NAME");
String fPic = j.getString("PROFILE_PIC");
BitmapDrawable bmd = ImageUtil.decode(fPic, size);
LayoutInflater i = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
CheckedTextView c = (CheckedTextView)i.inflate(R.layout.friend, null);
c.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, 50));
c.setText(name);
c.setCompoundDrawables(bmd, null, null, null);
c.setCompoundDrawablePadding(10);
friendsContainer.addView(c);
Log.i(TAG, "Friend Filter Created..."+name);
}catch (Exception e) {
Log.i(TAG, "Error Creating Friend Filter...");
}
}
I call this function from a for-loop, iterating through each JSONObject in a JSONArray. Basically what it does is creates a "friend filter" for each friend in the array. This is the problem: The new view is successfully added to the Linear Layout (friendsContainer) for the first friend, but fails to add any other friends to the Linear Layout. However, I know that the new view is supposed to have been added even when its not showing up because my Log indicates that the filter has been successfully created for that friend. To summarize, this function adds the first friend to the layout, but I cannot see any others. Any thoughts would be much appreciated. Thanks!
Upvotes: 0
Views: 951
Reputation: 87064
Maybe you have the friendsContainer LinearLayout
set to orientation horizontal (horizontal is the default value for orientation) and your TextView
have width set to fill_parent
, so your first TextView
fills the hole width of the LinearLayout
and pushes the other TextView
out of the screen.
Upvotes: 1
Reputation: 224
Did you check the hierarchy viewer to be sure it's not a layout problem?
(Sorry can't comment on your post, so I had to answer)
Upvotes: 0