包含TextView的java ListView和包含EditText的ListView不在同一行上
因此,图片将使您更好地了解问题:
请参见,我在左侧添加了3TextView
,在右侧添加了3ListView
,但它们不在同一行。
那我怎么解决呢
我的问题与XML有关:
<LinearLayout
安卓:id="@+id/inner_linear_layout_id"
安卓:layout_width="fill_parent"
安卓:layout_height="fill_parent"
安卓:layout_below="@id/date_picker_id"
安卓:baselineAligned="false"
安卓:orientation="horizontal"
安卓:weightSum="1" >
<ListView
安卓:id="@+id/dates_list_view_id"
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_weight="0.5"
/>
<ListView
安卓:id="@+id/comments_list_view_id"
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:layout_weight="0.5"
/>
</LinearLayout>
我的问题与Java有关:
arrayAdapter = new ArrayAdapter<String>(this, 安卓.R.layout.simple_list_item_1,datesListView.getId());
datesListView.setAdapter(arrayAdapter);
commentsListView.setAdapter(arrayAdapter);
date.setTextSize(20);
datesListView.addFooterView(date);
commentText.setId(998);
commentText.setInputType(EditorInfo.TYPE_CLASS_TEXT);
commentText.setHint("Add a comment");
commentText.setTextSize(15);
commentsListView.addFooterView(commentText);
date
是一个TextView
,而commentText
是一个EditText
# 1 楼答案
好的,这里有一个解决方案。当然,还有许多其他可能的解决办法
下面是列表项的XML。它描述了列表中单个条目的视图。在这里,它是用TextView和EditText构建的:
这是主活动的XML,它实际上包含ListView本身。但它没有指明子项(列表项)的外观,因为这是由上面的XML定义的:
这是MainActivity的代码,它包含一些绑定到ListView的演示数据。这实际上将ListView与其项以及ListView项对应的XML连接起来:
这就是它最终的样子:
如果您不使用ListView,那么这里有一个RelativeLayout也可以使用它。但它不是动态的,也不绑定到任何适配器: