Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to take the first element of an arrayList and view in a textview

Tags:

android

ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
                matches));

I want to change this code. I want to take the first element of the wordList and show in a text view

like image 432
ece çalıkuş Avatar asked Dec 03 '25 16:12

ece çalıkuş


2 Answers

try this not sure it perfect or not but try it

String text = ((TextView)(wordsList.getItemAtPosition(0))).getText();
yourTextView.setText(text);

or you can get the direct value from the ArrayList

String text = matches.get(0).toString();
yourTextView.setText(text);
like image 177
Pratik Avatar answered Dec 05 '25 06:12

Pratik


TextView mTextView=new TextView(mContext);
mTextView.setText(matches.get(0).toString()); // Take first element
myLayout.addView(mTextView);
like image 31
Mohammad Ersan Avatar answered Dec 05 '25 05:12

Mohammad Ersan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!