Reputation: 772
this is my adapter, the getView method is not called even if the array list having elements
public class CarrierSammuryAdapter extends ArrayAdapter<CarrierSummary> {
private final Activity context;
private final ArrayList<CarrierSummary> ite;
private final int lay;
public CarrierSammuryAdapter(Activity context, ArrayList<CarrierSummary> menuLinkList,int layout) {
super(context,layout );
this.context = context;
this.ite = menuLinkList;
this.lay=layout;
}
// static to save the reference to the outer class and to avoid access to
// any members of the containing class
static class ViewHolder {
public TextView customer;
public TextView attempts;
public TextView successful;
public TextView minutes;
public TextView ASR;
public TextView ACD;
public TextView NER;
public TextView PDD;
}
@Override
public int getCount () {
return ite.size();
}
@Override
public long getItemId (int position) {
return position;
}
@Override
public CarrierSummary getItem (int position) {
return ite.get(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHolder will buffer the assess to the individual fields of the row layout
final ViewHolder holder;
// Recycle existing view if passed as parameter
// This will save memory and time on Android
// This only works if the base layout for all classes are the same
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = context.getLayoutInflater();//this gives error !!
rowView=inflater.inflate(R.layout.carriersumamry_item,parent,false);
holder = new ViewHolder();
holder.customer=(TextView)rowView.findViewById(R.id.customer);
holder.attempts=(TextView)rowView.findViewById(R.id.attempts);
holder.successful=(TextView)rowView.findViewById(R.id.successful);
holder.minutes=(TextView)rowView.findViewById(R.id.minutes);
holder.ASR=(TextView)rowView.findViewById(R.id.asr);
holder.ACD=(TextView)rowView.findViewById(R.id.acd);
holder.NER=(TextView)rowView.findViewById(R.id.ner);
holder.PDD=(TextView)rowView.findViewById(R.id.pdd);
// ViewResizing.setListRowTextResizing(rowView, context);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
holder.customer.setText(ite.get(position).getCustomer());
holder.attempts.setText(ite.get(position).getAttempts());
holder.successful.setText(ite.get(position).getSuccessful());
holder.minutes.setText(ite.get(position).getMinutes());
holder.ASR.setText(ite.get(position).getASR());
holder.ACD.setText(ite.get(position).getACD());
holder.NER.setText(ite.get(position).getNER());
holder.PDD.setText(ite.get(position).getPDD());
return rowView;
}
}
and this is how i called it
carrierSummaryList =(ListView)findViewById(R.id.carrierSummary_listview);
CarrierSammuryAdapter adapter = new CarrierSammuryAdapter(CarrierSummaryActivity.this, carriersam,R.layout.carriersumamry_item);
carrierSummaryList.setAdapter(adapter);
I search a lot to solve this issue but no solution, getView method is never called.
this is my XML
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/pdd"
android:textColor="@color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ner"
android:textColor="@color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/acd"
android:textColor="@color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/asr"
android:textColor="@color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/minutes"
android:textColor="@color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/successful"
android:textColor="@color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/attempts"
android:textColor="@color/grey"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/customer"
android:textColor="@color/grey"
/>
</LinearLayout>
Upvotes: 1
Views: 814
Reputation: 772
The problem was in my drawerLayout, i put the listView into RelativeLayout but when i change to LinearLayout its working, this is the code
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white"
android:orientation="vertical">
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/mainbar"
layout="@layout/second_topmain"/>
<ListView
android:id="@+id/carrierSummary_listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@android:color/black"
></ListView>
<include
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginBottom="0dp"
android:id="@+id/mainbar"
layout="@layout/bottom_bar"/>
</LinearLayout>
<LinearLayout
android:id="@+id/linearSlider"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="right"
android:background="#7e7e7e"
android:orientation ="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Carrier Type"
android:textColor="@android:color/white"
android:padding="5dp"
android:background="@color/darkgrey"
/>
<LinearLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:background="@color/darkgrey"
android:layout_height="wrap_content">
<Button
android:id="@+id/customerButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/grey"
android:onClick="toggleClicked"
android:background="@drawable/toggleon"
android:text="Customer"
/>
<Button
android:id="@+id/SupplierButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="toggleClicked"
android:textColor="@color/grey"
android:background="@drawable/toggleoff"
android:text="Supplier"
/>
</LinearLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Carrier"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinnerCarrier"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:background="@color/darkgrey"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Top"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/SpinnerTop"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:onClick="showDateTimePickerFrom"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="From Date"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/fromDate"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:background="@color/darkgrey"
android:layout_width="wrap_content"
android:onClick="showDateTimePickeTo"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To Date"
android:layout_alignParentLeft="true"
android:layout_centerHorizontal="true"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/toDate"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
<RelativeLayout
android:padding="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Group By Profile"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/byprofilecheck"
android:layout_alignParentRight="true"
android:background="@android:color/transparent"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
Upvotes: 0
Reputation: 221
there are two mistakes.. first is change Activity to Contex in constructor secondly change
rowView=inflater.inflate(R.layout.single_row,parent,false);
Hope this will help you
Upvotes: 1
Reputation: 1287
/**
* Constructor
*
* @param context The current context.
* @param resource The resource ID for a layout file containing a TextView to use when
* instantiating views.
*/
public ArrayAdapter(Context context, int resource) {
init(context, resource, 0, new ArrayList<T>());
}
while you are doing super(context,layout) , this is the constructor that gets called. So adapter data is set to empty list.
Like derek said, Instead you should use super(context,layout,menuLinkList);
/**
* Constructor
*
* @param context The current context.
* @param resource The resource ID for a layout file containing a TextView to use when
* instantiating views.
* @param objects The objects to represent in the ListView.
*/
public ArrayAdapter(Context context, int resource, List<T> objects) {
init(context, resource, 0, objects);
}
Upvotes: 0
Reputation: 3191
I had this exact same problem, to solve it, I simply changed the ArrayAdapter to BaseAdapter, implemented the overriden methods and it worked.
And as khuskal said, you should always use Context
instead of Activity
.
Upvotes: 2