我想在导航抽屉的每个列表视图中添加按钮。我们如何在那里添加按钮可以任何正文提供示例/示例代码。我从Android Developers中获取了示例示例..
提前致谢
答案 0 :(得分:1)
您将使用此答案我解释了如何设计自定义listView .... 在下面的课程中,我使用了两个textview代替那两个你只需要使用两个
布局中的按钮并使用此自定义适配器
...等
CustomAdapter mAdapter = new CustomAdapter(this, R.layout.listitem, mListItems);
mPullRefreshListView.setAdapter(mAdapter);
然后使用此代码...
public class CustomAdapter extends ArrayAdapter<Sample> {
public ArrayList<Sample> mlist;
public Context context;
public LayoutInflater inflater;
public CustomAdapter(Context context, int resource, ArrayList<Sample> mlist) {
super(context, resource);
this.mlist = mlist;
this.context = context;
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getPosition(Sample item) {
return super.getPosition(item);
}
@Override
public Sample getItem(int position) {
return mlist.get(position);
}
@Override
public int getCount() {
return mlist.size();
}
@Override
public long getItemId(int position) {
return super.getItemId(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = inflater.inflate(R.layout.listitem, null);
TextView text1 = (TextView) convertView.findViewById(R.id.item1);
TextView text2 = (TextView) convertView.findViewById(R.id.item2);
text1.setText(mlist.get(position).getListitem1());
text2.setText(mlist.get(position).getListitem2());
text2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// you just put your Logic here And use this custom adapter to
// load your Data By using this particular custom adapter to
// your listview
}
});
return convertView;
}
}
一切顺利