Solution 1 :
listView = (ListView) findViewById(R.id.listviewID);
Forgot to add this.
Problem :
I want to be able to store the contents of the editText input, then be able to display it in a listview.
I have connected a RFID device that is set in emulator mode. This mode basically also you to scan an RFID tag and the RFID number gets populated where ever the mouse cursor is. In this case it is at the editText input. The lenght of the RFID number is 10, since the RFID number as 10 digits. Once the RFID number is detected I then want to display it on the listview and scan another tag and add that to the listview also.
In my case whenever I code sees the display method the app crashes and I dont know why. Can someone explain to me why this is happening?
epc.add("n" + etRfidNo.getText().toString() + ", " + DateFormat.getInstance().format(currentDate));
display();```
MainActivity code:
public class MainActivity extends AppCompatActivity {
EditText etRfidNo;
TextView textView;
private Set<String> epc = new HashSet<>();
ArrayAdapter<String> contactAdapter;
String single_epc;
Button scan;
ListView listView;
boolean set = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = (TextView)findViewById(R.id.textView);
etRfidNo = (EditText) findViewById(R.id.etRfidNo);
scan = (Button) findViewById(R.id.scan);
TextView textV = (TextView)findViewById(R.id.textView);
etRfidNo.addTextChangedListener(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) {
//TextView textV = (TextView)findViewById(R.id.textView);
//textV.setText(s); //set text for text view
single_epc = String.valueOf(s);
if(s.length() == 10)
{
Date currentDate = new Date();
epc.add("n" + etRfidNo.getText().toString() + ", " + DateFormat.getInstance().format(currentDate));
display();
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
public void display() {
contactAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, new ArrayList<>(epc));
listView.setAdapter(contactAdapter);
}
}
Comments
Comment posted by esQmo_
You need to open the logcat and you’ll find what is causing the app to crash