事情是在我的customlistadapter中它将显示六行的文本和图片。但在最后一行,它只会显示文字,而不是图片。当我把0而不是图片时,他们显示默认图片,但我不想在那里有任何图片。怎么做?任何提示都非常有价值,谢谢。
在这一行:
-> pilsTyper.add(new Pilstyper("Egendefinert", 0));
ListAdapterClass
private class MyListAdapter extends ArrayAdapter<Pilstyper> {
public MyListAdapter() {
super(velgDinPromille.this, R.layout.activity_item_view, pilsTyper);
}
public View getView(int position, View convertView, ViewGroup parent) {
View itemView = convertView;
if (itemView == null) {
itemView = getLayoutInflater().inflate(
R.layout.activity_item_view, parent, false);
}
// finn pilstype som du skal jobbe med
Pilstyper nyPils = pilsTyper.get(position);
// ImageView
ImageView imageView = (ImageView) itemView
.findViewById(R.id.lettol);
imageView.setImageResource(nyPils.getIkonId());
// Tekst
TextView tekst = (TextView) itemView.findViewById(R.id.tekst_pils);
tekst.setText(nyPils.getTekst());
return itemView;
}
}
private void pilsTyperList() {
// TODO Auto-generated method stub
pilsTyper.add(new Pilstyper("Øl", R.drawable.ol));
pilsTyper.add(new Pilstyper("Cider og rusbrus", R.drawable.cider));
pilsTyper.add(new Pilstyper("Vin", R.drawable.vin));
pilsTyper.add(new Pilstyper("Sterkvin", R.drawable.portvin2));
pilsTyper.add(new Pilstyper("Brennevin/Drinker", R.drawable.drink2));
pilsTyper.add(new Pilstyper("Egendefinert", 0));
}
答案 0 :(得分:1)
当图标ID为0时,您应该隐藏ImageView。试试这个:
if (nyPils.getIkonId() == 0) {
imageView.setVisibility(View.GONE); // or View.INVISIBLE
} else {
imageView.setVisibility(View.VISIBLE);
imageView.setImageResource(nyPils.getIkonId());
}
答案 1 :(得分:0)
不,你必须提供图片ID,你没有任何其他选择。