JAVA日报

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

listview 对每一条设置监听事件

package adapter;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.example.myapplication.R;
import com.example.myapplication.SecondActivity;
import com.example.myapplication.ThirdActivity;

import java.util.List;

import bean.User;
import bean.User2;

public class UserListAdapter2 extends BaseAdapter {
private final Context context;
private final List<User2> userList2;
public UserListAdapter2(Context context, List<User2> userList2) {
this.context=context;
this.userList2=userList2;
}

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

@Override
public Object getItem(int i) {
return userList2.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_user2,null);
}
TextView bu=convertView.findViewById(R.id.btn5);
bu.setTag(i);
bu.setText(userList2.get(i).getCl()+"-"+userList2.get(i).getName()+"-"+userList2.get(i).getNum());
return convertView;
}

}
上一篇:3月3日


下一篇:android 获取通讯录并显示listview,android内录音频