【发布时间】:2015-02-27 04:59:14
【问题描述】:
我正在开发一个应用程序,其中我有一个带有自定义适配器的列表视图。我将 ArrayList 附加到自定义适配器。适配器有四个图像视图,并且 onclick 侦听器应用于获取视图中的每个图像视图。
我正在根据条件从其他两个数组列表填充数组列表:
/* Condition 1 */
for(int i = 0; i < arrayList.size(); i++){
if( a == id){
arrayList1.add(arrayListOther.get(i));
}
}
/* condition 2 */
for(int i = 0; i < arrayList.size(); i++){
arrayList1.add(arrayList.get(i));
}
当我的 arrayList 仅从条件 2 填充时,单击列表的第一项时,它给出的位置为 0。但是当我的 arraList 从条件 1 和 2 填充时,第一项从 arrayListOther 填充,其余从 arrayList从条件二来看,点击列表中的第一项时,它的位置为 1。
在我的适配器中:
public class ViewHolder {
ImageView image1;
ImageView image2;
ImageView image3;
ImageView image4;
}
public View getView(final int position, View view, ViewGroup parent) {
if (view == null || view.getTag() == null) {
holder = new ViewHolder();
view = inflater.inflate(R.layout.listview_adapter_layout, null);
holder.image1 = (ImageView) view.findViewById(R.id.imageView1);
holder.image2 = (ImageView) view.findViewById(R.id.imageView2);
holder.image3 = (ImageView) view.findViewById(R.id.imageView3);
holder.image4 = (ImageView) view.findViewById(R.id.imageView4);
view.setTag(holder);
} else {
holder = (ViewHolder) view.getTag();
}
// Some code here
// Also having Async task
if(flag == 2){
holder.image1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Also having Async task
Log.d("Position",""+position);
}
});
}
// Some code here
}
我不明白这有什么问题。请建议我该怎么做。
【问题讨论】:
-
你在列表视图中看到了多少行?
-
一行的大小很大,所以有时我可以看到第二行的 1 和一半,有时一次可以看到 2 行,有时一次可以看到单行,这取决于图像的数据和大小。跨度>
标签: android android-listview listener android-adapter android-adapterview