从零开始的体温app开发(adapter1)
package adapter;
import android.content.Context;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.example.myapplication.R;
import java.util.List;
import bean.User;
public class UserListAdapter extends BaseAdapter {
private final Context context;
private final List<User> userList;
public UserListAdapter(Context context, List<User> userList) {
this.context=context;
this.userList=userList;
}
@Override
public int getCount() {
return userList.size();
}
@Override
public Object getItem(int i) {
return userList.get(i);
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(int i, View convertView, ViewGroup parent) {
if(convertView==null){
convertView=View.inflate(context,R.layout.item_user,null);
}
TextView num= convertView.findViewById(R.id.num);
TextView name= convertView.findViewById(R.id.name);
TextView cl= convertView.findViewById(R.id.cl);
TextView data= convertView.findViewById(R.id.date);
TextView time= convertView.findViewById(R.id.time);
TextView area= convertView.findViewById(R.id.area);
TextView tem= convertView.findViewById(R.id.tem);
TextView es= convertView.findViewById(R.id.es);
num.setText(userList.get(i).get("num"));
name.setText(userList.get(i).get("name"));
cl.setText(userList.get(i).get("cl"));
data.setText(userList.get(i).get("date"));
time.setText(userList.get(i).get("time"));
area.setText(userList.get(i).get("area"));
tem.setText(userList.get(i).get("tem"));
es.setText(userList.get(i).get("qw"));
//Log.e("position",""+i+userList.get(i).get("num"));
return convertView;
}
}