Hi all..
What im trying to do: Im trying to dynamically create a table of image buttons. When each image button is clicked, a counter badge/bubble (like the update icon u see on apps when there is an update in iphones). This badge should show one the top left corner of the image button.
My logic: To do that i thought that i need to create a tablerow, then in that tablerow put a FrameLayout, and in that FrameLayout but in the Image button and a text view that will display the badge image. Reason i use a FrameLayout is because i need to have the TextView overlap the Imagebutton to get the effect i want...
The Problem: I wrote the code below and it runs with no errors but no counter badge!! It seems like the application ignores the badge and only creates the image buttons for me.... Need help to make it work
HELP !!!
[HIGH]
setContentView(R.layout.activitymenu);
TableLayout table =(TableLayout) findViewById(R.id.MenuButtonTable);
for (int row=0; row<NUM_Array_Rows;row++) {
//Set new Row in Table
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT, 0.1F));
table.addView(tableRow);
for (int col = 0; col < NUM_Array_Clns; col++) {
int x, y;
final int FINAL_COL = col;
final int FINAL_ROW = row;
final int FINAL_BtnCounter = BtnCounter;
final String SW_NAME;
float w;
final ImageButton ImButton = new ImageButton(this);
final FrameLayout FrmLayout = new FrameLayout(this);
final TextView txtView = new TextView(this);
FrameLayout.LayoutParams layout1 =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
FrmLayout.setLayoutParams(layout1);
ViewGroup.LayoutParams layout2 =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
txtView.setLayoutParams(layout2);
txtView.setGravity(Gravity.TOP | Gravity.RIGHT);
txtView.setBackgroundResource(R.drawable.badge);
txtView.setText("2");
FrmLayout.setBackgroundResource(R.drawable.ic_launcher);
ImButton.setLayoutParams(new TableRow.LayoutParams(BtnWidth, BtnHight,0.1F));
Resources res = getResources();
SW_NAME = MenuArray[col][1]; //SW NAme
temp = MenuArray[col][3];
int id = res.getIdentifier(temp, "drawable", MenuActivity.this.getPackageName());
Drawable drawable = res.getDrawable(R.drawable.sw03);
ImButton.setBackground(drawable);
BtnCounter = BtnCounter + 1;
ImButtonArray[row][col] = BtnCounter; // just storing button positions in this array
ImButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int SW_ID;
SW_ID = BtnCounter;
onPrepareOptionsMenu(FINAL_ROW, FINAL_COL);
}
});
tableRow.addView(FrmLayout);
tableRow.addView(ImButton);
FrmLayout.addView(txtView);
[/HIGH]
What im trying to do: Im trying to dynamically create a table of image buttons. When each image button is clicked, a counter badge/bubble (like the update icon u see on apps when there is an update in iphones). This badge should show one the top left corner of the image button.
My logic: To do that i thought that i need to create a tablerow, then in that tablerow put a FrameLayout, and in that FrameLayout but in the Image button and a text view that will display the badge image. Reason i use a FrameLayout is because i need to have the TextView overlap the Imagebutton to get the effect i want...
The Problem: I wrote the code below and it runs with no errors but no counter badge!! It seems like the application ignores the badge and only creates the image buttons for me.... Need help to make it work
HELP !!!
[HIGH]
setContentView(R.layout.activitymenu);
TableLayout table =(TableLayout) findViewById(R.id.MenuButtonTable);
for (int row=0; row<NUM_Array_Rows;row++) {
//Set new Row in Table
TableRow tableRow = new TableRow(this);
tableRow.setLayoutParams(new TableLayout.LayoutParams(
TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.MATCH_PARENT, 0.1F));
table.addView(tableRow);
for (int col = 0; col < NUM_Array_Clns; col++) {
int x, y;
final int FINAL_COL = col;
final int FINAL_ROW = row;
final int FINAL_BtnCounter = BtnCounter;
final String SW_NAME;
float w;
final ImageButton ImButton = new ImageButton(this);
final FrameLayout FrmLayout = new FrameLayout(this);
final TextView txtView = new TextView(this);
FrameLayout.LayoutParams layout1 =
new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
FrmLayout.setLayoutParams(layout1);
ViewGroup.LayoutParams layout2 =
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
txtView.setLayoutParams(layout2);
txtView.setGravity(Gravity.TOP | Gravity.RIGHT);
txtView.setBackgroundResource(R.drawable.badge);
txtView.setText("2");
FrmLayout.setBackgroundResource(R.drawable.ic_launcher);
ImButton.setLayoutParams(new TableRow.LayoutParams(BtnWidth, BtnHight,0.1F));
Resources res = getResources();
SW_NAME = MenuArray[col][1]; //SW NAme
temp = MenuArray[col][3];
int id = res.getIdentifier(temp, "drawable", MenuActivity.this.getPackageName());
Drawable drawable = res.getDrawable(R.drawable.sw03);
ImButton.setBackground(drawable);
BtnCounter = BtnCounter + 1;
ImButtonArray[row][col] = BtnCounter; // just storing button positions in this array
ImButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int SW_ID;
SW_ID = BtnCounter;
onPrepareOptionsMenu(FINAL_ROW, FINAL_COL);
}
});
tableRow.addView(FrmLayout);
tableRow.addView(ImButton);
FrmLayout.addView(txtView);
[/HIGH]