ListView的Adapter问题

rungear123 2016-07-29 04:25:08
需求很简单,就是通过网络获取数据,然后用ListView显示出来。
我是自定义的一个Adapter,现在获取数据,创建Adapter都没有问题。
在setAdaper时出了问题,代码是这样的:
		new Thread(){
@Override
public void run() {
super.run();
String url = Utility.getUrlRoot(getApplicationContext()) + UrlTypeBind.GetAllTeamList;
TeamInfoReqHttp tifrh = new TeamInfoReqHttp(new TeamInfo() , url);
teamList = tifrh.GetAllTeamList();

handler.post(new Runnable() {
@Override
public void run() {
adapter = new TeamListAdapter(TeamListActivity.this,teamList);
lv_TeamList.setAdapter(adapter);
}
});
}
}.start();


问题是现在数据无法显示,并且LOG里不停的打印GC回收的信息,貌似是有内存泄露,但是找不到原因。
目前数据只有两条,因为数据是正常的,网络访问就不贴了。


Adapter和对应的layout如下
public class TeamListAdapter extends BaseAdapter {

private List<TeamInfo> teamList;
private Context context;
private LayoutInflater inflater;

public TeamListAdapter(Context context,List<TeamInfo> teamList){
this.context = context;
this.teamList = teamList;
this.inflater = LayoutInflater.from(context);
}

public TeamListAdapter(Context context){
this.context = context;
this.inflater = LayoutInflater.from(context);
}

public void setData(List<TeamInfo> teamList){
this.teamList = teamList;
}

@Override
public int getCount() {
return teamList.size();
}

@Override
public Object getItem(int i) {
return teamList.get(i);
}

@Override
public long getItemId(int i) {
return i;
}

@Override
public View getView(int i, View view, ViewGroup viewGroup) {
Holder holder = null;
if(view == null){
view = inflater.inflate(R.layout.team_list_item,null);
holder = new Holder(view);
view.setTag(holder);
}
else {
holder = (Holder) view.getTag();
}

TeamInfo team = teamList.get(i);
holder.tv_TeamName.setText(team.getTeamName());
holder.tv_MemberCount.setText(team.getMemberCount() + "人");
holder.tv_StartTime.setText(Utility.DayConvertString(team.getStartTime()) +
" " + new SimpleDateFormat("HH:mm").format(team.getStartTime()));
return view;
}

class Holder{
TextView tv_TeamName;
TextView tv_StartTime;
LinearLayout ll_TeamMember;
TextView tv_MemberCount;

public Holder(View view){
tv_TeamName = (TextView) view.findViewById(R.id.tv_team_name);
tv_StartTime = (TextView) view.findViewById(R.id.tv_team_start_time);
tv_MemberCount = (TextView) view.findViewById(R.id.tv_team_member_count);
ll_TeamMember = (LinearLayout) view.findViewById(R.id.ll_team_member);
}
}
}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="160dp"
android:layout_marginTop="10dp"
android:background="@null">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.15"
android:background="#d5c3ff"></RelativeLayout>

<TextView android:id="@+id/tv_team_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:textColor="#ffffff" />

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp">

<ImageView android:id="@+id/iv_time_tag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/time_tag"/>

<ImageView android:id="@+id/iv_time_ico"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ico_time"
android:layout_marginLeft="3dp"
android:layout_centerVertical="true"/>

<TextView android:id="@+id/tv_team_start_time"
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/iv_time_ico"
android:textSize="14sp"/>

</RelativeLayout>

<LinearLayout android:id="@+id/ll_team_member"
android:layout_below="@+id/tv_team_name"
android:layout_width="match_parent"
android:layout_height="100dp"
android:gravity="left|center_vertical"
android:orientation="horizontal">

</LinearLayout>

<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="15dp"
android:layout_marginBottom="10dp" >

<ImageView
android:id="@+id/iv_ico_people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ico_people"/>

<TextView android:id="@+id/tv_team_member_count"
android:layout_toRightOf="@id/iv_ico_people"
android:layout_marginLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

</RelativeLayout>
</RelativeLayout>


有没有人遇到过类似问题,或者教教我怎么查也好
...全文
165 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
TyroLJS 2016-07-29
  • 打赏
  • 举报
回复
4点半还在敲代码,好拼啊
「已注销」 2016-07-29
  • 打赏
  • 举报
回复
应该是在主线程更新ui,使用listview来setadapter
rungear123 2016-07-29
  • 打赏
  • 举报
回复
果然发帖有助于发现问题啊,原来是有条数据有问题,是前几天做的数据,现在过期了。 所以那个算时间的方法死了。
rungear123 2016-07-29
  • 打赏
  • 举报
回复
引用 2 楼 qq_31479481 的回复:
应该是在主线程更新ui,使用listview来setadapter
网络访问不是需要在Thread里吗,获取数据之后能更新啊

80,490

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧