public void onClick(View v) { switch (v.getId()) { case R.id.btnAddPeople: final TableRow tr = new TableRow(this); tr.setId(1); EditText editText = new EditText(this); editText.setId(200); editText.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME); editText.setMinWidth(100); // labelTV.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, // LayoutParams.WRAP_CONTENT)); tr.addView(editText); editText.requestFocus(); Button deleteButton = new Button(this); deleteButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.delete)); deleteButton.setId(200); deleteButton.setOnClickListener( new OnClickListener() { public void onClick(View v) { tblPersons.removeView(tr); } }); tr.addView(deleteButton); tblPersons.addView(tr); break; case R.id.btnContinue: String names = ""; for (int i = 0; i < tblPersons.getChildCount(); i++) { TableRow row = (TableRow) tblPersons.getChildAt(i); String name = ((EditText) (row.getChildAt(0))).getText().toString(); if (name != null && name.trim() != "") { names = names + name.trim(); } if (i < tblPersons.getChildCount() - 1) { names = names + ","; } } System.out.println("!!!!!!!!!!names:" + names); Intent intentExpenses = new Intent(); intentExpenses.setClassName("com.expenses", "com.expenses.ExpensesShareActivity"); intentExpenses.putExtra("com.expenses.PersonNames", names); startActivity(intentExpenses); break; default: break; } }
private void initCommentBox() { alert = new AlertDialog.Builder(this); // Set an EditText view to get user input input = new EditText(this); input.setHint("Enter your comment..."); input.setMinLines(3); input.setMinWidth(200); alert.setView(input); alert.setPositiveButton( "Post", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String value = input.getText().toString(); if (value.length() > 0) { CommentUploader up = new CommentUploader( getApplicationContext(), gaze.id, value, Installation.id(getApplicationContext())); up.execute(); } return; } }); alert.setNegativeButton( "Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { return; } }); alert.show(); input.requestFocus(); input.postDelayed( new Runnable() { public void run() { InputMethodManager keyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); keyboard.showSoftInput(input, 0); } }, 100); }
private void initMyGroupView() { ll = (LinearLayout) findViewById(R.id.l1); DisplayMetrics metric = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metric); /** * ******************************************************************************************* */ mvg = new MyViewGroup(NewSMSActivity.this); mvg.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, 70)); // mvg.setBackgroundColor(Color.GREEN); etMess = new EditText(NewSMSActivity.this); etMess.setFilters(new InputFilter[] {new InputFilter.LengthFilter(15)}); etMess.setSelection(etMess.getText().length()); etMess.setGravity(Gravity.CENTER_VERTICAL); etMess.setMinWidth(100); etMess.setHeight(60); etMess.setTag("edit"); etMess.getBackground().setAlpha(0); etMess.setId(extiTextId); etMess.addTextChangedListener( new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (isNum(s.toString())) { if (s.length() >= 1) { boolean bool = false; // length() == 15直接生成按钮 if (s.length() == 15) { bool = true; } // 字数没有满足15个验证是否有空格 if (!bool) { String c = s.toString().substring(start, start + count); for (int i = 0; i < chars.length; i++) { if (chars[i].equals(c)) { bool = true; break; } } } // bool == true 生成Button if (bool) { createView1(s.toString(), s.toString()); etMess.setText(""); } // 检测输入框数据是否已经换行 final View child = mvg.getChildAt(mvg.getChildCount() - 1); autoHeight(child); } } else { adapter.getFilter().filter(s); queryListView.setVisibility(View.VISIBLE); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {} @Override public void afterTextChanged(Editable s) {} }); mvg.addView(etMess); ll.addView(mvg); etMess.setOnFocusChangeListener( new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (!hasFocus) { if (isNum(etMess.getText().toString().trim())) { createView1(etMess.getText().toString().trim(), etMess.getText().toString().trim()); etMess.setText(""); } else { etMess.setText(""); queryListView.setVisibility(View.INVISIBLE); } } } }); }