I need to generate some ImageView inside the getView method.
I will generate them inside this layout :
<LinearLayout
android:id="@+id/layoutBaby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal" >
So the images will be added horizontally automatically (because the orientation
).
This is how i add those images :
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
for(int childId : dbHelper.getChildrenIdBySchedule(getItem(position).getId()))
{
ImageView imgBaby = new ImageView(context);
imgBaby.setLayoutParams(params);
String image = dbHelper.getChildImage(childId);
File imgFile = new File(image);
if(imgFile.exists())
{
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imgBaby.setImageBitmap(myBitmap);
}
else
{
imgBaby.setImageResource(R.drawable.ic_launcher);
}
holder.layoutBaby.addView(imgBaby);
}
I have debug the code above to make sure its called multiple times (based on dbHelper.getChildrenIdBySchedule
).
This code working if theres only 1 ImageView
, however if there is more than 1 ImageView
, only the lastest added ImageView
is vissible.
For example, if theres 2 ImageViews
, although both of them has been added (i debug the code), only the 2nd ImageView
is visible.
Feel free to ask me anything, and Thanks for your time.