Reputation: 1284
For some reasons getView(int position, View convertView, ViewGroup parent) of my customized ArrayAdapter isn't called and android displays an empty list. I've already Override getCount()
public class CEL_ElementsFromXMLArrayAdapter extends ArrayAdapter<LinkedHashMap<RoomItem, LinkedHashMap<ItemType, List<RoomDamage>>>> {
private Context context;
private int resource;
private List<LinkedHashMap<RoomItem, LinkedHashMap<ItemType, List<RoomDamage>>>> elementsFromXMLList;
public CEL_ElementsFromXMLArrayAdapter(Context context, int resource,
List<LinkedHashMap<RoomItem, LinkedHashMap<ItemType, List<RoomDamage>>>> elementsFromXMLList) {
super(context, resource, elementsFromXMLList);
this.context = context;
this.resource = resource;
this.elementsFromXMLList = elementsFromXMLList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int positionItem = position;
View view;
LayoutInflater viewInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if(convertView != null)
view = convertView;
else
view = viewInflater.inflate(R.layout.etat_piece_item, parent, false);
{...}
return view;
}
@Override
public int getCount() {
return this.elementsFromXMLList.size();
}
And this is how I set Adapter:
CEL_ElementsFromXMLArrayAdapter cel_ElementsFromXMLArrayAdapter = new CEL_ElementsFromXMLArrayAdapter(mContext, R.layout.etat_piece_item, elementsFromXMLLinkedHashMap);
listViewElements.setAdapter(cel_ElementsFromXMLArrayAdapter);
I'm looking for a solution since yesterday, I have read all of the posts on StackOverflow but none match my issue. So I would like to know, if it could come from LinkedHashMap<...>
Edit: this is my layout R.layout.etat_piece_item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mis2_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="1dip"
android:background="@color/white"
android:orientation="horizontal"
android:weightSum="12" >
<ImageView
android:layout_width="@dimen/stroke_dim"
android:layout_height="fill_parent"
android:background="@color/light_line"
android:contentDescription="@string/img" />
<TextView
android:id="@+id/descriptionElement_TextView"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:clickable="true"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:textColor="@color/black1"
android:textSize="@dimen/mis_item_size" />
<ImageView
android:id="@+id/stroke_dim"
android:layout_width="@dimen/stroke_dim"
android:layout_height="fill_parent"
android:background="@color/light_line"
android:contentDescription="@string/img" />
<Spinner
android:id="@+id/typeElement_Spinner"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_weight="2.5"
android:background="@drawable/spinner_ab_default"
android:clickable="true"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:textSize="@dimen/mis_item_size"
android:textStyle="normal" />
<ImageView
android:layout_width="@dimen/stroke_dim"
android:layout_height="fill_parent"
android:background="@color/light_line"
android:contentDescription="@string/img" />
<EditText
android:id="@+id/quantiteElement_EdiText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:inputType="number"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:singleLine="true"
android:textColor="@color/black1"
android:textSize="@dimen/mis_item_size" />
<ImageView
android:layout_width="@dimen/stroke_dim"
android:layout_height="fill_parent"
android:background="@color/light_line"
android:contentDescription="@string/img" />
<TextView
android:id="@+id/etatElement_TextView"
style="@android:style/Widget.Holo.Light.EditText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_marginLeft="3dp"
android:layout_marginRight="3dp"
android:layout_weight="1.5"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:onClick="callChooseEtat"
android:paddingLeft="5dp"
android:paddingTop="10dp"
android:textStyle="normal" />
<ImageView
android:layout_width="@dimen/stroke_dim"
android:layout_height="fill_parent"
android:background="@color/light_line"
android:contentDescription="@string/img" />
<TextView
android:id="@+id/ent_obervations_val"
style="@android:style/Widget.Holo.Light.EditText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="2"
android:clickable="true"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:singleLine="true"
android:textColor="@color/black1"
android:textSize="@dimen/mis_item_size" />
<ImageView
android:layout_width="@dimen/stroke_dim"
android:layout_height="fill_parent"
android:background="@color/light_line"
android:contentDescription="@string/img" />
<LinearLayout
android:id="@+id/imageLayout"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:gravity="center"
android:onClick="callCameraInList" >
<ImageView
android:id="@+id/photoElement_ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical|center_horizontal"
android:contentDescription="@string/img"
android:src="@drawable/photo_img" />
</LinearLayout>
<ImageView
android:layout_width="@dimen/stroke_dim"
android:layout_height="fill_parent"
android:background="@color/light_line"
android:contentDescription="@string/img" />
<EditText
android:id="@+id/trouElement_EditText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:hint="@string/zero"
android:inputType="number"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:singleLine="true"
android:textColor="@color/black1"
android:textSize="@dimen/mis_item_size" />
<ImageView
android:layout_width="@dimen/stroke_dim"
android:layout_height="fill_parent"
android:background="@color/light_line"
android:contentDescription="@string/img" />
<TextView
android:id="@+id/actionElement_TextView"
style="@android:style/Widget.Holo.Light.EditText"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight="1"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp"
android:singleLine="true"
android:textColor="@color/black1"
android:textSize="@dimen/mis_item_size" />
<ImageView
android:layout_width="@dimen/stroke_dim"
android:layout_height="fill_parent"
android:background="@color/light_line"
android:contentDescription="@string/img" />
</LinearLayout>
Upvotes: 0
Views: 212
Reputation: 155
public class CEL_ElementsFromXMLArrayAdapter extends ArrayAdapter<LinkedHashMap<RoomItem, LinkedHashMap<ItemType, List<RoomDamage>>>> {
private Context context;
private int resource;
private List<LinkedHashMap<RoomItem, LinkedHashMap<ItemType, List<RoomDamage>>>> elementsFromXMLList;
public CEL_ElementsFromXMLArrayAdapter(Context context, int resource,
List<LinkedHashMap<RoomItem, LinkedHashMap<ItemType, List<RoomDamage>>>> elementsFromXMLList) {
super(context, resource, elementsFromXMLList);
this.context = context;
this.resource = resource;
this.elementsFromXMLList = elementsFromXMLList;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
final int positionItem = position;
View view = convertView;
View v = (View)LayoutInflater.from(context).inflate(your layout,parent, false);
// this will make a list item from your layout then insert your data into it's child views
return v;
}
@Override
public int getCount() {
return this.elementsFromXMLList.size();
}
Upvotes: 0
Reputation: 543
Did u try to inflate view actually instead of using convert view. Convertview will be not null only when atleast one view is populated inside the array adapter
Upvotes: 0
Reputation:
It's being called, it's only returning a null value. ConvertView is null for the first getView call, so you have to inflate something (even if its not your first position nothing guarantees that it isnt null) and you dont seem to be inflating anything.
Try this:
if(convertView != null)
view = convertView;
else
view = viewInflater.inflate(R.layout.yourlayout, parent, false);
Where R.layout.yourlayout is the layout you want to populate your list with.
Upvotes: 0