Android : Android: Setting a table row visible in the main java class when defined in Tab1 class

on Sunday, April 19, 2015


I have a Tab1 class and the main class.


Tab1 class below - sets the table row to invisible:


public class Tab1 extends Fragment {



View v;
TableRow tr;

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {


v =inflater.inflate(R.layout.tab_1,container,false);

tr = (TableRow)v.findViewById(R.id.tb1_r1);
tr.setVisibility(View.INVISIBLE);
tr = (TableRow)v.findViewById(R.id.tb1_r2);
tr.setVisibility(View.VISIBLE);
tr = (TableRow)v.findViewById(R.id.tb1_r3);
tr.setVisibility(View.INVISIBLE);
tr = (TableRow)v.findViewById(R.id.tb1_r4);
tr.setVisibility(View.INVISIBLE);

return v;
}


}


In the main activity:


I have a popup window that contains a button and when it is pressed it will set one of the table rows to visible. Right now I am just trying to set the first table row visible.


public void BtnAddContact(View view){


Toast.makeText(getApplication(), "New Contact Added", Toast.LENGTH_SHORT ).show();


popupWindow_addcontact.dismiss();


LayoutInflater inflater=(LayoutInflater)getBaseContext().getSystemService(LAYOUT_INFLATER_SERVICE);


View view1=inflater.inflate(R.layout.tab_1, null);


TableRow tr =(TableRow)view1.findViewById(R.id.tb1_r1);


tr.setVisibility(View.VISIBLE);


}


It runs and no error message shows. The toast message appears but the table row does not become visible. Can you tell me why the table row is not becoming visible? It has to do with not accessing Tab 1 java class I believe.


0 comments:

Post a Comment