How to translate ListView texts? - java

My android application includes ListView binded with SimpleCursorAdapter to the database. This database contains column, which contains data like
somenameofrow
anothername
thirdname
However instead of directly displaying these texts in the ListView, I would like to read according texts (actually - translations) from the Android resources.
How should I do it?
I think that I can use setViewValue for the same, name in the code below is TextView item, which displays my text:
case R.id.name:
TextView elName = (TextView) view;
elName.setText(getApplicationContext().getString(R.string.));
return true;
I am not sure how to understand what is correct id of the resource I am looking for (probably, cursor.getString(columnIndex) or elName.getText()) and how to get the value?
Upd. What if I exclude names from the database and will use ids instead. Will it help?

If you read the android guide ListView tutorial, you will find:
Note that using a hard-coded string array is not the best design practice. One is used in this tutorial for simplicity, in order to demonstrate the ListView widget. The better practice is to reference a string array defined by an external resource, such as with a resource in your project res/values/strings.xml file
Simply create different string-arrays items in res/values-XX, where XX are the locales you want to translate.
See the dev guide for more details about resources and i18n: http://developer.android.com/guide/topics/resources/localization.html

No you can't, since id's are generated in some basically sem-random way during compilation, so you can't be sure which id will have specific String resource.
I would suggest to use translation from DB or you can read translations from assets

Related

Listview vs TableView in Android Studio

I need to recreate this table in my app: https://imgur.com/a/1HtpFqO
The third field must be editable by the user, so I don't know if I should prefer ListView for this reason. What do you think?
Also, do you know if are there existing library to create this exactly design?
That depends whether your table holds data that will change or you will always have the same table with editable third field. If you have static data you don't really need to have a list.
If you have data that changes, RecyclerView is your go to option. Create it with different ViewHolder types, one type for non-editable fields and the other for editable field.
Also, there is no need to add 3rd party library just to achieve this simple table.
You can use Recyclerview with different views Like this and this

Is there a way to create the stackoverfow "Tags" EditText/Input field in Android?

I want to know If there is a way to create a EditText like the stackoverflow EditText in Android:
Questions:
How is this called? so I can search it on google
Is there any library out there already?
If there isn't, where should I start with making one myself?
I found it by searching "android tag editor textview" and I came along this: http://www.kpbird.com/2013/02/android-chips-edittext-token-edittext.html
So Stackoverflow tags field is Chips EditText in Android.
You have to make a Database that will listen to the keys events and using pattern matching, fetch out the data from database.
When you select the data, the data will be stored in a button or whatever.

how to get rid of html in jsoup and only extract html table content?

So I'm trying to access the table in this website http://www.engin.umich.edu/htbin/wwwhostinfo?detail=0&display=all&sort=open and trying to make it into an Elements object. I only need the first and fourth columns . So I'm using jsoup and doing this :
Document doc = Jsoup.connect("http://www.engin.umich.edu/htbin/wwwhostinfo?detail=0&display=all&sort=open").get();
Elements buildings = doc.select("td:eq(0),td:eq(3)");
This should select the first and fourth columns. It is doing that but with all the html data as well
I need to skip all the initial stuff in the webpage "The following report ... ". And I only need the two columns - Building and Open so that I can simply initialize extra variables and assign the number of open computers in a building to it and finally use Toast or something similar to display the number of open computers in a building on the screen.
Currently I'm using a TextView to show data and its showing me all the html data I don't want as well.
TextView tv = new TextView(this);
tv.setText(""+buildings);
setContentView(tv);
Can Individual values be extracted from Elements ?
in short: How to extract only building names and No. of Open computers by skipping ALL other data and assign them to their own variables?
Any ideas on how to do this?.
Thanks in Advance - a.v.
you could use the JSOUP Cleaner & Whitelist for that task.
Just define what shall not be removed and you're good to go!

how to use more element in listview?

i m new to android .
i m doing my final yr project in android.
Is the any way to use more elements in list view control....
for example: fetch more data frm database and add it at runtime.
the formate may be
text text
text text
text text
text text
etc.....
refer this page for model https://play.google.com/store/apps/details?id=app.diaryfree&feature=search_result#?t=W251bGwsMSwxLDEsImFwcC5kaWFyeWZyZWUiXQ..
(in this page sample image for that application wil be given, like that report i need to display my data.)
is any other control there for that??? how to add runtime more assign more than one element value???
like this
and how to find which row is clicked?
thankz in advance
you can create custom list views to format the listview the way you asked for. And cursors are a good way to fetch data from a database and pass it to a listview. you can use adapters for that.
a sample code for custom list view can be seen here
to find out which item is clicked you need to use onListItemClickListener like given here Android: onListItemClick in Activity

Question about creating GUIS "dynamically" on Android

I'm trying to make an android app (I'm new in the Android programming world), and I'm having problems creating the GUI.
The point is that I get information of some data that is divided in days... The problem is that I don't know, until I retrieve the information, how many days the GUI should display.
http://img574.imageshack.us/img574/3787/mainscreen.jpg
The grey part will be a TextView, and, also, the black part will be another TextView with multiple lines.
So, the point is, how can I do to have multiple TextView's without knowing before the exact number? I suppose that I can't declare them in the layout.xml
The only solution that I've been thinking about is to create in the layout 7 pairs of TextView and, when I know the exact number, just use what I have to, and don't use the others... (It's a bad solution)
What do you suggest?
Thank you for your answers!
You should create a ListView, which inflates TextView for the items you have.
You can use this example of how to create sectioned ListView, which will look exactly like you want.
I'm not familiar with Android, so other people may offer better, more specific advice.
In the environments I'm familiar with, the problem of displaying an unknown number of items is solved by using not a series of display elements for each data item but a list control. The list component will display as many items as you give it, and can usually be modified to have different appearance for different data, so you're flexible in making it as pretty as you want.
Well you can consider this one also,
Create a table layout in XML, give it a id: TableLayout table=(TableLayout)findViewById(r.id. ....)
Create dynamic TextViews using: TextView day=new TextView(this); day.setText(day name);
Now add this text view to your table layout : table.addView(day);
Run the code for textView creation and addition to table in loop
Hope this helps...............

Categories