Android:HashMap不支持换行符

时间:2014-04-03 06:24:05

标签: android android-listview

我开发了一个应用程序。对于说明页面,我创建了一个可扩展列表视图。父代表应用程序主屏幕中的每个按钮,子代码包含按下相应父按钮时所发生情况的详细信息。

我的可扩展列表视图基于HashMap概念。我用ExpandableListActivity扩展了我的班级。在onCreate方法中我定义了一个SimpleExpandableListAdapter,如下所示:

SimpleExpandableListAdapter expListAdapter=
                new SimpleExpandableListAdapter(
                        this,
                        createGroupList(),
                        R.layout.group_row,
                        new String[] { "parent" },
                        new int[] { R.id.row_name },
                        createChildList(),
                        R.layout.child_row,
                        new String[] {"Sub Item"},
                        new int[] { R.id.grp_child}

                        );
        setListAdapter(expListAdapter);

createGroupList()createChildList()的定义如下所示:

public List createGroupList()
{
     ArrayList result = new ArrayList();
     for(int i=0;i<5;i++)
     {
        HashMap m=new HashMap();
        if(i==0)
            m.put("parent","Start Rec");
        else if(i==1)
            m.put("parent","automated Rec");
        result.add( m );
     }
     return (List)result;
}

public List createChildList()
    {
        ArrayList result = new ArrayList();

        for(int i=0;i<5;i++)
        {
            ArrayList secList = new ArrayList();
            for(int j=0;j<1;j++)
            {   
                HashMap child = new HashMap();
                if(i==0)
                {
                    if(j==0)
                    {
                        child.put( "Sub Item", "In this Mode\n user can start recording a video without a preview.\n\nSteps:\n1)Click on the \"Start Rec\" Button. 2) Once the button is clicked, the color and text message on the button change and the recording gets started in the background.\n3)The User should now Minimize the App using the Home Button and can continue recording.\n4)Inorder to stop recording the user should can Mazimize the minimized App and press on the \"Stop Rec\" Button to stop recording."); 
                        secList.add( child );
                    }
                }
                else if(i==1)
                {
                    if(j==0)
                    {
                        child.put( "Sub Item", "\\Multiple lines of exp here"); 
                        secList.add( child );
                    }                       
                }

            result.add( secList );
        }
        return result;      
    }

现在,在上面的例子中,在&#34; Sub Item&#34; HashMap,一旦遇到&#34; \ n&#34; 新行字符,我就不会收到任何文字。如果没有\ n,我只得到单行显示,只显示消息的一部分/一行,另一部分隐藏/不可见。

任何帮助,这对我都非常有帮助。

提前致谢。

0 个答案:

没有答案