Android Listview可以分为两部分吗?

Android Listview可以分为两部分吗?,android,android-listview,Android,Android Listview,我正在制作一个应用程序,它使用列表以如下方式显示员工的详细信息: Name : abcd Age : 28 Phone No : 1234567890. 我设计了2个listview和我的listview(并排,如上所示) 对于第一个列表,我添加了一个arrayadapter,它显示姓名、年龄和电话号码标签。现在我只想知道有没有可能把一个列表分成两部分? 或者我必须创建另一个列表来显

我正在制作一个应用程序,它使用列表以如下方式显示员工的详细信息:

Name                  :   abcd
Age                   :   28
Phone No              :   1234567890.
我设计了2个listview和我的listview(并排,如上所示)


对于第一个列表,我添加了一个arrayadapter,它显示姓名、年龄和电话号码标签。现在我只想知道有没有可能把一个列表分成两部分?
或者我必须创建另一个列表来显示详细信息吗?

您不需要使用两个listview。您必须通过使用适配器使用自定义列表


您必须根据需要设计一个列表元素。

您不需要使用两个listview。您必须通过使用适配器使用自定义列表

必须根据需要设计列表元素。

java:

ListView list = (ListView) findViewById(R.id.some_list);

ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("first", "Name");
map.put("second", ":");
map.put("third", "abcd");
mylist.add(map);
map = new HashMap<String, String>();
map.put("first", "Age");
map.put("second", ":");
map.put("third", "28");
mylist.add(map);

columnAdapter = new SimpleAdapter(this, mylist, R.layout.row,
            new String[] {"first", "second", "third"}, new int[] {R.id.first_cell, R.id.second_cell, R.id.third_cell});
list.setAdapter(columnAdapter);
ListView列表=(ListView)findViewById(R.id.some_列表);
ArrayList mylist=新的ArrayList();
HashMap=newHashMap();
地图放置(“第一”、“名称”);
图.put(第二个“,”:”);
地图放置(“第三”、“abcd”);
添加(地图);
map=新的HashMap();
地图放置(“第一”、“年龄”);
图.put(第二个“,”:”);
地图放置(“第三”、“28”);
添加(地图);
columnAdapter=new SimpleAdapter(this,mylist,R.layout.row,
新字符串[]{“第一”、“第二”、“第三”},新int[]{R.id.first_cell,R.id.second_cell,R.id.third_cell});
list.setAdapter(columnAdapter);
xml1:


xml2:


然后使用一些条件表达式以编程方式填充mylist

ListView list = (ListView) findViewById(R.id.some_list);

ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map = new HashMap<String, String>();
map.put("first", "Name");
map.put("second", ":");
map.put("third", "abcd");
mylist.add(map);
map = new HashMap<String, String>();
map.put("first", "Age");
map.put("second", ":");
map.put("third", "28");
mylist.add(map);

columnAdapter = new SimpleAdapter(this, mylist, R.layout.row,
            new String[] {"first", "second", "third"}, new int[] {R.id.first_cell, R.id.second_cell, R.id.third_cell});
list.setAdapter(columnAdapter);
ListView列表=(ListView)findViewById(R.id.some_列表);
ArrayList mylist=新的ArrayList();
HashMap=newHashMap();
地图放置(“第一”、“名称”);
图.put(第二个“,”:”);
地图放置(“第三”、“abcd”);
添加(地图);
map=新的HashMap();
地图放置(“第一”、“年龄”);
图.put(第二个“,”:”);
地图放置(“第三”、“28”);
添加(地图);
columnAdapter=new SimpleAdapter(this,mylist,R.layout.row,
新字符串[]{“第一”、“第二”、“第三”},新int[]{R.id.first_cell,R.id.second_cell,R.id.third_cell});
list.setAdapter(columnAdapter);
xml1:


xml2:



然后使用一些条件表达式以编程方式填充mylist。为此,不需要2个列表视图。您只需要一个带有自定义适配器的listview来显示所需的内容。你可以参考这个例子


为此,您不需要两个列表视图。您只需要一个带有自定义适配器的listview来显示所需的内容。你可以参考这个例子


不需要两个列表视图。具有多列的ListView的一个很好的示例如所示。

不需要两个列表视图。具有多列的ListView的一个很好的示例显示在。

我已经得到了答案。给你。我认为这对其他人会有帮助。 在我的行布局中,我创建了一个名为mylist.xml的新xml文件

在main.xml文件中,我有

<LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ListView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="true"
            android:id="@+id/list_main"/>
    </LinearLayout>

现在我在mylist.xml中有自己的listview布局,需要将该视图放在main.xml的listview中

然后,在我的活动文件中,我有:

ListView list_activity = (ListView)findViewById(R.id.list_main);

//got adapter for mylistview(for my first column) 
//and called a function to populate as my needed view....
//do that by urself...

public void populateList(ArrayAdapter<CharSequence> adpt, int pos,int pos2)
    {
        list = new ArrayList<HashMap<String,String>>();
        double[] array = getArray(pos, pos2);//was my for my pgm for a calulation
        for(int i = 0; i < adpt.getCount();i++)
        {
            String str = adpt.getItem(i).toString();

            HashMap<String, String> temp = new HashMap<String, String>();
            temp.put(FIRST_COLUMN, str);
            temp.put(SECOND_COLUMN, Double.toString(array[i]));
            list.add(temp);
        }
        ListViewAdapter adapter = new ListViewAdapter(this, list);
        list_activity.setAdapter(adapter);
    }
ListView list\u activity=(ListView)findViewById(R.id.list\u main);
//获取mylistview的适配器(用于我的第一列)
//并调用一个函数来填充我所需的视图。。。。
//你自己做吧。。。
公共无效人口列表(ArrayAdapter adpt、int pos、int pos2)
{
列表=新的ArrayList();
double[]array=getArray(pos,pos2);//是我的pgm的计算工具
对于(int i=0;i
我已经得到了答案。给你。我认为这对其他人会有帮助。
在我的行布局中,我创建了一个名为mylist.xml的新xml文件

在main.xml文件中,我有

<LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ListView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="true"
            android:id="@+id/list_main"/>
    </LinearLayout>

现在我在mylist.xml中有自己的listview布局,需要将该视图放在main.xml的listview中

然后,在我的活动文件中,我有:

ListView list_activity = (ListView)findViewById(R.id.list_main);

//got adapter for mylistview(for my first column) 
//and called a function to populate as my needed view....
//do that by urself...

public void populateList(ArrayAdapter<CharSequence> adpt, int pos,int pos2)
    {
        list = new ArrayList<HashMap<String,String>>();
        double[] array = getArray(pos, pos2);//was my for my pgm for a calulation
        for(int i = 0; i < adpt.getCount();i++)
        {
            String str = adpt.getItem(i).toString();

            HashMap<String, String> temp = new HashMap<String, String>();
            temp.put(FIRST_COLUMN, str);
            temp.put(SECOND_COLUMN, Double.toString(array[i]));
            list.add(temp);
        }
        ListViewAdapter adapter = new ListViewAdapter(this, list);
        list_activity.setAdapter(adapter);
    }
ListView list\u activity=(ListView)findViewById(R.id.list\u main);
//获取mylistview的适配器(用于我的第一列)
//并调用一个函数来填充我所需的视图。。。。
//你自己做吧。。。
公共无效人口列表(ArrayAdapter adpt、int pos、int pos2)
{
列表=新的ArrayList();
double[]array=getArray(pos,pos2);//是我的pgm的计算工具
对于(int i=0;i
这才是我真正需要的。这才是我真正需要的。
public class Constant 
{
    public static final String FIRST_COLUMN = "First";
    public static final String SECOND_COLUMN = "Second";
}
<LinearLayout android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <ListView android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:clickable="true"
            android:id="@+id/list_main"/>
    </LinearLayout>
ListView list_activity = (ListView)findViewById(R.id.list_main);

//got adapter for mylistview(for my first column) 
//and called a function to populate as my needed view....
//do that by urself...

public void populateList(ArrayAdapter<CharSequence> adpt, int pos,int pos2)
    {
        list = new ArrayList<HashMap<String,String>>();
        double[] array = getArray(pos, pos2);//was my for my pgm for a calulation
        for(int i = 0; i < adpt.getCount();i++)
        {
            String str = adpt.getItem(i).toString();

            HashMap<String, String> temp = new HashMap<String, String>();
            temp.put(FIRST_COLUMN, str);
            temp.put(SECOND_COLUMN, Double.toString(array[i]));
            list.add(temp);
        }
        ListViewAdapter adapter = new ListViewAdapter(this, list);
        list_activity.setAdapter(adapter);
    }