title: How can I program this UI to be smoother?
body: <p>I collect data from a loop here:</p>
  
  <pre><code>public void loop() throws ConnectionLostException, InterruptedException {
  
          led_.write(false);
  
          setCurrentAIVoltage0(AI0.getVoltage());
          setCurrentAIVoltage1(AI1.getVoltage());
          setCurrentAIVoltage2(AI2.getVoltage());
          setCurrentAIVoltage3(AI3.getVoltage());
          setCurrentAIVoltage4(AI4.getVoltage());
          setCurrentAIVoltage5(AI5.getVoltage());
          AIF.updateUI();
      }
  </code></pre>
  
  <p>Where <code>currentAIVoltage0</code> through <code>currentAIVoltage5</code> are all public float variables.
  and my <code>updateUI</code> method is a method in my <code>Fragment</code>, <code>AIF</code>.</p>
  
  <p><code>AIF</code> however tends to be slow using this approach; and the AI updates irregularly.</p>
  
  <p>Here is my <code>updateUI</code> method in my class file for my object <code>AIF</code>:</p>
  
  <pre><code>    public void updateUI(){
  
           getActivity().runOnUiThread(new Runnable() 
              {
                   @Override
                  public void run() {
                      // TODO Auto-generated method stub
                      AITVVOLT0.setText("Voltage is: " + getCurrentAIVoltage0());
                      AITVVOLT1.setText("Voltage is: " + getCurrentAIVoltage1());
                      AITVVOLT2.setText("Voltage is: " + getCurrentAIVoltage2());
                      AITVVOLT3.setText("Voltage is: " + getCurrentAIVoltage3());
                      AITVVOLT4.setText("Voltage is: " + getCurrentAIVoltage4());
                      AITVVOLT5.setText("Voltage is: " + getCurrentAIVoltage5());
                      AIVOLTBAR0.setProgress(Math.round(getCurrentAIVoltage0()*100));
                      AIVOLTBAR1.setProgress(Math.round(getCurrentAIVoltage1()*100));
                      AIVOLTBAR2.setProgress(Math.round(getCurrentAIVoltage2()*100));
                      AIVOLTBAR3.setProgress(Math.round(getCurrentAIVoltage3()*100));
                      AIVOLTBAR4.setProgress(Math.round(getCurrentAIVoltage4()*100));
                      AIVOLTBAR5.setProgress(Math.round(getCurrentAIVoltage5()*100));
                  }
               }
             );  
          }
  </code></pre>
  
  <p>Full Fragment:</p>
  
  <pre><code>public static class AnalogInputFragment extends Fragment {
      public TextView AITVVOLT0;
      public TextView AITVVOLT1;
      public TextView AITVVOLT2;
      public TextView AITVVOLT3;
      public TextView AITVVOLT4;
      public TextView AITVVOLT5;
  
      public ProgressBar AIVOLTBAR0;
      public ProgressBar AIVOLTBAR1;
      public ProgressBar AIVOLTBAR2;
      public ProgressBar AIVOLTBAR3;
      public ProgressBar AIVOLTBAR4;
      public ProgressBar AIVOLTBAR5;
  
      public static AnalogInputFragment newInstance() {
          AnalogInputFragment fragment = new AnalogInputFragment();
          return fragment;
      }
  
      public AnalogInputFragment() {
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.analogin_fragment,
                  container, false);
          AITVVOLT0 = (TextView) rootView.findViewById(R.id.aintvvolt0);
          AITVVOLT1 = (TextView) rootView.findViewById(R.id.aintvvolt1);
          AITVVOLT2 = (TextView) rootView.findViewById(R.id.aintvvolt2);
          AITVVOLT3 = (TextView) rootView.findViewById(R.id.aintvvolt3);
          AITVVOLT4 = (TextView) rootView.findViewById(R.id.aintvvolt4);
          AITVVOLT5 = (TextView) rootView.findViewById(R.id.aintvvolt5);
  
  
          AIVOLTBAR0 = (ProgressBar) rootView.findViewById(R.id.aintvvoltbar0);
          AIVOLTBAR1 = (ProgressBar) rootView.findViewById(R.id.aintvvoltbar1);
          AIVOLTBAR2 = (ProgressBar) rootView.findViewById(R.id.aintvvoltbar2);
          AIVOLTBAR3 = (ProgressBar) rootView.findViewById(R.id.aintvvoltbar3);
          AIVOLTBAR4 = (ProgressBar) rootView.findViewById(R.id.aintvvoltbar4);
          AIVOLTBAR5 = (ProgressBar) rootView.findViewById(R.id.aintvvoltbar5);
  
          AITVVOLT0.setText("Voltage is: " + currentAIVoltage0);
          AITVVOLT1.setText("Voltage is: " + currentAIVoltage1);
          AITVVOLT2.setText("Voltage is: " + currentAIVoltage2);
          AITVVOLT3.setText("Voltage is: " + currentAIVoltage3);
          AITVVOLT4.setText("Voltage is: " + currentAIVoltage4);
          AITVVOLT5.setText("Voltage is: " + currentAIVoltage5);
  
          AIVOLTBAR0.setMax(330);
          AIVOLTBAR1.setMax(330);
          AIVOLTBAR2.setMax(330);
          AIVOLTBAR3.setMax(330);
          AIVOLTBAR4.setMax(330);
          AIVOLTBAR5.setMax(330);
  
          AIVOLTBAR0.setProgress(0);
          AIVOLTBAR1.setProgress(0);
          AIVOLTBAR2.setProgress(0);
          AIVOLTBAR3.setProgress(0);
          AIVOLTBAR4.setProgress(0);
          AIVOLTBAR5.setProgress(0);
          return rootView;
      }
      public void updateUI(){
  
           getActivity().runOnUiThread(new Runnable() 
              {
                   @Override
                  public void run() {
                      // TODO Auto-generated method stub
  
                      AITVVOLT0.setText("Voltage is: " + getCurrentAIVoltage0());
                      AITVVOLT1.setText("Voltage is: " + getCurrentAIVoltage1());
                      AITVVOLT2.setText("Voltage is: " + getCurrentAIVoltage2());
                      AITVVOLT3.setText("Voltage is: " + getCurrentAIVoltage3());
                      AITVVOLT4.setText("Voltage is: " + getCurrentAIVoltage4());
                      AITVVOLT5.setText("Voltage is: " + getCurrentAIVoltage5());
                      AIVOLTBAR0.setProgress(Math.round(getCurrentAIVoltage0()*100));
                      AIVOLTBAR1.setProgress(Math.round(getCurrentAIVoltage1()*100));
                      AIVOLTBAR2.setProgress(Math.round(getCurrentAIVoltage2()*100));
                      AIVOLTBAR3.setProgress(Math.round(getCurrentAIVoltage3()*100));
                      AIVOLTBAR4.setProgress(Math.round(getCurrentAIVoltage4()*100));
                      AIVOLTBAR5.setProgress(Math.round(getCurrentAIVoltage5()*100));
                  }
               }
             );  
          }
  }
  </code></pre>