tags:

views:

117

answers:

3

Can anybody enlighten me why value/strings.xml is useful(important)? It occurred to me that all the attributes, e.g., id, label can be set in the layout xml as well. So why strings.xml?

A side question is, once get an ID of an object, say a listitem, how do I get the android:text from it? I did not find any getText() function.

+8  A: 

It allows for easily providing alternate languages and configurations. See the Resources and Internationalization topic (especially the Alternate Resources section) in the Dev Guide for more information.

For your second question, you may be looking for resolveInfo.nonLocalizedLabel or resolveInfo.loadLabel(getPackageManager())?

The reference page for ResolveInfo should help you find what you want.

jball
+1  A: 

To answer your 2nd question, you can use findViewById in your activity to get the View class. From the view class you can call getText().

To access views of list items in a ListView, override the getView function in your adapter. For example:

new SimpleAdapter(Activity.this, model, R.layout.my_layout, from, to) {

   public View getView(int position, View convertView, android.view.ViewGroup parent) {

        View view = super.getView(position, convertView, parent);

        View myView = findById(R.id.my_id); //< Access your view here!

        return view;
   };
Mayra
How might this work with a ListItem per the question?
jball
See my edit for an example
Mayra
+1  A: 

For your second question:

If your id is R.id.editText1, then you need to get the EditText control first,

EditText editText1 = (EditText) findViewById(R.id.editText1);

Then you can call the getText() method.

editText1.getText();
yuku
Same comment as I left for Mayra's answer, how might this work for a ListItem?
jball