How to get textview string from inside recyclerview - android

Recyclerview contain cardlayout text1,text2 (id) two textviews.i want get text1 string value .if i touched one card.(touchlistner).how to print text1 string.i tried many nothing worked .

If you have the position of your recyclerView list item. you can find the view with
TextView text1 = yourRecyclerView.findViewHolderForAdapterPosition(position).itemView.findViewById(R.id.text1);
and then get textView string.
String text1Str = text1.getText().toString();
System.out.println("my textView string : " + text1Str);

Related

Textview declaration using a variable String

Is it possible declare many diferent TextView. Like tv_concept1, tv_concept2, tv_concept3... and so on.
Using a variable string? If the string is "1" it would declare tv_concept1. So it will change the tv_concept1 text to Hi. But if the variable is it 2 then other TextView will do it.
String textview = "tv_concept" + value;
TextView textview = findViewById(R.id.textview);
textview.setText("Hi");```
You could use an array of your object.

Android Studio TextView format one String center

Hello I got two Strings and a TextView:
TextView test = (TextView) findViewById(R.id.eins);
String one = "DynamicText";
String two = "Title";
test.setText(two+one);
Now I would to set the two Strings in one TextView but I like to formate the String two text align to center and the String one normal (left). How is this possible?
TextView txtOne = (TextView) findViewById(R.id.txtOne );
TextView txtTwo = (TextView) findViewById(R.id.txtOne);
textOne.setText("DynamicText");
txtTwo.setText("Title");
txtTwo.setGravity(Gravity.CENTER);

How to Show data from String Array ,in Single Android textview with cross image Each line contains Two Strings

1.I am getting data from server storing inside string Array.
2.then i want to show in Android TextView ,each TextView line should Contain 2 strings(Like Skill Sets) from String array.
3.then need to add cross Image in right side of the Textview.
please help me, how to achieve this.
String mystring = "This is my first sentence";
String arr[] = mystring.split(" ", 3);
String firstWord = arr[0]; //This
String secondWord = arr[1]; //is
String theRest = arr[2]; //my first sentence
yourtextview.setText(firstWord +" "+ secondWord);
and regarding for Image in right side of the Textview put this in ur txtview'sxml.
android:drawableRight="#drawable/image"

Android spinner get text after comma

In my android application I am using spinner for selecting data.. and I created string array for strings that to be displayed in spinner. I put all the details in strings folder. I wanted the selected text t be displayed in edit text once the user selected item..
For example : spinner is used to select country codes suppose user selected USA
then the selected text will be like this
United States of America,+001
I don't need t take all the text and display it in edit text. I need only the text after comma, that is +001. So is there any way to get the text after the comma only
Spinner spinner = (Spinner)findViewById(R.id.spinner);
String text = spinner.getSelectedItem().toString();
I know this will display all text I want only text that dislpaying after comma
You can split your text on the comma:
String text = spinner.getSelectedItem().toString();
String[] splited_text = text.split(",");
text = splited_text[1];
Suppose the text is in a string name text. use this:
String[] temp = text.split(",")
String code = temp[1]; //+001 the code after , temp[0] contains the rest
String seperated[] = spinner.getSelectedItem().toString().split(",");
text = seperated[1];
This will return only "+001".
String code = text.substring(text.indexOf(','));
This is how to get string after last comma:
String founded;
Pattern p = Pattern.compile(".*,\\s*(.*)");
String dd = (String) "Your string, really, really2";
Matcher m = p.matcher(dd);
if (m.find()) {
founded = m.group(1); //returns "really2"
}

Grab TextView (in a ListVIew Row ) from ContextMenu

I know to get a string of a specific TextView in a ListView, I can do this:
ReviewUser = ((TextView) rowView.findViewById(R.id.labelUser))
.getText().toString();
What if I want to get the TextView itself?
The TextView is an integer and I simply want to get the TextView and add 1 to it.
So you already specified that you know how to get the specific text from your ListView. Since you want to modify that same TextView, the rest is simple. This code is lengthier just to show the steps.
TextView textView = (TextView) rowView.findViewById(R.id.labelUser)
String text = textView.getText().toString();
int num = Integer.valueOf (text).intValue() + 1;
textView.setText (""+num);
Also, if you are working with a String ArrayAdapter and you know the index of the row you want to modify, what you can do is (assuming arrayAdapter is initialized and index is your index variable):
String text = arrayAdapter.get(index);
arrayAdapter.remove (text);
arrayAdapter.insert ((Integer.valueOf (text).intValue() + 1 ) + "", index);

Categories

Resources