我在这里做错了什么?我想我需要另外一组眼球,因为我已经看了太长时间......
我有一个自定义微调器适配器,显示图像和文本以选择态度。我在拉 文本的字符串和我拥有的资源中的图标。文字是正确的,但图像不仅不合适,有时甚至完全疯狂 - 甚至在图像集中也是如此 我选择。
public View getCustomView(int position, View convertView, ViewGroup parent) {
String[] attitude = new String[]{
this.context.getResources().getString(R.string.happy),
this.context.getResources().getString(R.string.sad),
this.context.getResources().getString(R.string.angry),
this.context.getResources().getString(R.string.difficult),
this.context.getResources().getString(R.string.hurt),
this.context.getResources().getString(R.string.confused),
this.context.getResources().getString(R.string.stubborn)};
LayoutInflater inflater=(LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row=inflater.inflate(R.layout.spinner_row, parent, false);
TextView label=(TextView)row.findViewById(R.id.attitude_label);
label.setText(attitude[position]);
ImageView icon=(ImageView)row.findViewById(R.id.emoticon);
switch (position) {
case 0:
icon.setImageResource(R.drawable.happy);
break;
case 1:
icon.setImageResource(R.drawable.sad);
break;
case 2:
icon.setImageResource(R.drawable.angry);
break;
case 3:
icon.setImageResource(R.drawable.difficult);
break;
case 4:
icon.setImageResource(R.drawable.hurt);
break;
case 5:
icon.setImageResource(R.drawable.confused);
break;
case 6:
icon.setImageResource(R.drawable.stubborn);
break;
}
return row;
}
下面的图片显示了全部 - 文字是正确的,但图片不是。快乐显然很伤心, 应该感到遗憾的是我用于导入数据的另一个图像资源。愤怒,困难和困惑都很好,但伤害和固执也是完全不同的资源。
什么是biff?我怀疑我做了一些微不足道的事情而且看不到它,所以请踢我。
答案 0 :(得分:0)
Hello may be its helpful to you. pls try this.
public class ViewHolder {
public TextView label;
public ImageView icon;
}
public View getCustomView(int position, View convertView, ViewGroup parent) {
View vi = convertView;
ViewHolder holder;
if (convertView == null) {
vi = inflater.inflate(R.layout.spinner_row, null);
holder = new ViewHolder();
holder.label = (TextView) vi.findViewById(R.id.attitude_label);
holder.icon = (ImageView) vi.findViewById(R.id.emoticon);
vi.setTag(holder);
} else
holder = (ViewHolder) vi.getTag();
holder.label.setText(attitude[position]);
switch (position) {
case 0:
holder.icon.setImageResource(R.drawable.happy);
break;
case 1:
holder.icon.setImageResource(R.drawable.sad);
break;
case 2:
holder.icon.setImageResource(R.drawable.angry);
break;
case 3:
holder.icon.setImageResource(R.drawable.difficult);
break;
case 4:
holder.icon.setImageResource(R.drawable.hurt);
break;
case 5:
holder.icon.setImageResource(R.drawable.confused);
break;
case 6:
holder.icon.setImageResource(R.drawable.stubborn);
break;
}
return vi;
}
答案 1 :(得分:0)
是否有可能需要从头开始重建项目 - 在eclipse中意味着使用project-> clean?