Help when entering several data in Android

1

I need help loading several data using a TextView, I'm doing a project that I was asked at the University is the subject Operational Research I do not know if you already know but I have to do a project for that matter, my problem is that I know how I can enter various data to my application

Where it says number of variables as I enter the number of variables and where it says number of restrictions as I enter the number of restrictions.

Once I enter the number of variables and the number of restrictions I want internally to create a matrix with the values that I enter, in this case in the image introduced: number of variables: 2 and number of restrictions: 2 so which should create a 2x2 matrix and I want that every time I press the LOAD button every data that I enter in the EditText is loaded in the matrix that was created. In Java Eclipse it would be something like this:

for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
        matriz[i][j]=JOptionPane.showInputDialog("Ingrese un numero");
    }
}

With that I quietly charge it in the matrix but how can I do something like this in Android Studio ??? I hope you have understood me, I was as clear as possible, I hope your answers ... Thank you.

    
asked by eyllanesc 07.01.2017 в 03:27
source

1 answer

0

It would stay that way with the approach you want to use:

for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
        matrixInput(matriz,i,j,"Ingrese un numero:");
    }
}

where you define the matrixInput function like this:

void matrixInput(final double [][] matriz,final int i,final int j,String msg) {
    final EditText txtNum = new EditText(this);
    new AlertDialog.Builder(this)
            .setTitle("Ingrese un numero:")
            .setMessage(msg)
            .setView(txtNum)                
            .setPositiveButton("Ingresar", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    String num = txtNum.getText().toString();
                    try {
                        matriz[i][j] = Double.valueOf(num);
                    }catch (NumberFormatException nf){
                        matrixInput(matriz,i,j,"Repita el numero, el formato es incorrecto");
                    }
                }
            }
            ).show();
}

Should validate that they do not cancel the dialogue, although this is not the best approach in terms of UI design or use JOptionPane.showInputDialog for four or more values

    
answered by 21.07.2017 в 19:03