im adding a bunch of edittxts dynamically to a linear layout but want them to appear centrally in layout rather than to the left of the layout
<p>im pretty new to android and im trying to add a number of edittexts dynamically to a layout based on a strings length which is entered by the user in an edittext in another activity. i  pass the string from the first activity to the next and add an editText  to a layout for each character in the string vertically across a linearlayout. but unfortunately these edittexts start at the very left hand side of the screen and move left to right as added. i want these edittexts to be central regardless of the number of letter in the word. anyone know how i can do this? here is my code so far for the activity where im adding multiple edittexts based on no. of characters in the string.</p>

<pre><code>import java.util.ArrayList;
import java.util.List;

import eoin.hangman.R;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.Toast;

public class GameScreen extends Activity {

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.gscreen);


        Intent intent = getIntent();
        String word = intent.getExtras().getString("ans");
        int noofletters = word.length();
        View linearLayout =  findViewById(R.id.info);
       // char[] cArray = word.toCharArray();




          for(int i=0;i&lt;noofletters;i++)
          {
                EditText editText = new EditText(this);
            LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            editText.setLayoutParams(params);
            ((ViewGroup) linearLayout).addView(editText);
            // editText.setText(cArray[i]);
          }
       }
}
</code></pre>

<p>i was also trying to add a single character from the string to each edittext but this didnt seem to be working for me either. any help is greatly appreciated!</p>

<p>so ive edited my code. here is what i have done. seperate edttxt.xml created for the edittext box which i then inflate. created within a tablelayout with a row already setup inside the tablelayout in the gscreen.xml. it gets rid of adding the views programmatically which is good. I still want to ad one char from the string to each edittext but cant do it. hopefully ill figure it out. the main thing is im learning. id like to be progressing a bit faster though. almost forgot about centering the edittext boxes i jjust did that with  android:gravity="center_horizontal" in the tablerow within the gscreen.xml. hopefully this will help someone in the future.</p>

<pre><code>public class GameScreen extends Activity {

    @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.gscreen);


            Intent intent = getIntent();
            String word = intent.getExtras().getString("ans");   //get string from intent sent to this activity
            int noofletters = word.length();                     //no of letters in string which creates an edittext box for each character.




            LayoutInflater  edit_inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View insertpoint = findViewById(R.id.tablerow);


              for(int i=0;i&lt;noofletters;i++)
              {
                  EditText edtview = (EditText)edit_inflater.inflate(R.layout.edtxt,null);  
                  ((ViewGroup) insertpoint).addView(edtview);

              }
</code></pre>
