Gridview Taking Limited Values to Display

Am having a custom Gridview to display a list of operators with their icon and names of the provider.my problem is the Gridview displaying only Limited providers (12 only).But am having more than 16 values to display.the Remaining Values is getting Repeated in Gridview while Scrolling GridView.

my source code is Here

public class ImageAdapter extends BaseAdapter {

    public int getCount() {
        return providerlist1.size();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        View v;
        ImageView imageView;
        if (convertView == null) {
            LayoutInflater layoutInflater = getLayoutInflater();
            v = layoutInflater.inflate(R.layout.icon_with_text, null);
            TextView txt = (TextView) v.findViewById(R.id.icon_text);
            txt.invalidate();
            txt.setTypeface(localTypeface1);
            Collections.sort(providerlist1);
            Log.v("COLLECTIONS", ""+providerlist1);
            txt.setText("" + providerlist1.toArray()[position]);
            String string = (String) txt.getText();
            icon = string.toLowerCase();
            System.out.println(icon);
            int resid = getResources().getIdentifier("" + icon, "drawable",
                    "com.digient.yeldi.app");
            imageView = (ImageView) v.findViewById(R.id.icon_image);
            imageView.setImageResource(resid);

        } else {
            v = convertView;
        }

        return v;

    }

}

providerlist1 is an arraylist in which am having more than 16 operators values.

Answers


Use Below Code for that, may be it will help you.

public class ImageAdapter extends BaseAdapter {

    LayoutInflater layoutInflater;
    Context ctx;
    public ImageAdapter(Context context) {
        // TODO Auto-generated constructor stub
        layoutInflater=LayoutInflater.from(context);
        this.ctx=context;
    }

    public int getCount() {
        return providerlist1.size();
    }

    public Object getItem(int position) {
        return null;
    }

    public long getItemId(int position) {
        return 0;
    }

    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
        View v;
        ImageView imageView;
        if (convertView == null) {
            v = layoutInflater.inflate(R.layout.icon_with_text, null);
        } else {
            v = convertView;
        }

        TextView txt = (TextView) v.findViewById(R.id.icon_text);
        txt.invalidate();
        txt.setTypeface(localTypeface1);
        Collections.sort(providerlist1);
        Log.v("COLLECTIONS", ""+providerlist1);
        txt.setText("" + providerlist1.toArray()[position]);
        String string = (String) txt.getText();
        icon = string.toLowerCase();
        System.out.println(icon);
        int resid = getResources().getIdentifier("" + icon, "drawable", "com.digient.yeldi.app");
        imageView = (ImageView) v.findViewById(R.id.icon_image);
        imageView.setImageResource(resid);

        return v;

    }

}

Need Your Help

Raster Calc with KendallATS function from "smwrQW" package

r raster subscript calc r-raster

This is my first question on StackOverflow. I am trying to use Mann-Kendall trend test on a brick of rasters consisting of 15 layers (time-series of counts) to make three rasters (sen slope, tau-b ...