自定义linearLayout布局中添加listView,并且使用baseAdapter添加数据 50
2个回答
展开全部
在显示ListView的Java类中
TakeNotesAdapter adapter = new TakeNotesAdapter(mContext);
list.setAdapter(adapter);
public class MyAdapter extends BaseAdapter{
private LayoutInflater mInflater;
public MyAdapter(Context context){
this.mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 20; //设置item数目
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = new ViewHolder();
if(convertView == null){
convertView = mInflater.inflate(R.layout.take_notes_item, null); //item的布局文件
holder.txtTime = (TextView) convertView.findViewById(R.id.txtWorkDetails);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.txtTime.setText("工作内容" + position);
return convertView;
}
static class ViewHolder {
TextView txtTime;
}
}
TakeNotesAdapter adapter = new TakeNotesAdapter(mContext);
list.setAdapter(adapter);
public class MyAdapter extends BaseAdapter{
private LayoutInflater mInflater;
public MyAdapter(Context context){
this.mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return 20; //设置item数目
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ViewHolder holder = new ViewHolder();
if(convertView == null){
convertView = mInflater.inflate(R.layout.take_notes_item, null); //item的布局文件
holder.txtTime = (TextView) convertView.findViewById(R.id.txtWorkDetails);
convertView.setTag(holder);
}else{
holder = (ViewHolder) convertView.getTag();
}
holder.txtTime.setText("工作内容" + position);
return convertView;
}
static class ViewHolder {
TextView txtTime;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询