Translating, anuvaad karana or अनुवाद करना - android

When you make translations do you use English Characters or The cultures native characters? So for example would I Put "Anuvaad karana" or "अनुवाद करना" instead of "Translating" when translating into Hindi?
English TextView tv = (TextView) findViewById(R.id.EnglishTxt);
List<String> list = new ArrayList<String>();
list.add("Translating");
Hindi TextView tv = (TextView) findViewById(R.id.HindiTxt);
List<String> list = new ArrayList<String>();
list.add("Anuvaad karana");
HindiC TextView tv = (TextView) findViewById(R.id.HindiCTxt);
List<String> list = new ArrayList<String>();
list.add("अनुवाद करना");
Random rand = new Random();
String random = list.get(rand.nextInt(list.size()));
tv.setText(random);
Thanks in Advance.
P.S The code is just an example it's not actually anything.

I always use the culture's native characters in translation, so the people who will use the app and switch to there own language would understand the context.
for example (good) would be in Arabic جيد

Related

How to create a new "TextView" object,by concatenating two strings?

I want to create a new "TextView" object in "MainActivity" code by concatenating
Two String names. for example:
String s1 = "num";
String s2 = "ber";
String s3 = s1+s2;
TextView s3 = new TextView(this);
How cast s3 to TextView object,so i dont get anyy error,code above?
I mean i want to use s3 as a "TextView" name object.
You would do something like this.
TextView textView = new TextView(this);
textView.setText(s3);
or
TextView s3 = new TextView(this);
s3.setText(s1 + s2);
or programmatically in a loop
for (int i = 0; i < list.size(); i++) {
TextView textView = new TextView(this);
textView.setId(s3); //set textview id, this WILL NOT make it a variable of 'number'
linearLayout.addView(textView);
}
First problem is you declared 2 variables with the same name. Fix it by giving TextView a better name and then as #soldforapp answered already, set the text using the method .setText();
edit:
Wait, so you want to assign the value of the TextView to the string variable s3?
I don't really understand your problem. If so, if your code would look like this (so it runs)
String s1 = "num";
String s2 = "ber";
String s3 = s1+s2;
TextView tv = new TextView(this);
This line will assign the variable s3 the text inside your TextView.
s3 = tv.getText().toString();
Using the same name for the different variable in one scope is not possible in JAVA. (even with different types)
Using StringBuilder is better option than concatenating with + operation, so:
String s1 = "num";
String s2 = "ber";
String concat = new StringBuilder().append(s1).append(s2).toString();
TextView s3 = new TextView(this);
s3.setText(concat);
Edit:
What you want is not as easy as what exists in script languages like PHP but you can do it with reflection with efforts. But there is an easier option with using Map:
Map<String,TextView> map = new HashMap<>();
map.put(concat, new TextView(this));
You can get the TextViews with:
map.get(concat).setText("Your String");

Displaying the sum value of a SQLite query in a textview as currency

I have the sum total of the income column of my database displaying as a double in a textview but I can't get it to display as currency. When I debug, the results show it should display as "$ 10,432.18", but it just shows as "10432.18". Below is what I used in a listview for the individual income items that worked in the listview, but not in the textview:
TextView cmIncomeSumTextView = (TextView) findViewById(R.id.cm_income_sum_text_view);
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setGroupingSeparator(',');
symbols.setDecimalSeparator('.');
DecimalFormat decimalFormat = new DecimalFormat("$ #,###.00", symbols);
String cmIncomeDecimal = decimalFormat.format(cmIncomeSum());
cmIncomeSumTextView.setText(cmIncomeDecimal);
any help would be appreciated!
You can try this instead.
string pattern = "$###,###.###";
DecimalFormat decimalFormat = new DecimalFormat(pattern);
String format = decimalFormat.format(123456789.123);
System.out.println(format);

MPAndroidChart PieChart - set data from plain text input

I'm making an app that I can input name and money and calculate together. Example i input like this in plain text
User 1 = $520
User 2 = $241
User 3 = $253
User 4 = $704
Total = $1718
and here are the id i declared for my plain texts
name1 = (EditText) findViewById(R.id.editName1);
name2 = (EditText) findViewById(R.id.editName2);
name3 = (EditText) findViewById(R.id.editName3);
name4 = (EditText) findViewById(R.id.editName4);
money1 = (EditText) findViewById(R.id.editMoney1);
money2 = (EditText) findViewById(R.id.editMoney2);
money3 = (EditText) findViewById(R.id.editMoney3);
money4 = (EditText) findViewById(R.id.editMoney4);
but how can I set the data from plain text to PieGraph?
Convert the text to numbers (integer, float, ...)
Add them like this:
float number1 = ...; // parse your EditText input here
// other numbers ...
ArrayList<Entry> vals = new ArrayList<Entry>();
vals.add(new Entry(number1, 0));
vals.add(new Entry(number2, 1));
vals.add(new Entry(number3, 2));
vals.add(new Entry(number4, 3));
String[] xVals = new String[] { "User1", "User2", "User3", "User4" };
PieDataSet dataSet = new PieDataSet(vals, "User Values");
PieData data = new PieData(xVals, dataSet);
pieChart.setData(data);
// refresh
pieChart.invalidate();
Also, the example project shows numerous use cases of how data can be added to the charts, you might wanna check it out.
Furthermore, the documentation is pretty good and also gives examples and instructions on how to add data.

Obscure issue with string formatting from SQLite database

I appreciate there's a lot of helpful stack questions and answers to my question but I'm running into problems I've not had in the past.
The Problem:
I am using a cursor to populate textviews in rows on a view (without using listview - that's crazy I know). I am trying to format the string value(s) taken from from the database column STUDENT_POINTS that are put into a textview tpoints. Here is the code I am using:
public void bindView(View v, final Context context, Cursor c) {
final int id = c.getInt(c.getColumnIndex(Students.STUDENT_ID));
final String name = c.getString(c.getColumnIndex(Students.STUDENT_NAME));
final String age = c.getString(c.getColumnIndex(Students.STUDENT_AGE));
final String points = c.getString(c.getColumnIndex(Students.STUDENT_POINTS));
final String teachernote = c.getString(c.getColumnIndex(Students.TEACHERNOTE));
final byte[] image = c.getBlob(c.getColumnIndex(Students.IMAGE));
ImageView iv = (ImageView) v.findViewById(R.id.photo);
if (image != null) {
if (image.length > 3) {
iv.setImageBitmap(BitmapFactory.decodeByteArray(image, 0,image.length));
}
}
TextView tname = (TextView) v.findViewById(R.id.name);
tname.setText(name);
TextView tage = (TextView) v.findViewById(R.id.age);
tage.setText(age);
TextView tpoints = (TextView) v.findViewById(R.id.points);
tpoints.setText(String.format(points, "%1$,.2f"));
final StudentsConnector sqlCon = new StudentsConnector(context);
The rest of bindView is for buttons so I have not included it here. The problem is with the line:
tpoints.setText(String.format(points, "%1$,.2f"));
I'm intending to have commas to separate out large numbers but this does nothing! If anybody has the time could you please tell me what I'm doing wrong?
Thanks in advance.
You have your two parameters backwards-- you should have the format string followed by the data string: String.format("%1$,.2f", points );
This formatted nicely for me with this little snippet in my code:
double points = 56789.45f;
String boogie = String.format("%1$,.2f", points );
and it generated a number 56,789.45
But bigger numbers don't work well due to precision in the formater. You may want to split the mantissa off of their, format them separately and combine them.

Android: adding multiple Views programmatically

I want to add a LinearLayout wrapped around a TextView and Button programmatically. I want it to take a String array and then using the length of the string array, add that many TextViews each with their own button.
So first:
String [] s = { .... the values ....}
int sL = s.length;
TextView t1 = new TextView (this);
// then somehow create t2, t3... etc. matching the length of the String array.
Is this the best way to do this or is there another way to do this? For some context, it's a quiz app and I've created a list of categories inside resources as values and I'm trying to programmatically get my app to create as many TextViews as there are categories then set each TextView to each category then get each button to take the user to that category of questions.
You are starting it right, just do a for loop and add textviews to your linearlayout.
// You linearlayout in which you want your textview
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.mylayout);
linearLayout.setBackgroundColor(Color.TRANSPARENT);
String [] s = { .... the values ....}
int sL = s.length;
TextView textView = null;
// For later use if you'd like
ArrayList<TextView> tViews = new ArrayList<TextView>();
for (int i = 0; i < sL; i++)
{
textView = new TextView(this);
textView.setText(s[i]);
linearLayout.addView(textView);
tViews.add(textView);
}
There is nothing wrong with this way of doing it. If you want to use these textview later on (set text for them or something) store them in an Array of some kind. Edited code
You can do the following:
for(int i=0;i<s.length;i++){
TextView t=new TextView(this);
t.setText(s[i]);
yourLinearLayout.addView(t);
}
But I really think that using a ListView would be better for performance ;)

Categories

Resources