Custom Adapter getView() method is not called

Here is the code of the fragment in which I am setting a custom adapter to the list. There no errors but the list view is empty. I have implemented getCount() which returns right number of items in my arraylist. I am stuck badly please help.I dont see ("Inside", "GetView") in the logcat


public class ServiceCarListFragment extends Fragment {

private String url;
private ArrayList<CarDetail> carDetailList = new ArrayList<CarDetail>();
private CarListAdapter adapter;
private ListView mList ;

public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    url = getActivity().getIntent().getStringExtra("url");
    new DownloadCarDetail().execute(url);


public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View v = inflater.inflate(R.layout.fragment_service_car_list, container,false);
    mList = (ListView)v.findViewById(;

    for (CarDetail car : carDetailList) {
    return v;

class DownloadCarDetail extends AsyncTask<String, String, ArrayList<CarDetail>>{

    protected ArrayList<CarDetail> doInBackground(String... params) {
        // TODO Auto-generated method stub
        ArrayList<CarDetail> carDetailList = JsonParser.parseJson(params[0]);
        return carDetailList;

    protected void onPostExecute(ArrayList<CarDetail> carDetailList) {
        // TODO Auto-generated method stub
        ServiceCarListFragment.this.carDetailList = carDetailList;
        Log.d("dccs", String.valueOf(ServiceCarListFragment.this.carDetailList.size()));
        adapter = new CarListAdapter(getActivity(),ServiceCarListFragment.this.carDetailList);
        Log.d("dccs", String.valueOf((adapter.getCount())));



public class CarListAdapter extends BaseAdapter {

private ArrayList<CarDetail> items = new ArrayList<CarDetail>();
private Context context;

public CarListAdapter(Context context , ArrayList<CarDetail> items) {

    this.context = context;
    this.items = items;


public int getCount() {
    // TODO Auto-generated method stub
    return items.size();

public Object getItem(int position) {
    // TODO Auto-generated method stub
    return items.get(position);

public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;

public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    Log.d("Inside", "GetView");
    LayoutInflater mInflater = (LayoutInflater)context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    ViewHolder holder = null;
    CarDetail car = items.get(position);

     if (convertView == null) {
            convertView = mInflater.inflate(R.layout.car_list_row, null);
            holder = new ViewHolder();
            holder.tvCarName = (TextView) convertView.findViewById(;
            holder.tvDailyPriceValue = (TextView) convertView.findViewById(;
            holder.tvWeeklyPriceValue = (TextView) convertView.findViewById(;
            holder.imgCar = (ImageView) convertView.findViewById(;
     else {
            holder = (ViewHolder) convertView.getTag();

        if (car.getImage() != null) {
        } else {
                // MY DEFAULT IMAGE

  return convertView;

static class ViewHolder {

            TextView tvCarName;
            TextView tvDailyPriceValue;
            TextView tvWeeklyPriceValue;
            ImageView imgCar;



the only reasons getView is not called are:

  1. getCount returns 0
  2. you forget to call setListAdapter on the ListView.
  3. If the ListView's visibility (or its container's visibility) is GONE. Thanks to @Tayn√£Bonaldo for the valuable input
  4. ListView is not attached to any viewport layout. That is, mListView = new ListView(...) is used without myLayout.addView(mListView)

In the onPostExcute, after you create a new instance of CarListAdapter I will suggest you to update the new instance to your ListView. Indeed you need to call again


Edit: setAdapter should be always called on the ui thread, to avoid unexpected behaviours

Edit2: you are using the new RecyclerView, make sure that the getItemCount in your Adapter's subclass is returning the size of the dataset, and not an hard-coded 0

Need Your Help

WebRTC: Determine which TURN server is used in PeerConnection

javascript webrtc turn

Scenario: You would like to know if TURN server is being used for a particular call and which one from the array of TURN servers you provided during PeerConnection creation, is being used. Right now

Python program not working, input == string not working

python python-3.x

Hello i'm learning python and i am trying to make a small program that converts money into dollar,euro or British pounds. Can some one help me and tell me why is not working?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.