Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/215.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何更改此列表视图中每行的图像_Java_Android_Image_Listview - Fatal编程技术网

Java 如何更改此列表视图中每行的图像

Java 如何更改此列表视图中每行的图像,java,android,image,listview,Java,Android,Image,Listview,我是android和java新手,我根据在线教程创建了自己的适配器和列表视图。我想知道如何为每一行创建图像,因为我的适配器(来自教程)只有一个用于所有行的图像。下面是我自己的适配器的代码 class HangarAdapter extends ArrayAdapter<String> { public HangarAdapter(Context context, String[] values) { super(context, R.layout.hangar_layout

我是android和java新手,我根据在线教程创建了自己的适配器和列表视图。我想知道如何为每一行创建图像,因为我的适配器(来自教程)只有一个用于所有行的图像。下面是我自己的适配器的代码

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;


}
class机库适配器扩展了ArrayAdapter{
公共机库适配器(上下文,字符串[]值){
超级(上下文、右布局、机库布局、值);
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
LayoutInflater theInflater=LayoutInflater.from(getContext());
View theView=theInflater.充气(R.layout.hangar\u布局,父项,false);
字符串ship=getItem(位置);
TextView theTextView=(TextView)theView.findViewById(R.id.textView1);
textView.setText(船舶);
ImageView theImageView=(ImageView)theView.findViewById(R.id.ImageView);
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);
}
它还取决于支持数据

you could potentially do something like this;
if (position == 0){
   theImageView.setImageResource(R.drawable.dot);
} else if (position == 1){
   theImageView.setImageResource(R.drawable.circle);
}