Android,xml元件屬性style的使用,自定義介面卡(含持有者模式)
阿新 • • 發佈:2019-02-12
importandroid.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
/** * Created by Administrator on 2016/8/1. */public class WeatherAdapterextends BaseAdapter {
private int resourceID= 0;
private Context context= null;
private List<Weather>list = null;
public WeatherAdapter(Context context,intresourceID,List<Weather> list){
this.context= context;
this.resourceID=resourceID;
this.list= list;
}
@Override public intgetCount() {
return list.size();
}
@OverridepublicObject getItem(int position) {
return list.get(position);
}
@Overridepublic longgetItemId(int position) {
return position;
}
@OverridepublicView getView(int position, View convertView, ViewGroup parent) {
Weather weather = (Weather) getItem(position);
Holder holder = null ;
if (convertView ==null){
convertView = LayoutInflater.from(context).inflate(resourceID,null);
holder = new Holder();
holder.image = (ImageView) convertView.findViewById(R.id.imageView_list);
holder.windDirection = (TextView) convertView.findViewById(R.id.textView_windDirection_list);
holder.day = (TextView) convertView.findViewById(R.id.textView_day_list);
holder.publishTime = (TextView)convertView.findViewById(R.id.textView_publishtime_list);
convertView.setTag(holder);
}else{
holder =(Holder)convertView.getTag();
}
holder.image.setImageResource(weather.imageID);
holder.windDirection.setText(weather.windDirection);
holder.day.setText(weather.day);
holder.publishTime.setText(weather.publishTime);
return convertView;
}
}
class Holder{
TextView weatherName;
TextView location;
ImageView image;
TextView temperature;
TextView windDirection;
TextView publishTime;
TextView day;
}
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
/** * Created by Administrator on 2016/8/1. */public class WeatherAdapterextends
private int resourceID= 0;
private Context context= null;
private List<Weather>list = null;
public WeatherAdapter(Context context,intresourceID,List<Weather> list){
this.context= context;
this.resourceID=resourceID;
this.list= list;
}
@Override
return list.size();
}
@OverridepublicObject getItem(int position) {
return list.get(position);
}
@Overridepublic longgetItemId(int position) {
return position;
}
@OverridepublicView getView(int position, View convertView, ViewGroup parent) {
Weather weather = (Weather) getItem(position);
Holder holder = null
if (convertView ==null){
convertView = LayoutInflater.from(context).inflate(resourceID,null);
holder = new Holder();
holder.image = (ImageView) convertView.findViewById(R.id.imageView_list);
holder.windDirection = (TextView) convertView.findViewById(R.id.textView_windDirection_list);
holder.day = (TextView) convertView.findViewById(R.id.textView_day_list);
holder.publishTime = (TextView)convertView.findViewById(R.id.textView_publishtime_list);
convertView.setTag(holder);
}else{
holder =(Holder)convertView.getTag();
}
holder.image.setImageResource(weather.imageID);
holder.windDirection.setText(weather.windDirection);
holder.day.setText(weather.day);
holder.publishTime.setText(weather.publishTime);
return convertView;
}
}
class Holder{
TextView weatherName;
TextView location;
ImageView image;
TextView temperature;
TextView windDirection;
TextView publishTime;
TextView day;
}