How to assign textview return to a string?

2

I'm new to Android / Java, I wanted to do the following to get the result of a textview that is taken through the barcode scan and play in a string to make a list of results taken by the barcode scan. How do I play the result in a string?

Here is the snippet of code:

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

txResult = (TextView) findViewById(R.id.txResult);

String[] itens = new String[]{"Item 1", "Item 2"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,(itens));

In this way the Listview with item 1 and 2 will display on the screen, I want it to be shown with the return of txResult.

Thank you.

    
asked by anonymous 16.02.2016 / 14:28

1 answer

2

Use the getText() this way :

String texto = txResult.getText().toString();

Because getText() returns a CharSequence , Cast is required to avoid type error, since String is charsequence , but not always the opposite is true .

    
16.02.2016 / 14:36