如何从另一个访问 HashMap class

How to access a HashMap from another class

我目前已经在一个class中创建了一个hash map,如下图:

public static HashMap BasicDetails;

我想从另一个 class 访问它。 我还把来自同一个 class 的值放在 HashMap 被声明为这样的地方:

            BasicDetails.put("currentPersonName", personName);
            BasicDetails.put("currentPersonImage", personPhoto);
            BasicDetails.put("currentPersonGooglePlusProfile", personGooglePlusProfile);

获取检索到的 Google 帐户信息并将其存储到哈希映射中。

现在,在我的第二个 class 中,我想访问它。我不知道从哪里开始,所以我声明了一个名为 nameValue

的 TextView 变量
public TextView nameValue;

然后在我的 onCreate 方法中,我决定将此 nameValue 等同于哈希映射等效值 (currentPersonName):

        nameValue = (TextView) findViewById(R.id.nameValue);
        nameValue.setText(BasicDetails.get("currentPersonName"));

然而 BasicDetails 标记以红色突出显示,指出它未被 class 识别(尽管哈希映射被声明为 public)。我可能还会注意到,在 xml 文件中,我创建了一个空白的 textView 对象,它也具有 id = nameValue。

请帮忙,我们将不胜感激。

编辑 - 找到解决方案

我重新输入了要通过 Intents 传递的数据,很快就会 post 编码

NameOfClassThatContainsMap.MapName.put()

像这样

Class A{
public static HashMap BasicDetails;
}

(在其他地方):

 A.BasicDetails.put("stuff);

要么通过使用静态(不推荐)使信息可用,要么使用某种数据库(可以像文本文件一样简单),要么随您的 Activity 传递 Intent。可以在此处找到有关向 Intent 添加信息的不错教程:http://startandroid.ru/en/lessons/complete-list/241-lesson-28-extras-passing-data-using-intent.html