Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6033257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:27:27+00:00 2026-05-23T05:27:27+00:00

I have an Edit button in my header. And I populating my TableLayout in

  • 0

I have an Edit button in my header. And I populating my TableLayout in a loop. In The loop I am inflating a Delete button.
Following is the code I have used :

MainActivity :

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.cookbooklist);

    btnHeaderEdit = (Button)findViewById(R.id.btnEdit);
    btnHeaderEdit.setVisibility(View.VISIBLE);
    delete_button = (View)findViewById(R.id.btnDelete);
    listTable = (TableLayout)findViewById(R.id.cookbookListTable);
    btnHeaderEdit.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
        delete_button.getTag();
        delete_button.setVisibility(View.VISIBLE);  
        }
    });

    for(int i=0;i<=10;i++)
    {
        // Row to display news title
        final TableRow newsRow = new TableRow(this);
        newsRow.setMinimumHeight(200);
        newsRow.setClickable(true);
        newsRow.setTag(i);
        newsRow.setBackgroundColor(Color.WHITE);

        // Some other views

        //create inflater
        LayoutInflater inflater = getLayoutInflater();   
         delete_button = inflater.inflate(R.layout.deletebutton,
                    (ViewGroup) newsRow, false);
         delete_button.setTag(i);
         delete_button.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                listTable.removeView(newsRow);
            }
        });

        //Add views in table

        newsRow.addView(delete_button);
        listTable.addView(newsRow);

    }
}  

delebutton.xml :

<Button 
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/btnDelete" 
android:layout_width="100dip" 
android:visibility="invisible"
android:layout_height="40dip" 
android:padding="10sp" 
android:text="Delete">  
</Button>  

Question :

The problem I am facing is that when I click the Edit button in header, Delete button appears only in the last row. When I setVisibility of Delete button to Visible in layout, it appears in all rows. But I want it to be invisible in the start. And on clicking the Edit button it should appear in all rows. I Am wondering how to achieve that.
Can someone assist me? Let me know if more code is needed.

Thanks
The problem I am facing is that when

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:27:28+00:00Added an answer on May 23, 2026 at 5:27 am

    Hi Stone i think you have to use a boolean flag. which wil determine whether the delete button should be visible or not. Try with the following example. Its working fine. On click of edit button if delete buttons are invisible i make all as visible and viceversa. Try the following code.

    See My Working Example

    Sample2.java

    import java.util.ArrayList;
    import java.util.Iterator;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class Sample2 extends Activity {
        boolean showDeleteButtonFlag = false;
        Button delteBtn2 = null;
        Button delteBtn1 = null;
        Button editBtn = null;
        ArrayList<Button> deleteButtonList = new ArrayList<Button>(); 
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.tablerow);
            delteBtn1 = (Button) findViewById(R.id.delete1);
            delteBtn2 = (Button) findViewById(R.id.delete2);
    //      add all delete buttons buttons to the array list
            deleteButtonList.add(delteBtn1);
            deleteButtonList.add(delteBtn2);
            editBtn = (Button) findViewById(R.id.edit);
            setVisibilityOfDeleteButtons();
            editBtn.setOnClickListener(new OnClickListener() {
    
                public void onClick(View arg0) {
                    // if delete button is visible make it as invisible and viceversa
                    showDeleteButtonFlag = !showDeleteButtonFlag;
                    setVisibilityOfDeleteButtons();
                }
            });
    
    
        }
    
    
        void setVisibilityOfDeleteButtons(){
    
            if(showDeleteButtonFlag){
                Iterator<Button> itr =deleteButtonList.iterator();
                while(itr.hasNext()){
                    itr.next().setVisibility(View.VISIBLE);
                }
            }else{
                Iterator<Button> itr =deleteButtonList.iterator();
                while(itr.hasNext()){
                    itr.next().setVisibility(View.INVISIBLE);
                }
            }
        }
    }
    

    tablerow.xml

    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    
        <TableRow>
            <Button
                android:id="@+id/edit"
                android:layout_width="100dip"
                android:layout_height="60dip"
                android:text="Edit" />
    
            <Button
                android:id="@+id/delete1"
                android:layout_width="100dip"
                android:layout_height="60dip"
                android:text="Delete" />
        </TableRow>
    
        <TableRow>
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Password:"
                android:textColor="#ffffff"
                android:textStyle="bold" />
    
            <Button
                android:id="@+id/delete2"
                android:layout_width="100dip"
                android:layout_height="60dip"
                android:text="Delete" />
        </TableRow>
    </TableLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have am writing a code where I can edit or delete certain details
Ok, i have 2 edit controls and a button in my main window; in
I have a javascript function which get datagrid's header into THEAD tags. This code
I have rich datatable with delete button: When I delete the row, row is
I have a list of input type radio buttons in formview (edit mode) and
I have a page where the user can edit various content using buttons and
I have some filter and one grid.And grid have some buttons like modify/edit.I am
I won't want to have edit any working sets. I just want a way
I have an Edit action and an Edit view to allow users to update
I have a edit View - Product/Edit/1 1 being the Id of the Product.How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.