The constructor ArrayAdapter<ArrayList<HashMap<String, String>>>(Context, int, ArrayList<HashMap<String, String>>) is undefined

拟墨画扇 提交于 2019-12-23 05:59:31

问题


I am totally new to Android.

This question might be a basic one.

But I'm struggling for four days with this. Please Help me.

I'm making horizontal listview for providing the contents of several categories from blog.

(similar interface with Pulse news app)

I got the open source of the horizontal listview and I'm modifying it.

This code is CustomArrayAdapter.java.

But when I try to write super(); inside the constructor, it makes an error like this :

The constructor ArrayAdapter<ArrayList<HashMap<String, String>>>(Context, int, ArrayList<HashMap<String, String>>) is undefined

And eclipse suggests like this :

Remove argument to match 'ArrayAdapter<ArrayList<HashMap<String, String>>>(Context, int)'

I don't know where this (Context, int) argument came from.

Please check what is wrong in CustomArrayAdapter.java below :

package com.xxxx.xxxxxxxxx;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

/** An array adapter that knows how to render views when given CustomData classes */
public class CustomArrayAdapter extends ArrayAdapter<ArrayList<HashMap<String, String>>> {
    private Context context;
    private ArrayList<HashMap<String, String>> data;
    private int viewId;

    private LayoutInflater mInflater;

    public CustomArrayAdapter(Context c, int textViewResourceId, ArrayList<HashMap<String, String>> d) {
        super(c, textViewResourceId, d);

        this.context = c;
        this.viewId = textViewResourceId;
        this.data = d; 
    }

     @Override
     public int getCount() {
         return data.size();
     }

    /*
     * We are overriding the getView method here - this is what defines how each
     * list item will look.
     */
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {         
        // Assign the view we are converting to a local variable
        View vi = convertView;
        Holder holder;      

        if (convertView == null) {

            // Inflate the view since it does not exist
            if (vi == null) {
                mInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                vi = mInflater.inflate(R.layout.custom_data_view, null);
            }

            /*
             * Recall that the variable position is sent in as an argument to this method.
             * The variable simply refers to the position of the current object in the list. (The ArrayAdapter
             * iterates through the list we sent it)
             * 
             * Therefore, i refers to the current Item object.
             */

            // This is how you obtain a reference to the TextViews.
            // These TextViews are created in the XML files we defined.

            // Create and save off the holder in the tag so we get quick access to inner fields
            // This must be done for performance reasons

            holder = new Holder();
            holder.textView = (TextView) vi.findViewById(R.id.title_view);
            holder.imageView = (ImageView) vi.findViewById(R.id.thumbnail_view);

            vi.setTag(holder);                                  

        } else {
            holder = (Holder) vi.getTag();
        }

        // check to see if each individual textview is null.
        // if not, assign some text!
        // Populate the text 

        HashMap<String, String> currentData = new HashMap<String, String>();
        currentData = data.get(position);

        if (currentData != null) {
            holder.textView.setText(currentData.get(MainActivity.KEY_TITLE));
            holder.imageLoader = new ImageLoader(context.getApplicationContext());    
            holder.imageLoader.DisplayImage(currentData.get(MainActivity.KEY_THUMBNAIL), holder.imageView);
        }       

        // Set the color
        vi.setBackgroundColor(Color.DKGRAY);
        return vi;
    }

    /** View holder for the views we need access to */
    private static class Holder {
        public TextView textView;
        public ImageView imageView;
        public ImageLoader imageLoader;
    }
}

回答1:


It should be:

public class CustomArrayAdapter extends ArrayAdapter<HashMap<String, String>>



回答2:


The compiler is telling you to change this

super(c, textViewResourceId, d);

to

super(c, textViewResourceId);


来源:https://stackoverflow.com/questions/17775077/the-constructor-arrayadapterarraylisthashmapstring-stringcontext-int-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!