Skip to content Skip to sidebar Skip to footer

Custom Listview With Text And Image

I have developed a listview,listview displaying image and text.1st have to download image and text form web-service then have to display because it takes more time so we thought 1s

Solution 1:

Try this example or use any adapter like this

WeatherAdapter.java

publicclassWeatherAdapterextendsArrayAdapter<Weather>{

Context context;
int layoutResourceId;   
Weather data[] = null;

publicWeatherAdapter(Context context, int layoutResourceId, Weather[] data) {
    super(context, layoutResourceId, data);
    this.layoutResourceId = layoutResourceId;
    this.context = context;
    this.data = data;
}

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
    Viewrow= convertView;
    WeatherHolderholder=null;

    if(row == null)
    {
        LayoutInflaterinflater= ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = newWeatherHolder();
        holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
        holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);

        row.setTag(holder);
    }
    else
    {
        holder = (WeatherHolder)row.getTag();
    }

    Weatherweather= data[position];
    holder.txtTitle.setText(weather.title);
    holder.imgIcon.setImageResource(weather.icon);

    return row;
}

staticclassWeatherHolder
{
    ImageView imgIcon;
    TextView txtTitle;
}
}

Post a Comment for "Custom Listview With Text And Image"