复制代码- public class DeviceAdapter extends BaseAdapter {
- Context context;
- List> mList;
- LayoutInflater inflater;
- public DeviceAdapter(Context context,List> mList){
- this.context = context;
- this.mList = mList;
- inflater = LayoutInflater.from(context);
- }
- public int getCount() {
- // TODO Auto-generated method stub
- return mList.size();
- }
- public Object getItem(int position) {
- // TODO Auto-generated method stub
- return mList.get(position);
- }
- public long getItemId(int position) {
- // TODO Auto-generated method stub
- return 0;
- }
- public View getView(int position, View convertView, ViewGroup parent) {
- View view = inflater.inflate(R.layout.devicelistitem,null);
- ImageView device_icon = (ImageView) view.findViewById(R.id.device_icon);
- device_icon.setBackgroundResource((Integer) mList.get(position).get("device_icon"));
- TextView device_name = (TextView) view.findViewById(R.id.device_name);
- device_name.setText(mList.get(position).get("device_name").toString());
- TextView device_setting = (TextView) view.findViewById(R.id.device_setting);
- device_setting.setText(mList.get(position).get("device_setting").toString());
- device_setting.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- View view1 = inflater.inflate(R.layout.devicesetting, null);
- Builder builder = new AlertDialog.Builder(context);
- builder.setTitle("其他功能");
- builder.setView(view1);
- builder.create().show();
- TextView timesetting = (TextView) view1.findViewById(R.id.timesetting);
- TextView timedelete = (TextView) view1.findViewById(R.id.timedelet);
- timesetting.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- Intent intent = new Intent();
- intent.setClass(context, SmartPowerActivity.class);
- context.startActivity(intent);
- }
- });
- }
- });
- return view;
- }
|