Textview declaration using a variable String - android

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.

Related

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

Unicode to text in java

How can I convert a Unicode string like
"\u0646\u0627\u0645"
to a human-readable string that I can put in a TextView?
No need to do anything more than this
TextView text = (TextView) findViewById(R.id.yourTextView);
text.setText("\u0646\u0627\u0645");

Comparing TextView's getText() w/ R.string.stringValue in android?

Here's my code that's giving me grief.
TextView questionView = (TextView) findViewById(R.id.questionView);
if(questionView.getText().equals(R.string.begginigStatement){
currentQuestionIndex = -2;
Log.d(TAG, "the TextView's text is equal to R.string.beggingStatement);
}
I'm trying to compare a string w/ an int
but I can't figure out the solution other than perhaps hardcoding the string, though I know that's not a proper convention. What's the solution?
R.string.begginigStatement is just an ID of the string as generated in R.class. To retrieve the value call:
getResources().getString(R.string.begginigStatement)
try to use:
context.getResources().getString(R.string.begginigStatement);
and context can be 'getActivity()' if it's in Fragment or just :
getResources().getString(R.string.begginigStatement)
if it has context
You have to compare this string values:
questionView.getText().toString().equal(getResources().getString(R.string.begginigStatement))

Android: java.lang.NumberFormatException: Invalid int: "1.01"

Hi in my app i am reading the values from the database thru cursor and displaying in textview
my cursor contains the value 1.01 now i wanna display 101 in my text view..doing the following
TextView tv2 = (TextView)view.findViewById(R.id.acValue);
int ach = Integer.parseInt(topcursor.getString(6));
tv2.setText(ach +"");
i am getting the float value as 1.01, now i wanna show the percentage in textview i.e, 101% .how can i do that
But iam getting numberformatexception. Any help is appreciated.
1.01 is not an integer value, that is why the conversion is failing. Also be careful with locale when you use the parse* methods
Try this
TextView tv2 = (TextView)view.findViewById(R.id.acValue);
String ach = topcursor.getString(6);
tv2.setText(ach);
There is no need to parse as it returns the string.
TextView tv2 = (TextView)view.findViewById(R.id.acValue);
String mResult = topcursor.getString(6);
tv2.setText(mResult);
Thank You all ...Did as follows it work fine..
float ach = Float.parseFloat(topcursor.getString(6));
String kj = String.valueOf(ach*100+"%");
Using replace() will do the trick
TextView tv2 = (TextView)view.findViewById(R.id.acValue);
int ach = Integer.parseInt(topcursor.getString(6).replace(".", ""));
tv2.setText(ach +"%");

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