I want to create multiple buttons dynamically with label and another small button on it. For example:-
How to add image button and label on main button dynamically in android?
1.5k views Asked by Deepmala singh M At
2
There are 2 answers
0
On
Ok so first of all make an item of Image button and label in xml.
item.xml
<LinearLayout
android:id="@+id/llOverallTitleDOWN"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageButton
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Then on java file refer the below code.
LinearLayout llOverallTitleDOWN = (LinearLayout) findViewById(R.id.llOverallTitleDOWN);
View layout2 = LayoutInflater.from(this).inflate(R.layout.item, llOverallTitleDOWN, false);
ImageButton imgBtn = (ImageButton) layout2.findViewById(R.id.imgBtn);
TextView textLabel = (TextView) layout2.findViewById(R.id.textLabel);
imgBtn.setImageBitmap(bitmap);
textLabel.setText("label");
llOverallTitleDOWN.addView(layout2);
Need to add drawable in button right.I think there is no need to add extra button on button if there is no action for upper button . please see below code and try
If you face any issue .. let me know.. hope this help