Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need Help with Referencing Dynamically Created Inputs

    I am trying to create a program which a user can create two matrices and then perform a certain operation on Matrix A and B which results in Matrix C.

    I have been successfully able to produce code that allows the user to determine the the size of Matrix A and B, and my code is also able to go ahead and create the edit texts for these Matrices.

    My problem is that for some reason I cannot reference the Edit Texts that are dynamically created to perform the operation IE (A+B=C) and have Matrix C have the correct values inserted into the Edit Texts. If anyone could help me I would GREATLY appreciate it, My code is below.

    Code:
    package zach.etier.osu.MC;
    
    import android.app.Activity;
    import android.content.DialogInterface;
    import android.os.Bundle;
    import android.view.Gravity;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.view.ViewGroup.LayoutParams;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.LinearLayout;
    import android.widget.TableLayout;
    import android.widget.TableRow;
    
    
    public class  Matrix  extends Activity implements OnClickListener  {
    LinearLayout A,B,C,Container;
    String gotBread,gotBread2,gotBread3,gotBread4;
    int Arow,Acol,Brow,Bcol;
    Button infocalc;
    TableRow rowA,rowB;
    String[]  myTextViewsA, myTextViewsB;   
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.home);
        infocalc=(Button)findViewById(R.id.calc);
        infocalc.setOnClickListener(this);
        A=(LinearLayout)findViewById(R.id.arrayA);
        B=(LinearLayout)findViewById(R.id.arrayB);
        C=(LinearLayout)findViewById(R.id.arrayC);
        Container=(LinearLayout)findViewById(R.id.Container);
        Container.setVisibility(View.INVISIBLE);
        Bundle gotBasket =getIntent().getExtras();
        gotBread=gotBasket.getString("key");
        Arow=Integer.parseInt(gotBread);
        gotBread2=gotBasket.getString("key2");
        Acol=Integer.parseInt(gotBread2);
        gotBread3=gotBasket.getString("key3");
        Brow=Integer.parseInt(gotBread3);
        gotBread4=gotBasket.getString("key4");
        Bcol=Integer.parseInt(gotBread4);
    
        final EditText[] myTextViewsA = new EditText[Arow];
        for (int i = 0; i < Arow; i++) {
            TableRow rowA = new TableRow(this);
            rowA.setId(i);
            for (int j = 0; j < Acol; j++) {
                EditText cell = new EditText(this);
                cell.setHint("(" + i + ", " + j + ")");
                rowA.addView(cell);
                myTextViewsA[j] = cell;
            }
            A.addView(rowA, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
                    rowA.setGravity(Gravity.CENTER);
        }
    
        final EditText[] myTextViewsB = new EditText[Brow];
        for (int i = 0; i < Brow; i++) {
            TableRow rowB = new TableRow(this); 
            rowB.setId(i);
            for (int j = 0; j < Bcol; j++) {
                EditText cell = new EditText(this);
                cell.setHint("(" + i + ", " + j + ")");
                rowB.addView(cell);
                myTextViewsB[i] = cell;
            }
            B.addView(rowB, new TableLayout.LayoutParams(
                    LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT));
                    rowB.setGravity(Gravity.CENTER);
        }
        Container.setVisibility(View.VISIBLE);
    
    }
        public void onClick(View v) {
            // TODO Auto-generated method stub  
            final EditText[] myTextViewsC = new EditText[Arow];
            for (int i = 0; i < Arow; i++) {
                TableRow rowC = new TableRow(this);      
                for (int j = 0; j < Acol; j++) {
                    EditText cell = new EditText(this);
                    cell.setText("(" + i + ", " + j + ")");
                    rowC.addView(cell);
                }
                C.addView(rowC, new TableLayout.LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));
                        rowC.setGravity(Gravity.CENTER);
        }
    }
    }

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    First you need to get a reference to the right forum: http://codingforums.com/java-jsp/

  • #3
    New to the CF scene
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Aaah, I am sorry about that. Honest mistake!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •