我是android和java的新手,我从我在线跟踪的教程中创建了自己的适配器和列表视图。我想知道每个行的图像是如何的,因为我的适配器(来自教程)只有1个图像用于所有行。这是我自己的适配器的代码。
class HangarAdapter extends ArrayAdapter<String> {
public HangarAdapter(Context context, String[] values) {
super(context, R.layout.hangar_layout, values);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater theInflater = LayoutInflater.from(getContext());
View theView = theInflater.inflate(R.layout.hangar_layout, parent, false);
String ship = getItem(position);
TextView theTextView = (TextView) theView.findViewById(R.id.textView1);
theTextView.setText(ship);
ImageView theImageView = (ImageView) theView.findViewById(R.id.imageView);
theImageView.setImageResource(R.drawable.dot);
return theView;
}
}
答案 0 :(得分:0)
theImageView.setImageResource(R.drawable.dot);
以上这一行是为了使用不同的图像而必须更改的内容;
you could potentially do something like this;
if (position == 0){
theImageView.setImageResource(R.drawable.dot);
} else if (position == 1){
theImageView.setImageResource(R.drawable.circle);
}
它还取决于后备数据。