EditText ed; List<EditText> allEds = new ArrayList<EditText>(); for (int i = 0; i < count; i++) { ed = new EditText(Activity2.this); allEds.add(ed); ed.setBackgroundResource(R.color.blackOpacity); ed.setId(id); ed.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); linear.addView(ed); }
@Nullable @Override public View onCreateView(final LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable final Bundle savedInstanceState) { final View view = inflater.inflate(R.layout.notes_fragment, container, false); // Find the clear button and wire the click listener to call the clear notes updatable view.findViewById(R.id.clear).setOnClickListener(v -> notesStore.clearNotes()); // Find the add button and wire the click listener to show a dialog that in turn calls the add // note from text from the notes store when adding notes view.findViewById(R.id.add).setOnClickListener(v -> { final EditText editText = new EditText(v.getContext()); editText.setId(R.id.edit); new AlertDialog.Builder(v.getContext()) .setTitle(R.string.add_note) .setView(editText) .setPositiveButton(R.string.add, (d, i) -> { notesStore.insertNoteFromText(editText.getText().toString()); }) .create().show(); }); // Setup the recycler view using the repository adapter recyclerView = (RecyclerView) view.findViewById(R.id.result); recyclerView.setAdapter(adapter); recyclerView.setLayoutManager(new LinearLayoutManager(getContext())); final ImageView imageView = (ImageView) view.findViewById(R.id.background); updatable = () -> backgroundRepository.get().ifSucceededSendTo(imageView::setImageBitmap); return view; }
(Receiver<Note>) (note) -> { final EditText editText = new EditText(getContext()); editText.setId(R.id.edit); editText.setText(note.getNote()); new AlertDialog.Builder(getContext())
// Find my layout LinearLayout mLinearLayout = (LinearLayout) findViewById(R.id.ll1); // Add a new EditText with default text of "test" EditText testText = new EditText(this.getApplicationContext()); testText.setText("test"); // This line is the key; without it, any additional text changes will // be lost on rotation. Try it with and without the setId, text will revert // to just "test" when you rotate. testText.setId(100); // Add your new EditText to the view. mLinearLayout.addView(testText);
EditText edText = new EditText(this); edText .setId(i); edText .setLayoutParams(new LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1f)); edText .setWidth(100); edText .setImeOptions(EditorInfo.IME_ACTION_NEXT); edText .setInputType(InputType.TYPE_CLASS_NUMBER); edText .setKeyListener(DigitsKeyListener.getInstance()); edText .setMaxLines(1); edText .setOnFocusChangeListener(this); edText .setOnEditorActionListener(this); edText .addTextChangedListener(this); //this linearlayout id is declared inside your xml file LinearLayout linear=(LinearLayout)findViewById(R.id.linearLayout1); linear.addView(edText );
LinearLayout llMain = (LinearLayout)findViewById(R.id.llmain); EditText editText = new EditText(this); //0-based index, so get the number of current views, and use it for the next editText.setId(llMain.getChildCount()); llMain.addView(editText);
LinearLayout ll = (LinearLayout) findViewById(R.id.linearlayout2); EditText tv; List<EditText> allEds = new ArrayList<EditText>(); for (int i = 0; i < 5; i++) { tv = new EditText(this); tv.setText("Dynamic TextView" + i); tv.setId(i + 5); ll.addView(tv); }
EditText editText = new EditText(this); editText.setId(i); //Set id so that you can remove that EditText in the future. editText.setLayoutParams(new LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); linearLayout.addView(editText);
for(int i=0;i<max;i++){ EditText et=new ExitText(this); //......... et.setId(i); }
LinearLayout layout=(LinearLayout)view.findViewById(R.id.linearLayout); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( android.widget.LinearLayout.LayoutParams.MATCH_PARENT, android.widget.LinearLayout.LayoutParams.WRAP_CONTENT); EditText edttext= new EditText(this); edttext.setId("edittext"); edttext.setLayoutParams(params); layout.addView(edttext);
@Override public void onViewCreated(final View view, Bundle savedInstanceState){ LinearLayout l = (LinearLayout) view.findViewById(R.id.scrolllayout); EditText e = new EditText(view.getContext()); e.setId(R.id.mytextbox); LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT)); e.setLayoutParams(lp); l.addView(e); }
createMultipleEditTexts(int n) { for(int i = 0; i < n; i++) { EditText et = new EditText(this); // Assign id for future reference probably store it somewhere et.setId(i) // Assign layout params to it LayoutParams params = new LayoutParams(width, height) et.setParams(params) // Add it to the root layout of your activity's/view groups view rootLayout.addView(et); } }
EditText myEditText = new EditText(this); // Pass it an Activity or Context LayoutParams editLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); myEditText.setLayoutParams(editLayoutParams); myEditText.setVerticalFadingEdgeEnabled(true); myEditText.setHint(hint); myEditText.setId(Integer.parseInt(id)); myLayout.addView(myEditText);// myLayout is object of linear layout created in xml file
EditText ed; List<EditText> allEds = new ArrayList<EditText>(); for (int i = 0; i < count; i++) { ed = new EditText(Activity2.this); allEds.add(ed); ed.setBackgroundResource(R.color.blackOpacity); ed.setId(id); ed.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); linear.addView(ed); }
EditText editText = new EditText(this); editText.setId(1); editText.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,0f)); editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE); editText.setGravity(Gravity.TOP|Gravity.LEFT); editText.setHint("Comment"); editText.setSingleLine(false); editText.setLines(5); editText.setMaxLines(5); editText.setText(CommentFromDB); editTextRemark.setFocusable(false);
@Override public void onClick(View v) { // TODO Auto-generated method stub EditText editText = new EditText(MainActivity.this); editText.setId(editText.generateViewId()); editText.setHeight(50); editText.setWidth(50); ll.addView(editText); }
private void addEditText(Context context, AttributeSet attrs) { mEditText = onCreateEditText(context, attrs); mEditText.setId(ViewUtils.generateViewId()); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); addView(mEditText, lp); mEditText.addTextChangedListener(new InputContentChangeListener()); }
private void givenEditTextToOpenSoftKeyboard() { EditText editText = new EditText(activityTestRule.getActivity()); editText.setId(editTextId); addViewToLayout(editText, BaseActivity.rootLayout); } }
@Before public void setup() { EditText editText = new EditText(activityTestRule.getActivity()); editText.setId(editTextId); editText.setHint(HINT_TEXT); addViewToLayout(editText, BaseActivity.rootLayout); }