1. Are you ready for the Galaxy S20? Here is everything we know so far!

Nesting FrameLayout into a TableRow dynamically

Discussion in 'Android Development' started by afh110, Oct 26, 2014.

  1. afh110

    afh110 Lurker
    Thread Starter

    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 !!! :(

    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));

    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);

    ViewGroup.LayoutParams layout2 =
    new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    txtView.setGravity(Gravity.TOP | Gravity.RIGHT);

    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);
    BtnCounter = BtnCounter + 1;
    ImButtonArray[row][col] = BtnCounter; // just storing button positions in this array

    ImButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    int SW_ID;
    SW_ID = BtnCounter;
    onPrepareOptionsMenu(FINAL_ROW, FINAL_COL);



    1. Download the Forums for Android™ app!



Share This Page