I am writing an application that uses an externally connected USB barcode / RFID scanner. The data that is scanned is βcompositeβ data. Here is an example:
=+03000=W12560712345600=%2800&>0090452359
This is from scanning complex data. The separator in the data is the equal sign (=) or ampersand (&). The first bit =+03000
says that there are three pieces of data in the scan:
=W12560712345600
=%2800
&>0090452359
This data may contain any number of pieces of data from one to N.
In my Android app, I have a form with three elements EditText
. What I need to do with this composite scanned data is to split it with delimiters and insert each piece of data into the correct field EditText
.
, stdin TextWatcher
EditText
, .
, , . :
activity_main.xml
<LinearLayout>
<TextView />
<EditText android:id="@+id/datafield01" />
<EditText android:id="@+id/datafield02" />
<EditText android:id="@+id/datafield03" />
<Button />
</LinearLayout>
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText dataField01 = (EditText)findViewById(R.id.datafield01);
EditText dataField02 = (EditText)findViewById(R.id.datafield02);
EditText dataField02 = (EditText)findViewById(R.id.datafield03);
dataField01.addTextChangedListener(editTextWatcher);
}
TextWatcher editTextWatcher = new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after){
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count){
}
@Override
public void afterTextChanged(CharSequence s){
}
};
}
CharSequence
StringBuffer
- before, on afterTextChanged - EditText
, .
MainActivity.java
public class MainActivity extends AppCompatActivity {
private StringBuffer stringBuffer;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
stringBuffer = new StringBuffer();
EditText dataField01 = (EditText)findViewById(R.id.datafield01);
EditText dataField02 = (EditText)findViewById(R.id.datafield02);
EditText dataField02 = (EditText)findViewById(R.id.datafield03);
dataField01.addTextChangedListener(editTextWatcher);
System.out.println(stringBuffer.toString());
}
TextWatcher editTextWatcher = new TextWatcher(){
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after){
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count){
stringBuffer.append(s);
}
@Override
public void afterTextChanged(CharSequence s){
}
};
}
, System.out.println(stringbuffer);
, .
, , N, .
, - , Google .
, , , ?
.