Android ListView的不同行中的不同组件

时间:2014-11-17 20:34:20

标签: android android-listview android-calendar

我是Android新手。我想创建一个非常类似于Android日历应用的“添加事件”部分的Activity。对我来说,它看起来像ListView,每行有不同的组件。我错了。如果我是对的,我仍然不知道如何为ListView的每一行添加不同的组件,例如,一行EditText,另一行TextView等。如果这个应用程序根本不是ListView,如果有人能告诉我如何创建类似的东西,我会非常感激。

2 个答案:

答案 0 :(得分:4)

你好看看这个链接是否有用1

listView with different component

答案 1 :(得分:1)

首先,您必须学习如何实现自定义适配器(请参阅本教程:http://www.vogella.com/tutorials/AndroidListView/article.html#adapterown

然后在你的getView overriden方法中(你将在教程中了解它)你必须做这样的事情:

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View rowView = null;
    if (position == LAYOUT1_POSITION) //In this row you will place the layout named layout1
        rowView = inflater.inflate(R.layout.rowLayout1, parent, false);
    if (position == LAYOUT2_POSITION)
        rowView = inflater.inflate(R.layout.rowLayout2, parent, false);
    //Do similar for all your different layouts

    return rowView;
}