0

I have the following issue, I inflate a layout which includes 2 buttons. The onClick method works fine and everything runs smoothly. However I would like to make both buttons that are inflated each time invisible once one of those two is being clicked. I know how to make the button invisbile that was clicked however I find no way of making the corresponding button invisible. Any help is greatly appreciated.
(If it is any concern, this is all done in a fragment)

for(i = 0; i < al.size(); i = i+6) { 
    TableLayout tl = (TableLayout)fragmentView.findViewById(R.id.myTableLayout);
    LayoutInflater inflater1 = (LayoutInflater)getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    View itemView = inflater1.inflate(R.layout.element_request, null);  

    TextView t1 = (TextView) itemView.findViewById(R.id.tvdescription1);   
    t1.setText(al.get(i+2)); 

    TextView t2 = (TextView) itemView.findViewById(R.id.tvdescription2);   
    t2.setText(al.get(i+3));
    String id = al.get(i+1);

    accept = (Button) itemView.findViewById(R.id.baccept);
    accept.setTag(R.id.tvdescription1, id);
    String id1 ="a"+id;
    accept.setTag(R.id.tvdescription2, id1);

    decline = (Button) itemView.findViewById(R.id.bdecline);
    decline.setTag(R.id.tvdescription1, id);
    String id2 = "b"+id;
    decline.setTag(R.id.tvdescription2,id2);
    tl.addView(itemView, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));

    accept.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            crid = v.getTag(R.id.tvdescription1);
            crid2 = crid.toString();
            ....Code...
            accept = (Button)v;
            accept.setVisibility(View.GONE);
            //----->set corresponding "decline" button also Invisible
        }
    }
}
Sam
  • 86,580
  • 20
  • 181
  • 179
Max
  • 572
  • 2
  • 6
  • 23

1 Answers1

1

You could try this:

ViewGroup row = (ViewGroup) v.getParent();
Button dec = (Button) row.getChildAt(3); //If decline is the 4th member in the view
dec.setVisibility(View.GONE);
iTurki
  • 16,292
  • 20
  • 87
  • 132
  • Thank you. That was exactly what I was looking for and I learned something new about ViewGroup. Your help was really appreciated. – Max Oct 29 '12 at 22:15