public ZhuoInfoListAdapter(Activity context, ArrayList<ZhuoInfoVO> list) { this.mContext = context; this.mList = list; this.inflater = LayoutInflater.from(context); this.mConnHelper = ZhuoConnHelper.getInstance(context); this.width = DeviceInfoUtil.getDeviceCsw(context); this.times = DeviceInfoUtil.getDeviceCsd(context); this.phw = new PopupWindows(context); this.myid = ResHelper.getInstance(context).getUserid(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_card_add_user_hobby); Intent intent = getIntent(); String hobby = intent.getStringExtra(CardEditActivity.EDIT_HOBBY_STR); String[] hobbys = hobby.split(";|£º| "); Map<String, Boolean> hobbymap = new HashMap<String, Boolean>(); for (String item : hobbys) { hobbymap.put(item, false); } LayoutInflater inflater = LayoutInflater.from(CardAddUserHobbyActivity.this); TableLayout tl = (TableLayout) findViewById(R.id.tableLayout); this.width = DeviceInfoUtil.getDeviceCsw(getApplicationContext()); this.times = DeviceInfoUtil.getDeviceCsd(getApplicationContext()); padding = (int) (padding * times); baseMargin = (int) (baseMargin * times); int restWidth = width - 2 * padding - 3 * baseMargin; int widthOne = restWidth / 4; baseMargin = (int) ((restWidth - widthOne * 4) / 3) + baseMargin; tl.setPadding(padding, 0, padding, 0); String[] items = getResources().getStringArray(R.array.array_hobby); TableRow tr = null; for (int i = 0; i < items.length; i++) { if (i % 4 == 0) { tr = new TableRow(CardAddUserHobbyActivity.this); tl.addView(tr); } ToggleButton tb = (ToggleButton) inflater.inflate(R.layout.item_toggle, null); tb.setText(items[i]); tb.setTextOn(items[i]); tb.setTextOff(items[i]); tb.setOnCheckedChangeListener( new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { buttonView.setTextColor(Color.rgb(0, 72, 255)); selected.put(buttonView.getText().toString(), true); } else { buttonView.setTextColor(Color.rgb(52, 52, 52)); selected.put(buttonView.getText().toString(), false); } } }); tr.addView(tb); TableRow.LayoutParams trlp = new TableRow.LayoutParams(widthOne, TableRow.LayoutParams.WRAP_CONTENT); trlp.rightMargin = baseMargin; trlp.bottomMargin = baseMargin * 3 / 8; trlp.topMargin = baseMargin * 3 / 8; tb.setLayoutParams(trlp); if (hobbymap.containsKey(items[i])) { tb.setChecked(true); hobbymap.put(items[i], true); selected.put(items[i], true); } else { selected.put(items[i], false); } } String hobbyStr = ""; for (String item : hobbymap.keySet()) { if (!hobbymap.get(item)) { hobbyStr += item + " "; } } ((EditText) findViewById(R.id.editText)).setText(hobbyStr); initClick(); }