Java教程

JAVA日报

本文主要是介绍JAVA日报,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

从零开始的体温app开发(adapter)

用listview 显示数据库里信息

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;
    }
}
这篇关于JAVA日报的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!