开发者

value/strings.xml vs. layout/*.xml

Can anybody e开发者_运维知识库nlighten 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.


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.


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() method 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;
   };


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜