这是我的活动代码:
@Override
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
String[] names = new String[] { "Investor Relations", "Social Sharing", "Rate this app", "About Rathbones",
"Disclaimer", "Security", "Credits"};
// Create an ArrayAdapter, that will actually make the Strings above
// appear in the ListView
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.moremenulist,
R.id.label, names));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
// Get the item that was clicked
Object o = this.getListAdapter().getItem(position);
String keyword = o.toString();
Toast.makeText(this, "You selected: " + keyword, Toast.LENGTH_LONG).show();
}
这是xml文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout android:id="@+id/LinearLayout1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:layout_width="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:layout_height="wrap_content" android:id="@+id/label"></TextView>
<LinearLayout android:id="@+id/linearLayout2" android:layout_width="wrap_content" android:orientation="vertical" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentBottom="true">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageButton android:layout_width="wrap_content" android:id="@+id/imgbtn1" android:layout_alignParentLeft="true" android:layout_alignBottom="@+id/imgbtn3" android:layout_height="wrap_content" android:src="@drawable/topnews" android:visibility="visible"></ImageButton>
<ImageButton android:layout_width="wrap_content" android:layout_alignParentRight="true" android:id="@+id/imgbtn5" android:layout_alignBottom="@+id/imgbtn4" android:layout_height="wrap_content" android:src="@drawable/more"></ImageButton>
<ImageButton android:layout_width="wrap_content" android:id="@+id/imageButton1" android:layout_height="wrap_content" android:src="@drawable/contact_us" android:layout_alignParentTop="true" android:layout_toRightOf="@+id/imgbtn1"></ImageButton>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
现在,当活动加载时,它会在菜单中附加列表中的每个项目。我只是希望它只出现在底部而不是每个列表项。 有什么建议吗?
我试过这个但是得到了nullpointer异常的错误
View footerView =
((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer, null, false);
ListView lv = new ListView(this);
lv.addFooterView(footerView);
答案 0 :(得分:1)
菜单是什么意思?你的意思是你的ImageButtons?
如果是这种情况,则删除那些为这些ImageButtons创建另一个布局,然后使用ListView.addFooterView()添加它们。
您可以创建例如list_footer_layout.xml
,其中包含您的ImageButtons。然后:
public void onCreate(Bundle bundle) {
...
ListView lv = getListView(); // If your activity is ListActivity
View foot = getLayoutInflater().inflate(R.layout.list_footer_layout, null);
lv.addFooterView(foot);
}