可序列化对象到 Hashmap 的 Arraylist [英] Serializable object to Arraylist of Hashmap

查看:49
本文介绍了可序列化对象到 Hashmap 的 Arraylist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 android 应用程序,我在列表视图中显示联系人的所有姓名.

I am developing an android application, where I display all the names of the contact in a Listview.

单击联系人列表视图,我需要在另一个列表视图中显示该联系人的相应号码.

Onclick of the contact Listview,I need to display the respective numbers of that Contact in another Listview.

这里的问题是,我将所有数字捆绑在一起,然后向它发送了另一个活动,也收到了捆绑包,但收到的捆绑包是可序列化的对象.

The problem here is, I bundled all the numbers and sent it another activity and also received the bundle, but the received bundle is Serializable object.

因此,要在 Listview 中显示,我需要将其转换为 Hashmap 的 Arraylist.我怎样才能做到这一点?

So, to dispaly in the Listview I need to convert it to the Arraylist of Hashmap. How can I do this?

代码如下:

发送活动:

HashMap<String, String> Numbermap = new HashMap<String, String>();

Numbermap.put("numb",number);
Numbermap.put("type",type);

NumberList.add(Numbermap);

Intent intent = new Intent (ContactNames.this,ContactsPhoneNumbers.class);

intent.putExtra("map", NumberList);


startActivity(intent);

接收活动:

    Serializable Numbermap = new HashMap<String, String>();

    //  contNum = (TextView)findViewById(R.id.ContactNumber);

    Bundle bundle = getIntent().getExtras();

    Intent intent = getIntent();

    if(bundle!=null)
    {
        Numbermap = bundle.getSerializable("map");
    }

推荐答案

你用键map"放入意图中,对象NumberListArrayList 我想.但是在您的活动 ContactsPhoneNumbers 中,您尝试使用键映射"一个 HashMap 实例,这是不正确的.

You put into the intent with the key "map", the object NumberList which is an instance of ArrayList I think. But in your activity ContactsPhoneNumbers, you try to get with the key "map" an instance of HashMap, which is not correct.

这是你应该做的:

ArrayList<HashMap<String, String>> numberList = null;
Bundle bundle = getIntent().getExtras();
Intent intent = getIntent();
if(bundle!=null)
{
    numberList = (ArrayList<HashMap<String, String>>) bundle.getSerializable("map");
}

这篇关于可序列化对象到 Hashmap 的 Arraylist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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