Android的:如何在strings.xml中的字符串数组得到项目的属性 [英] android: How to get item's attributes from its string-array in strings.xml

查看:421
本文介绍了Android的:如何在strings.xml中的字符串数组得到项目的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我爸爸喜欢看他的电影,他有很多。他保持光盘在几个粘合剂,但也没有编目所有的系统。

My dad likes to watch his movies and he has a lot of them. He keeps his discs in several binders but there is no system of cataloging at all.

我想我会做一个Android应用程序,以帮助他找到他们。

I thought I'd make an android app to help him find them

所以我想ID存储中的信息在strings.xml中的字符串数组

So i thought id store the information in a string array in strings.xml

        <?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Hello World, MovieFinderActivity!</string>
    <string name="app_name">MovieFinder</string>
    <string name="movie_prompt">Choose Movie</string>
    <string-array name="all_movies_array">
        <item binder="1" page="1">Star Wars Episode 1: The Phantom Menace</item>
        <item binder="1" page="1">Star Wars Episode 2: Attack of the Clones</item>
        <item binder="1" page="1">Star Wars Episode 3: Revenge of the Sith</item>
        <item binder="1" page="1">Star Wars Episode 4: A New Hope</item>
        <item binder="1" page="2">Star Wars Episode 5: The Empire Strikes Back</item>
        <item binder="1" page="2">Star Wars Episode 6: Return of the Jedi</item>
        <item binder="1" page="2">Dr Zhivago Side A</item>
        <item binder="1" page="2">Dr Zhivago Side B</item>    

    </string-array>

</resources>

那么我这样做

    movie_spinner = (Spinner) findViewById(R.id.search_movie_spinner);
    movie_spinner.setAdapter(adapter2);
    movie_spinner.setOnItemSelectedListener((OnItemSelectedListener) this);

和这个被这里叫做

    public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {

    //movie_title is a textview
    movie_title.setText( movie_spinner.getSelectedItem() + "");

}

所以每当一部电影的微调被选中的MOVIE_TITLE更改影片的名字的TextView

so whenever a movie gets selected in the spinner, the TextView of movie_title changes to the movie's name

我想知道的是如何从节点检索粘合剂和页面的属性的项目

What i want to know is how to retrieve the attributes of binder and page from the node item

推荐答案

据我所知,你是不是能够得到属性的资源字符串数组值。

AFAIK, you are not able to get attribute values for the resources string array.

我看到它的方式是,你可以有如下选择

The way I see it is that you can have the following options


  1. 与您的数据创建一个XML文件作为谢里夫提及。
    例如,

  1. Create an xml file with you data as sherif mentioned. Eg,

<movies>
   <item binder="1" page="1">Star Wars Episode 1: The Phantom Menace</item>
   <item binder="1" page="1">Star Wars Episode 2: Attack of the Clones</item>
   <item binder="1" page="1">Star Wars Episode 3: Revenge of the Sith</item>
   <item binder="1" page="1">Star Wars Episode 4: A New Hope</item>
   <item binder="1" page="2">Star Wars Episode 5: The Empire Strikes Back</item>
</movies>

您可以使用任何F中的avaliable解析器如DOM,SAX解析这个并创建你选择的ArrayList或对象。

You could use any f the avaliable parsers like DOM,SAX to parse this and create an arraylist or object of your choice.

创建JSON数据,而不是XML和使用GSON解析到一个可用的对象。

Create json data instead of xml and use GSON to parse to to a usable object.

这篇关于Android的:如何在strings.xml中的字符串数组得到项目的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆