Tuesday, 10 September 2013

Insert data on array text input on edittext

Insert data on array text input on edittext

Hi i am trying to insert data on array , i request the user insert data on
edittext and have a button insert then other edittext get the number of
times user want insert data and the array, will make trail and the other
edittext will go asking for data to user. Thats is what i have.
I can do that on java but i can´t do it on android.
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.moda);
findViewById(R.id.num1);
findViewById(R.id.num2);
findViewById(R.id.tvresultado);
/*Scanner numero = new Scanner(System.in);
int valor;
System.out.print("introduzca un valor");
valor = numero.nextInt();*/
}
public void ingresar(){
EditText num1 = (EditText)findViewById(R.id.num1);
EditText num2 = (EditText)findViewById(R.id.num2);
TextView total = (TextView)findViewById(R.id.tvresultado);
if(num1.length() <= 0 || num2.length() <=0){
Toast toast =
Toast.makeText(getApplicationContext(), "Introduce un
valor", Toast.LENGTH_SHORT);
toast.show();
}else{
int dbnum1 = Integer.parseInt(num1.getText().toString());//toma el
numero de datos a ingresar
int dbnum2 = Integer.parseInt(num2.getText().toString());
int vector[]={dbnum1};
int i;
//boolean sw;
//DataInputStream oCadena;
vector=new int[dbnum1];
//oCadena = new DataInputStream(System.in);
//System.out.println("Ingrese el numero de datos");
for(dbnum2=0;dbnum2<=vector.length;dbnum2++){
System.out.println(""+vector[dbnum2]);
}
}
}
}

No comments:

Post a Comment