问题描述
- 怎么给Fragment中的ListView绑定数据
-
急求指点!我的Fragment加载的布局里有一个ListView控件,ListView内行有一个lmageView
我想给这个ImageVieW绑定数据
求大神指点怎么弄啊,我老报错
解决方案
listview的getview中,加载视图,并findviewbyid,找到imageview,并根据position得到指定位置的数据,给imageview赋值
解决方案二:
绑定数据到ListView
ListView绑定数据
ListView绑定数据
解决方案三:
绑定数据到ListView
ListView绑定数据
ListView绑定数据
解决方案四:
把logcat 报错 贴出来看下 就知道了
解决方案五:
那你把你的代码贴出来。看看就知道了
解决方案六:
一下是我的代码麻烦大家帮忙看看
public class MyFragment3 extends ListFragment{
private ListViewAdapter adapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.mylog,container,false);
return view;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
adapter = new ListViewAdapter(getActivity());
setListAdapter(adapter);
}
}
public class ListViewAdapter extends BaseAdapter{
private LayoutInflater inflater;
private int[] pic = {R.drawable.a,R.drawable.b};
public ListViewAdapter(Context context){
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return pic.length;
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null) {
holder = new ViewHolder();
convertView = inflater.inflate(R.layout.log_item, null);
holder.iv = (ImageView) convertView.findViewById(R.id.log_pic);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.iv.setImageResource(pic[position]);
return convertView;
}
class ViewHolder{
ImageView iv;
}
}
解决方案七:
你可以用Picasso加载图片
时间: 2024-10-02 08:05:01