Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't fix this issue in Edit Text Linear Layout in Android
    primarykey
    data
    text
    <p>I did a small coding based on the input count, it will display the number of check box and radio button. Here, everything goes fine. But I'm stuck with the Edit Text. If I enter any value to the first Edit Text and click the button, the concern value is displaying in the left top corner. I need it to display below as like checkbox and radio button is displayed. Your help is highly appreciated. Thanks in advance.</p> <p>Here is my code. </p> <p><strong>XML layout:</strong></p> <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" &gt; &lt;LinearLayout android:id="@+id/linearLayout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" &gt; &lt;/LinearLayout&gt; &lt;EditText android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignLeft="@+id/textView1" android:layout_below="@+id/textView1" android:layout_marginLeft="12dp" android:layout_marginTop="05dp" android:hint="Enter no" /&gt; &lt;Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button1" android:layout_alignBottom="@+id/button1" android:layout_alignParentRight="true" android:layout_marginRight="05dp" android:text="Edit Text" /&gt; &lt;EditText android:id="@+id/button3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignRight="@+id/button1" android:layout_below="@+id/button1" android:layout_marginTop="0dp" android:hint="Enter no" /&gt; &lt;Button android:id="@+id/button4" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/button3" android:layout_alignBottom="@+id/button3" android:layout_alignRight="@+id/button2" android:text="Check Box" /&gt; &lt;RadioGroup android:id="@+id/radiogroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:orientation="vertical" /&gt; &lt;Button android:id="@+id/button5" android:layout_width="98dp" android:layout_height="wrap_content" android:layout_alignLeft="@+id/button4" android:layout_alignRight="@+id/button2" android:layout_below="@+id/button3" android:text="Radio Button" /&gt; &lt;/RelativeLayout&gt; </code></pre> <p><strong>Java MainActivity:</strong></p> <pre><code>import android.os.Bundle; import android.app.Activity; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; import android.widget.*; import android.widget.LinearLayout.*; public class MainActivity extends Activity { private LinearLayout mLayout; private EditText mEditText; private Button mButton; Button abutton; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mLayout = (LinearLayout) findViewById(R.id.linearLayout); mEditText = (EditText) findViewById(R.id.button1); mButton = (Button) findViewById(R.id.button2); mButton.setOnClickListener(onClick()); TextView textView = new TextView(this); textView.setText("New text"); final EditText button2=(EditText)findViewById(R.id.button3); findViewById(R.id.button5).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub int number=Integer.parseInt(button2.getText().toString()); addRadioButtons(number); } }); findViewById(R.id.button4).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub int number=Integer.parseInt(button2.getText().toString()); addCheckBox(number); } }); } public void addRadioButtons(int number) { for (int row = 0; row &lt; 1; row++) { LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.HORIZONTAL); for (int i = 1; i &lt;= number; i++) { RadioButton rdbtn = new RadioButton(this); rdbtn.setId((row * 2) + i); rdbtn.setText("Radio " + rdbtn.getId()); ll.addView(rdbtn); } ((ViewGroup) findViewById(R.id.radiogroup)).addView(ll); } } public void addCheckBox(int number) { for (int row = 0; row &lt; 1; row++) { LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.HORIZONTAL); for (int i = 1; i &lt;= number; i++) { CheckBox ch = new CheckBox(this); ch.setId((row * 2) + i); ch.setText("Check " + ch.getId()); ll.addView(ch); } ((ViewGroup) findViewById(R.id.radiogroup)).addView(ll); } } private OnClickListener onClick() { return new OnClickListener() { @Override public void onClick(View v) { mLayout.addView(createNewTextView(mEditText.getText().toString())); } }; } private TextView createNewTextView(String text) { final LayoutParams lparams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); final TextView textView = new TextView(this); textView.setLayoutParams(lparams); textView.setText("" + text); return textView; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload