将项目设置到列表视图的页脚

Set an item to the footer of listview

我有一个导航抽屉,它是从字符串中获取的,通过使用它们的位置,我正在处理要启动的 activity 我只想 listview 最后一项应该出现在 listview

我使用了 setFooter 属性 但它不起作用。

有什么方法可以做到?

代码如下:

class MyAdapter extends BaseAdapter {
    private Context context;
    String[] navlist;
    int[] images = { R.drawable.job, R.drawable.career, R.drawable.project,
            R.drawable.facebook, R.drawable.games, R.drawable.mail, R.drawable.rate };

    public MyAdapter(Context context) {
        this.context = context;
        navlist = context.getResources().getStringArray(R.array.navdra);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return navlist.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return navlist[position];
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = null;
        if (convertView == null) {
            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            row = inflater.inflate(R.layout.customrow, parent, false);
        }

        else {
            row = convertView;
        }
        TextView titleTextView = (TextView) row.findViewById(R.id.textView11);
        ImageView titleImageView = (ImageView) row
                .findViewById(R.id.imageView1);
        titleTextView.setText(navlist[position]);
        titleImageView.setImageResource(images[position]);

        return row;
    }

}

ListView 和 ArrayAdapter 代码:

listView = (ListView) findViewById(R.id.drawerlist);
        myAdapter = new MyAdapter(this);

        listView.setAdapter(myAdapter);
        listView.setOnItemClickListener(this);
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerListner = new ActionBarDrawerToggle(this, drawerLayout,
                R.drawable.ic_drawer, R.string.dopen, R.string.dclose);

        drawerLayout.setDrawerListener(drawerListner);

listview 没有像 "setfooter" 这样的方法。 您可以使用以下代码扩充页脚布局并将其作为页脚添加到列表视图。

View footerView = ((LayoutInflater)ActivityContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.footer_layout, null, false);

ListViewObject.addFooterView(footerView);

查看此答案How to add a footer in ListView?

希望它会 help.thanks。

请参阅示例代码以将页脚设置为 ListView

mListview = (ListView) mContentView.findViewById(R.id.myListView);

// Inflating header and footer view to ListView
ViewGroup header = (ViewGroup) inflater.inflate(R.layout.header_item, mListview,false);
ViewGroup footer = (ViewGroup) inflater.inflate(R.layout.footer_item,mListview,false);

// Adding view to mlist header and footer
mListview.addHeaderView(header, null, false);
mListview.addFooterView(footer, null, false);

// Initializing the adapter
ListAdapter adapter = new ListAdapter(getNGAActivity(), myData);

// Setting the listview adapter
mListview.setAdapter(adapter);

我希望代码注释是不言自明的