カスタムアダプターを作っています。私のlist_itemにListView
はそれ自体があり、後でsLinearLayout
を追加しています。ImageView
私は次のコードを使用しています:
public class Adapter extends ArrayAdapter<Row_Item> {
private java.util.List<Row_Item> List;
private Context context;
public Adapter(List<Row_Item> list, Context ctx) {
super(ctx, R.layout.row_item, list);
this.List = list;
this.context = ctx;
}
public int getCount() {
return List.size();
}
public Row_Item getItem(int position) {
return List.get(position);
}
public long getItemId(int position) {
return List.get(position).hashCode();
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
TopicHolder holder = new TopicHolder();
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.row_item, null);
TextView tv = (TextView) v.findViewById(R.id.textView);
*LinearLayout* l = (LinearLayout) v.findViewById(R.id.myLayout);
holder.topic = tv;
holder.myLayout = l;
v.setTag(holder);
} else
holder = (TopicHolder) v.getTag();
Row_Item p = List.get(position);
holder.topic.setText(p.getName());
ImageView imgUsers;
for (int i = 0; i < some_parameter; i++) { imgUsers = new ImageView(context);
imgUsers.setImageResource(some_image);
holder.myLayout.addView(imgUsers); //add that image to my linearlayout
}
return v;
}
private static class TopicHolder {
public TextView topic;
public LinearLayout myLayout;
// public ImageView notifications;
}
}
ここで起こることは、getView()
が無限に呼び出されることです。また、onItemClickListener
このアダプターが呼び出されるクラスに設定しました。アダプター クラスが終了しないため、リスナーは機能せず、アプリは停止したままになります。
myLayout.getChildCount()
また、画像の数よりも大きい場合は返すなどを試しましたが、それでも無限ループは終了しません。