Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>After looking into listview I couldnt get them to work with the edittext so I went back to my tablelayout and this is the final working version.</p> <p>Here I create the fields and a textwatcher added to the edittext to watch for changes:</p> <pre><code> TableLayout tL = (TableLayout)findViewById(R.id.tableLayout1); // creates all the fields for(int i = 1; i &lt;= numOfInjWells; i++) { TableRow tR = new TableRow(this); // creates the textView TextView tV1 = new TextView(this); tV1.setText(" " + i + ": "); // add edit text eT = new EditText(this); eT.setInputType(InputType.TYPE_CLASS_NUMBER); eT.setWidth(100); eT.setId(1000 + i); eT.addTextChangedListener(new CustomTextWatcher(eT)); tV2 = new TextView(this); tV2.setText(""); tV2.setId(2000 + i); // add the TextView and the editText to the new TableRow tR.addView(tV1); tR.addView(eT); tR.addView(tV2); // add the TableRow to the TableLayout tL.addView(tR,new TableLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); } // end for statement </code></pre> <p>next I created this class for my customtextwachter:</p> <pre><code>private class CustomTextWatcher implements TextWatcher { private EditText mEditText; public CustomTextWatcher(EditText eT) { mEditText = eT; } public void beforeTextChanged(CharSequence s, int start, int count, int after) { } public void onTextChanged(CharSequence s, int start, int before, int count) { } public void afterTextChanged(Editable s) { // gets the change amount for each meter reading from the previous reading // this method does the work getMeterChange(); } } // end class CustomTextWatcher </code></pre> <p>the getMeterChange() method does the work:</p> <pre><code>public void getMeterChange() { int preMeterReading = 0; int mReading = 0; try { cRWLogData.moveToPosition(recordLookUp - 1); preMeterReading = cRWLogData.getInt( 14 + rowChanged); // finds the edittext that has focus View currView = tL.findFocus(); int currentid = tL.findFocus().getId(); // gets the string from the edittext and changes it to a int EditText currentComponent = (EditText) currView; String eTValue = currentComponent.getText().toString(); mReading = Integer.parseInt(eTValue); // calculates difference for what is entered and what is in database mChange = mReading - preMeterReading; // makes the textview in the same tablerow as the edittext active TextView tV2 = (TextView) findViewById(currentid + 1000); // sets the text of the textview tV2.setText(" " + mChange +""); } // end try catch (Exception e) {} } // end getMeterChange </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload