android listview 不显示,baseAdapter listview不显示,该怎么解决
baseAdapter listview不显示Java codeprivate ArrayList> getData(){try {Document doc = Jsoup.connect("http://www.3dmgame.com/").timeout(30000).get();Elements et = doc.getElementsByAttributeValue("class",
baseAdapter listview不显示
Java codeprivate ArrayList> getData(){
try {
Document doc = Jsoup.connect("http://www.3dmgame.com/").timeout(30000).get();
Elements et = doc.getElementsByAttributeValue("class", "newList").select("li").select("a");
for(Element e : et){
HashMap map = new HashMap();
String text = e.text().replace(Jsoup.parse(" ").text(), " ");
map.put("text", text);
list.add(map);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
这段代码获得的数据,使用simpleAdapter的时候可以正确显示
但是是用baseadapter的时候就不显示东西,也不提示错误
baseadapter如下:Java codeprivate class NewsAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return getData().size();
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int arg0, View arg1, ViewGroup arg2) {
// TODO Auto-generated method stub
arg1 = LayoutInflater.from(getApplicationContext()).inflate(R.layout.newslist, null);
TextView tv = (TextView)arg1.findViewById(R.id.textView1);
ImageView iv = (ImageView)arg1.findViewById(R.id.imageView1);
tv.setText(getData().get(arg0).get("text").toString());
return arg1;
}
}
但是把getData()写成这样
Java codeprivate ArrayList> getData(){
list = new ArrayList>();
HashMap map = new HashMap();
for(int i = 0; i < 2; i++){
map.put("text", "dfdfadf");
map.put("text", "fdedaf");
}
list.add(map);
return list;
}
这样用baseadapter就可以用了,为什么啊
------解决方案--------------------
你确定第一个list里有数据
------解决方案--------------------
private class RosterAdapter extends BaseAdapter {
private LayoutInflater inflater;
private Context context;
public RosterAdapter(Context context) {
this.context = context;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return userinfos.size();
}
@Override
public Object getItem(int position) {
return userinfos.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder {
TextView user;
TextView status;
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
User user = userinfos.get(position);
ViewHolder viewHolder;
if (convertView == null) {
更多推荐
所有评论(0)