【问题标题】:How to make a list view from an array with multiple information attached to it?如何从附加了多个信息的数组中创建列表视图?
【发布时间】:2011-12-02 19:42:28
【问题描述】:

我对安卓很陌生。我的项目要求我创建一个列表视图,并根据用户的选择更改其他视图中的多条数据。所以,假设我从列表中选择一个人的名字。我想更改一个 ImageButton 图像、一个 TextView,并为那个特定的人连接一个数组。我一直在对用户选择的字符串进行文本处理,并确保我的资源与某种格式匹配。但是,我觉得应该有更好的方法。如果你还不能说,我对编程也很陌生。

我正在寻找最简单但有点有效的解决方案。

编辑:这是一些代码 WRT 一个带有名为 people 的数组的列表:

// Handles User Selection of People

    peopleList.setOnItemClickListener( new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    // Get Selection String
    person1SavedText = people[position];

    // Modify String to match corresponding resources and values
    String people1ImageParsed = person1SavedText.toLowerCase().replace(" ", "").replace("-", "");

    // Person 1 Image Uri/String
    person1ImageUriString = "android.resource://org.example.person/drawable/" + person1ImageParsed;
    person1ImagePath = Uri.parse(person1ImageUriString);

    // Person 1 Array Uri/String
    person1ArrayUriString = "android.resource://org.example.person/values/" +     person1ImageParsed;
    }
}

【问题讨论】:

  • 另外我知道你需要查看 Android 教程以从这两个 http://developer.android.com/resources/tutorials/hello-world.htmlhttp://developer.android.com/resources/tutorials/notepad/index.html 开始

标签: android listview object arraylist


【解决方案1】:

听起来您需要根据选择存储临时信息,然后根据该选择查找数据,对吗?我会使用内置的 android 首选项来存储选定的项目索引(或其他识别方式),然后根据存储在首选项中的值查找 ImageButton 图像、文本视图等。如果设置正确,这些首选项可用于应用程序的所有内容。

共享首选项详情:http://developer.android.com/guide/topics/data/data-storage.html#pref

谷歌“android sharedPreferences examples”以获得更多帮助。

最好的!

【讨论】:

    猜你喜欢
    • 2013-05-17
    • 1970-01-01
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    • 2019-10-18
    • 1970-01-01
    • 2019-06-14
    • 1970-01-01
    相关资源
    最近更新 更多