カスタムのリストビューがあり、最初の項目の左側にプラス アイコンを表示したいと考えています。最初のアイテムのみ!
カスタム アダプタを getView() メソッドに記述し、次のような if 条件を使用しました。
If position == 0
imgicon.setvisibility=0;
}
else
{
imgicon.setvisibility=1;
}
しかし、リストを上下にスクロールすると、最初のアイテムにアイコンが表示されるだけでなく、いくつかのランダムなアイテムにもそのアイコンが表示されます。なにが問題ですか?これはバグですか?
編集:言うまでもなく、行を削除すると: imgicon.setvisibility==0
、すべてのアイコンが消えます。
編集:
ここに私のカスタム配列アダプターがあります:
public class Projects_list_custom_array extends ArrayAdapter<Project_Detail> implements
Filterable {
private final Object mLock = new Object();
private ItemsFilter mFilter;
public ArrayList<Project_Detail> mItems;
private ArrayList<Project_Detail> objects;
public Projects_list_custom_array(Context context, int textViewResourceId,
ArrayList<Project_Detail> objects) {
super(context, textViewResourceId, objects);
this.objects = objects;
this.mItems = new ArrayList<Project_Detail>(objects);
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.activity_placeholder_projects_list,
null);
}
Project_Detail i = objects.get(position);
if (i != null) {
TextView tt = (TextView) v
.findViewById(R.id.projects_list_first_placeholder);
RelativeLayout projects_list_layout = (RelativeLayout)v.findViewById(R.id.projects_list_placeholder_layout);
if (tt != null) {
tt.setText(i.get_projectname() + " " + position);
}
if (position == 0) {
ImageView imgv = new ImageView(getContext());
imgv.setImageResource(R.drawable.project_add);
projects_list_layout.addView(imgv);
}
}
return v;
}
/* ... */
@Override
public int getCount() {
return objects.size();
}
@Override
public Project_Detail getItem(int position) {
return objects.get(position);
}