Siret Sarv
Siret Sarv

Reputation: 11

How to put dynamically created EditText data into two dimensional array in Android?

I am making a determinant calculator. This code creates a*a EditText matrix. If I insert numbers in each EditText (in this case "et" in code) I want those numbers into two dimensional array.

I want the data from the matrix, not put in the matrix.

My code is:

public void matrixSize(int a){
    ll = (LinearLayout)findViewById(R.id.ll);
    Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int width = display.getWidth()/3;
    for(int i=0;i<a;i++){
        l = new LinearLayout(this);
        l.setOrientation(LinearLayout.HORIZONTAL);
        for(int j=0;j<a;j++){
            et = new EditText(this);
            if (a<=7){
                ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(150, 150);
                l.addView(et,lp);
            }
            else {
                ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(100, 100);
                l.addView(et,lp);
            }

        }
        ll.addView(l);
    }
}

Here is the matrix:

Here is the matrix

Upvotes: 0

Views: 137

Answers (1)

Mike
Mike

Reputation: 4570

You should use a GridView for that.

Here is a short tutorial on how to build a GridView layout in Android.

Upvotes: 1

Related Questions