Create ImageButton programatically depending on local database records
Posted
by
user2507920
on Stack Overflow
See other posts from Stack Overflow
or by user2507920
Published on 2013-06-25T10:11:39Z
Indexed on
2013/06/25
10:21 UTC
Read the original article
Hit count: 165
As i described in title, i have a local db in sqlite. I want to create ImageButton
parametrically. How many times is local database loop executing? Please see code below :
RelativeLayout outerRelativeLayout = (RelativeLayout)findViewById(R.id.relativeLayout2_making_dynamically);
db.open();
Cursor c = db.getAllLocal_Job_Data();
if(c!=null){
if(c.moveToFirst()){
do {
RelativeLayout innerRelativeLayout = new RelativeLayout(CalendarActivity.this);
innerRelativeLayout.setGravity(Gravity.CENTER);
ImageButton imgBtn = new ImageButton(CalendarActivity.this);
imgBtn.setBackgroundResource(R.drawable.color_001);
RelativeLayout.LayoutParams imageViewParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
imgBtn.setLayoutParams(imageViewParams);
// Adding the textView to the inner RelativeLayout as a child
innerRelativeLayout.addView(imgBtn, new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
outerRelativeLayout.addView(innerRelativeLayout, new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
} while (c.moveToNext());
}
}
db.close();
But when i run the project, i can see only one button created there. I think there are many buttons but here image button is creating on last created image button. I think i should use android:layout_toRightOf
with previous created button but i cant find how to place it here. I have tried some ideas but it did not change any thing. So please anybody has any idea to solve my problem then please share it with me.
© Stack Overflow or respective owner