Note that there are some explanatory texts on larger screens.

plurals
  1. POManaging several EditTexts in Android
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/7536791/android-how-to-elegantly-set-many-button-ids">android: how to elegantly set many button IDs</a> </p> </blockquote> <p>Everyone.</p> <p>I'm trying to build my first Android app for doing some RMS (Root Mean Square) error calculation. For this I need several experimental points inputs, this is done manually in EditTexts. So I have 40 EditTexts in one layout. The problem is when it comes to managing them, I have something like this:</p> <pre><code>public class InsertarData extends Activity implements OnClickListener { EditText x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,x17; EditText y1,y2,y3,y4,y5,y6,y7,y8,y9,y10,y11,y12,y13,y14,y15,y16,y17; float [] datosX; float [] datosY; public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.insertardatos); x1=(EditText)findViewById(R.id.x1Et); x2=(EditText)findViewById(R.id.x2Et); x3=(EditText)findViewById(R.id.x3Et); x4=(EditText)findViewById(R.id.x4Et); x5=(EditText)findViewById(R.id.x5Et); x6=(EditText)findViewById(R.id.x6Et); x7=(EditText)findViewById(R.id.x7Et); x8=(EditText)findViewById(R.id.x8Et); x9=(EditText)findViewById(R.id.x9Et); x10=(EditText)findViewById(R.id.x10Et); x11=(EditText)findViewById(R.id.x11Et); x12=(EditText)findViewById(R.id.x12Et); x13=(EditText)findViewById(R.id.x13Et); x14=(EditText)findViewById(R.id.x14Et); x15=(EditText)findViewById(R.id.x15Et); x16=(EditText)findViewById(R.id.x17Et); x17=(EditText)findViewById(R.id.x17Et); y1=(EditText)findViewById(R.id.y1Et); y2=(EditText)findViewById(R.id.y2Et); y3=(EditText)findViewById(R.id.y3Et); y4=(EditText)findViewById(R.id.y4Et); y5=(EditText)findViewById(R.id.y5Et); y6=(EditText)findViewById(R.id.y6Et); y7=(EditText)findViewById(R.id.y7Et); y8=(EditText)findViewById(R.id.y8Et); y9=(EditText)findViewById(R.id.y9Et); y10=(EditText)findViewById(R.id.y10Et); y11=(EditText)findViewById(R.id.y11Et); y12=(EditText)findViewById(R.id.y12Et); y13=(EditText)findViewById(R.id.y13Et); y14=(EditText)findViewById(R.id.y14Et); y15=(EditText)findViewById(R.id.y15Et); y16=(EditText)findViewById(R.id.y16Et); y17=(EditText)findViewById(R.id.y17Et); Button continuar=(Button)findViewById(R.id.continuarBtn); continuar.setOnClickListener(this); } @Override public void onClick(View e) { switch(e.getId()){ case R.id.continuarBtn:{ datosX=new float[17]; datosX[0]=Float.parseFloat(x1.getText().toString()); datosX[1]=Float.parseFloat(x2.getText().toString()); datosX[2]=Float.parseFloat(x3.getText().toString()); datosX[3]=Float.parseFloat(x4.getText().toString()); datosX[4]=Float.parseFloat(x5.getText().toString()); datosX[5]=Float.parseFloat(x6.getText().toString()); datosX[6]=Float.parseFloat(x7.getText().toString()); datosX[7]=Float.parseFloat(x8.getText().toString()); datosX[8]=Float.parseFloat(x9.getText().toString()); datosX[9]=Float.parseFloat(x10.getText().toString()); datosX[10]=Float.parseFloat(x11.getText().toString()); datosX[11]=Float.parseFloat(x12.getText().toString()); datosX[12]=Float.parseFloat(x13.getText().toString()); datosX[13]=Float.parseFloat(x14.getText().toString()); datosX[14]=Float.parseFloat(x15.getText().toString()); datosX[15]=Float.parseFloat(x16.getText().toString()); datosX[16]=Float.parseFloat(x17.getText().toString()); datosY[0]=Float.parseFloat(y1.getText().toString()); datosY[1]=Float.parseFloat(y2.getText().toString()); datosY[2]=Float.parseFloat(y3.getText().toString()); datosY[3]=Float.parseFloat(y4.getText().toString()); datosY[4]=Float.parseFloat(y5.getText().toString()); datosY[5]=Float.parseFloat(y6.getText().toString()); datosY[6]=Float.parseFloat(y7.getText().toString()); datosY[7]=Float.parseFloat(y8.getText().toString()); datosY[8]=Float.parseFloat(y9.getText().toString()); datosY[9]=Float.parseFloat(y10.getText().toString()); datosY[10]=Float.parseFloat(y11.getText().toString()); datosY[11]=Float.parseFloat(y12.getText().toString()); datosY[12]=Float.parseFloat(y13.getText().toString()); datosY[13]=Float.parseFloat(y14.getText().toString()); datosY[14]=Float.parseFloat(y15.getText().toString()); datosY[15]=Float.parseFloat(y16.getText().toString()); datosY[16]=Float.parseFloat(y17.getText().toString()); } } } } </code></pre> <p>This "works" (it needs to be completed passing the datosX and datosY to another activity. But, before, I need to know whether the EditTexts are empty or not and I cannot imagine doing something like if(edittext.getText().toString()!=null) before every parseFloat.</p> <p>Is there any better way to manage a lot of EditTexts and know if they're empty or not? I've though of an array of EditText and doing something like:</p> <pre><code>EditText editarray[17]; editarray[0]=(EditText)findViewById(R.id.edittext0); </code></pre> <p>Is this the way of doing it?</p> <p>Thank you very much for reading and answering in advance. Sorry for my English.</p>
    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.
    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