Commit 3cc8c1953fa982e9e2d374aac12afd8e12fab6df

Authored by JLo'w
1 parent 407f6a73

On désactive les boutons de commande si prix

PremiereActivite/app/src/main/java/com/example/app_10p5/TabFragment1.java
@@ -2,12 +2,17 @@ package com.example.app_10p5; @@ -2,12 +2,17 @@ package com.example.app_10p5;
2 2
3 import android.os.Bundle; 3 import android.os.Bundle;
4 import android.app.Fragment; 4 import android.app.Fragment;
  5 +import android.text.Editable;
5 import android.text.InputFilter; 6 import android.text.InputFilter;
  7 +import android.text.TextWatcher;
6 import android.view.LayoutInflater; 8 import android.view.LayoutInflater;
7 import android.view.View; 9 import android.view.View;
8 import android.view.ViewGroup; 10 import android.view.ViewGroup;
  11 +import android.widget.Button;
9 import android.widget.EditText; 12 import android.widget.EditText;
10 13
  14 +import java.util.ArrayList;
  15 +
11 /** 16 /**
12 * Created by beaus on 24/04/2016. 17 * Created by beaus on 24/04/2016.
13 */ 18 */
@@ -17,8 +22,67 @@ public class TabFragment1 extends Fragment { @@ -17,8 +22,67 @@ public class TabFragment1 extends Fragment {
17 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 22 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
18 View v = inflater.inflate(R.layout.tab_fragment_1, container, false); 23 View v = inflater.inflate(R.layout.tab_fragment_1, container, false);
19 EditText et = (EditText) v.findViewById(R.id.commande_prix); 24 EditText et = (EditText) v.findViewById(R.id.commande_prix);
  25 +
20 et.setFilters(new InputFilter[]{new DecimalDigitsInputFilter(3, 2)}); 26 et.setFilters(new InputFilter[]{new DecimalDigitsInputFilter(3, 2)});
21 27
  28 + final ArrayList<View> allChildren = getAllChildren(v.findViewById(R.id.commande_table_boutons));
  29 + et.addTextChangedListener(new TextWatcher() {
  30 + @Override
  31 + public void beforeTextChanged(CharSequence s, int start, int count, int after) {
  32 + }
  33 +
  34 + @Override
  35 + public void onTextChanged(CharSequence s, int start, int before, int count) {
  36 +
  37 + if(s.toString().trim().length() != 0){
  38 + for (View child : allChildren) {
  39 + if (child instanceof Button) {
  40 + Button bouton = (Button) child;
  41 + bouton.setEnabled(false);
  42 + }
  43 + }
  44 + }
  45 + else{
  46 + for (View child : allChildren) {
  47 + if (child instanceof Button) {
  48 + Button bouton = (Button) child;
  49 + bouton.setEnabled(true);
  50 + }
  51 + }
  52 + }
  53 +
  54 + }
  55 +
  56 + @Override
  57 + public void afterTextChanged(Editable s) {
  58 +
  59 + }
  60 + });
  61 +
22 return v; 62 return v;
23 } 63 }
  64 +
  65 + private ArrayList<View> getAllChildren(View v) {
  66 +
  67 + if (!(v instanceof ViewGroup)) {
  68 + ArrayList<View> viewArrayList = new ArrayList<View>();
  69 + viewArrayList.add(v);
  70 + return viewArrayList;
  71 + }
  72 +
  73 + ArrayList<View> result = new ArrayList<View>();
  74 +
  75 + ViewGroup vg = (ViewGroup) v;
  76 + for (int i = 0; i < vg.getChildCount(); i++) {
  77 +
  78 + View child = vg.getChildAt(i);
  79 +
  80 + ArrayList<View> viewArrayList = new ArrayList<View>();
  81 + viewArrayList.add(v);
  82 + viewArrayList.addAll(getAllChildren(child));
  83 +
  84 + result.addAll(viewArrayList);
  85 + }
  86 + return result;
  87 + }
24 } 88 }
25 \ No newline at end of file 89 \ No newline at end of file