[英]Is it possible to have components other than List in ListActivity
By using the following code. 通过使用以下代码。
BuyActivity.java BuyActivity.java
public class BuyActivity extends ListActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.transaction_list_view);
OrderAdapter orderAdapter = new OrderAdapter(this,
R.layout.custom_row_view, new ArrayList<Object>());
setListAdapter(orderAdapter);
orderAdapter.add(new Object());
orderAdapter.add(new Object());
}
}
transaction_list_view.xml transaction_list_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:drawSelectorOnTop="false">
</ListView>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data"
/>
</LinearLayout>
custom_row_view.xml custom_row_view.xml
Please refer to custom_row_view.xml 请参阅custom_row_view.xml
I was able to get the following outcome. 我得到了以下结果。
Besides list, I would also like to have a static label at the bottom of ListActivity. 除了列表,我还想在ListActivity的底部有一个静态标签。
I try 我试试
transaction_list_view.xml transaction_list_view.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="2"
android:drawSelectorOnTop="false">
</ListView>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="No data"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="THIS IS TOTAL STATIC LABEL"
/>
</LinearLayout>
But I am getting 但我得到了
What my expectation is 我的期望是什么
Is there anything I had missed out? 有什么我错过了吗?
You have indicated that your ListView
is supposed to fill_parent
in the vertical orientation, leaving no room for your other widgets. 你已经指出你的ListView
应该是垂直方向的fill_parent
,没有空间容纳你的其他小部件。 Your weight is being ignored. 你的体重被忽略了。 You probably want to have your android:layout_height
be 0dip
instead. 您可能希望将android:layout_height
改为0dip
。
尝试将静态textview的高度设置为wrap_content。
Well you could try Relative Layout to just set the static label anchored to the bottom of the screen. 那么你可以尝试相对布局来设置固定在屏幕底部的静态标签。 If that's not what you meant, I would try to help you further on. 如果这不是你的意思,我会尽力帮助你。 Good luck 祝好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.