开发者

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

开发者 https://www.devze.com 2023-03-31 03:58 出处:网络
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_开发者_Stack
ArrayList<String> matches = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
wordsList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_开发者_StackOverflow1,
                matches));

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


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);


TextView mTextView=new TextView(mContext);
mTextView.setText(matches.get(0).toString()); // Take first element
myLayout.addView(mTextView);
0

精彩评论

暂无评论...
验证码 换一张
取 消