我有一个导航抽屉,它从字符串中填充并使用他们的位置我正在处理要启动的活动我只想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);
答案 0 :(得分:2)
请参阅示例代码以将页脚设置为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);
我希望代码注释是自解释的
答案 1 :(得分:1)
没有类似" setfooter"对于listview。 您可以通过使用以下代码来扩充页脚布局并将其作为页脚添加到列表视图。
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?
希望它会有所帮助。谢谢。