java - android listview 也在迭代页脚菜单

标签 java android menu android-listview

这是我的 Activity 代码:

@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>

现在,当 Activity 加载时,它会将列表中的每个项目附加到菜单中。我只是希望它只出现在底部,而不是出现在每个列表项中。 有什么建议吗?

编辑1:

我尝试了这个,但收到了空指针异常的错误

View footerView = 
        

    ((LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer, null, false);
        ListView lv = new ListView(this);
        lv.addFooterView(footerView);

最佳答案

菜单是什么意思?您是说您的 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);
}

关于java - android listview 也在迭代页脚菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7756680/

相关文章:

java - 如果在单个窗口中打开多个选项卡,getWindowHandles 返回一个窗口句柄

android - 如何用 firebase 构建友谊数据?

java - 类的 saveInstantState()

java - 需要将用户输入存储到 arrayList 中并保存到 txt 文件中,以便能够在请求时拉回

java - 为什么在 java 中测试参数内部赋值不起作用?

Java使用父类型的对象引用访问不同包中子类中的 protected 成员

java - 从 Mountain Lion 中删除 Java 7

android - ScrollView 中的 ViewPager 无法正确滚动

在单击该部分之前菜单不会展开的 CSS 导航

wordpress - 如何将 HTML 添加到 Wordpress 菜单?