SetEnabled (), setClickable () does not work

I used FrameLayout, in which I used two LinearLayouts. The second one is initially invisible, but when I click the button on the layout one, the second layout becomes visible and overlaps the first layout. I want, when my second layout appears, the first elements of the layout should not be clickable (or included). For this, I tried setEnabled (false) and setClickable (false), but both of them do not work. I do not understand what the problem is.

The code is as follows

TableLayout table; EditText edit; ScrollView scroll; Button btn_save; Button btn_layer_save; Button btn_cross; AlertDialog alert_dialog; LinearLayout layout_above; int primary_selected; RadioButton radio_geo; RadioButton radio_alumni; String geo = "no" ; String alumni = "no" ; int color; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); table = (TableLayout) findViewById(R.id.tableLayout1); edit = (EditText) findViewById(R.id.message_select_friends_edit_search); search_geo_name_list = new ArrayList<String>(); search_id_list = new ArrayList<String>(); scroll = (ScrollView) findViewById(R.id.register_scroll_view); btn_cross = (Button) findViewById(R.id.register_cross); btn_save = (Button) findViewById(R.id.register_save); btn_layer_save = (Button) findViewById(R.id.register_layer_save); btn_cross.setOnClickListener(this); btn_save.setOnClickListener(this); btn_layer_save.setOnClickListener(this); layout_above = (LinearLayout) findViewById(R.id.regsiter_layout_layer_above); createTableRows(name_list,id_list); } void createTableRows(ArrayList<String> list_name , ArrayList<String> list_id ) { /*-----ROWSOFTABLECREATEDDYN AMICALLY ------*/ } @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.register_save: layout_above.setVisibility(LinearLayout.VISIBLE); btn_save.setVisibility(LinearLayout.INVISIBLE); scroll.setEnabled(false); edit.setEnabled(false); edit.setClickable(false); scroll.setClickable(false); break; case R.id.register_cross: Toast.makeText(this, "Cross Cancel", 1000).show(); Intent intent = new Intent(this, TestSave.class); startActivity(intent); finish(); break; case R.id.register_layer_save: selectedInfo(); break; } }` 
+6
source share
4 answers

Take the size of the front layout as the size of the background layout and set the front background layout color to transparent, so that the background layout is partially visible. And set onClickListener to the front layout and do nothing in the onClick method.

This answer is not exactly the way you want, but it is a good alternative.

Hope this helps

+7
source

Try using setFocusable (False); maybe this should help you

+2
source

Try working with children instead of layout

 LinearLayout l=(LinearLayout) findViewById(R.layout.layout2); int num=l.getChildCount(); for(int i=0;i<l.getChildAt(0);i++) if(l.getChildAt(i).isClickable()||l.getChildAt(i).isEnabled()) { l.getChildAt(i).setClickable(false); l.getChildAt(i).setEnabled(false); } 
0
source

You can use recursion for this and recursively disable the clickable property for all children -

 public static void enableDisableViewGroup(ViewGroup viewGroup, boolean enabled) { int childCount = viewGroup.getChildCount(); for (int i = 0; i < childCount; i++) { View view = viewGroup.getChildAt(i); view.setEnabled(enabled); if (view instanceof ViewGroup) { enableDisableViewGroup((ViewGroup) view, enabled); } else if (view instanceof ListView) { view.setEnabled(enabled); ListView listView = (ListView) view; int listChildCount = listView.getChildCount(); for (int j = 0; j < listChildCount; j++) { listView.getChildAt(j).setEnabled(enabled); } } } } 
0
source

Source: https://habr.com/ru/post/893479/


All Articles