Skip to content Skip to sidebar Skip to footer

How To Set The First Item In Gridview With Default Value And Populate The Rest Of The Items Based On Json Result

Hi i would like to set the first item of my GridView with a default value, and populate the rest of the item accordingly (based on JSON result) My code consist of 2 classes 1. Main

Solution 1:

Try doing this:

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stubLayoutInflaterinflater= (LayoutInflater) mContext
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

View view;

if(position == 0)
// Populate default itemelse// Populate from jsonif(convertView == null){
    view = newView(mContext);
    view = inflater.inflate(R.layout.grid_item_text, null);

    TextViewpersonName= (TextView) view.findViewById(R.id.textItem);
    ImageViewpersonThumb= (ImageView) view.findViewById(R.id.iconItem);

    // IF HAVE RESULTif(mList.size() != 0){
        /* INITIALIZES PHOTO */
        BitmapFactory.Options bmOptions;
        bmOptions = newBitmapFactory.Options();
        bmOptions.inSampleSize = 1;

        /*
        Bitmap bmpThumb = loadBitmap(mList.get(position).accId, bmOptions, IMAGE_THUMB);

        if(bmpThumb != null){
            ImageHelper ih = new ImageHelper();
            bmpThumb = ih.getRoundedCornerBitmap(bmpThumb, 10);
            personThumb.setImageBitmap(bmpThumb);
        }else{
            personThumb.setImageResource(mThumbs);
        }
        */

        personThumb.setImageResource(mThumbs);
        personName.setText(mList.get(position).fullName.toString());
    }else{
        personThumb.setImageResource(mThumbs);
        personName.setText("Add Friends");
    }



}else{
    view = (View) convertView;
}
return view;

}

Solution 2:

if you are using array or arraylist to bind data in gridview than add data at first position than after add data of JSON result. so you can have your data at first position of array or arraylist. and than bind it in to gridview.

Post a Comment for "How To Set The First Item In Gridview With Default Value And Populate The Rest Of The Items Based On Json Result"