@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(); }
public void appendNeighborCellInfo(NeighboringCellInfo data) { TableRow tr = new TableRow(this); int color = Color.parseColor("#000000"); TextView label = new TextView(this); TableRow.LayoutParams params = new TableRow.LayoutParams(); params.span = 2; params.leftMargin = 10; params.rightMargin = 10; params.bottomMargin = 10; TableRow.LayoutParams params2 = new TableRow.LayoutParams(); params2.weight = 1; // params2.gravity=16; label.setLayoutParams(params); label.setText("Neighbor Cell Tower"); label.setTextSize(20); label.setTextColor(Color.parseColor("#909090")); // label.setTypeface(null, Typeface.BOLD); // label.setGravity(Gravity.CENTER); // label.setPadding(0, 10, 0, 0); tr.addView(label); tr.setLayoutParams(params); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr = new TableRow(this); label = new TextView(this); label.setLayoutParams(params); label.setText("Network type "); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); tr.addView(label); label = new TextView(this); label.setTextSize(18); label.setLayoutParams(params2); label.setText(getString(DCSConvertorUtil.networkTypeToStringId(data.getNetworkType()))); label.setTextColor(color); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); tr = new TableRow(this); label = new TextView(this); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); label.setLayoutParams(params); label.setText("PSC "); tr.addView(label); label = new TextView(this); label.setText(data.getPsc() + ""); label.setLayoutParams(params2); label.setTextColor(color); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); tr = new TableRow(this); label = new TextView(this); label.setLayoutParams(params); label.setText("Cell id "); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); tr.addView(label); label = new TextView(this); label.setLayoutParams(params); label.setText(data.getCid() + ""); label.setTextColor(color); label.setLayoutParams(params2); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); tr = new TableRow(this); label = new TextView(this); label.setLayoutParams(params); label.setText("Area code "); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); tr.addView(label); label = new TextView(this); label.setText(data.getLac() + ""); label.setTextColor(color); label.setLayoutParams(params2); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); tr = new TableRow(this); label = new TextView(this); label.setLayoutParams(params); label.setText("Signal Strength "); label.setTextSize(18); label.setTextColor(color); tr.setBackgroundResource(R.drawable.black_alpha); tr.addView(label); label = new TextView(this); label.setLayoutParams(params); label.setText(data.getRssi() + ""); label.setTextColor(color); label.setLayoutParams(params2); tr.addView(label); ((TableLayout) findViewById(R.id.info_table)).addView(tr, params); tr.setLayoutParams(params); }