Я показываю список с помощью адаптера массива. для каждого элемента списка я надуваю один и тот же файл xml. Я могу отображать список в порядке. Но теперь у меня есть другое требование. Я хочу программно добавить еще несколько представлений в тот же XML-файл, который я раздуваю для каждого элемента списка. но когда я пытаюсь это сделать, я не получаю никаких ошибок. но каким-то образом вид, который я добавил программно, не отображается... может ли кто-нибудь помочь мне. ниже приведен код макета xml и адаптера массива
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/placeholder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/listitemcolor"
android:padding="10dip">
<LinearLayout
android:layout_weight="1.0"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:textColor="@android:color/black"
android:id="@+id/locationitem_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textSize="16dp"
android:textStyle="bold" />
<LinearLayout
android:layout_marginTop="5dip"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:drawableLeft="@drawable/like"
android:textColor="#008000"
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Likes"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:textColor="#008000"
android:layout_marginLeft="5dip"
android:id="@+id/number_of_likes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="15"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:drawableLeft="@drawable/dislike"
android:textColor="#FF0000"
android:layout_marginLeft="10dip"
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dislikes"
android:textSize="12dp"
android:textStyle="bold" />
<TextView
android:textColor="#FF0000"
android:layout_marginLeft="5dip"
android:id="@+id/number_of_dislikes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="8"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
This is the code for arrayadapter:
public class LocationItemAdapter extends ArrayAdapter<LocationItem> {
private Context context;
private ArrayList<LocationItem> items;
public LocationItemAdapter(Context context,
List<LocationItem> objects) {
super(context, R.layout.locationitem_listview_element, objects);
this.context = context;
items = (ArrayList<LocationItem>) objects;
}
/* (non-Javadoc)
* @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowview = null;
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowview = inflater.inflate(R.layout.locationitem_listview_element, null);
}
else
{
rowview = convertView;
}
((TextView)rowview.findViewById(R.id.locationitem_name)).setText(items.get(position).getName());
((TextView)rowview.findViewById(R.id.number_of_likes)).setText(String.valueOf(items.get(position).getLikes()));
((TextView)rowview.findViewById(R.id.number_of_dislikes)).setText(String.valueOf(items.get(position).getDislikes()));
LayoutInflater inflater1 = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
TextView tv = new TextView(context);
//TextView tv = (TextView)inflater1.inflate(R.layout.sample, null);
tv.setText("My name is blah");
tv.setTextColor(R.color.black);
tv.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
//tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
LinearLayout ll = (LinearLayout)rowview.findViewById(R.id.placeholder);
//((LinearLayout)rowview.findViewById(R.id.placeholder)).addView(tv);
ll.addView(tv);
rowview.setTag(items.get(position));
return rowview;
}
}