0

I have 20 edittext,layout and autocompletetextview I want to access them and everything using arrays I am getting an error right on attaching their ids. Where am I going wrong here

  LinearLayout[] laygroup ;
  EditText[] etquantity,etprice ; 
  AutoCompleteTextView[] etproduct ; 
  int[] laygroupid = new   int[]{R.id.laygroup0,R.id.laygroup1,R.id.laygroup2,R.id.laygroup3} ;
  int[] etquantityid = new int[]{R.id.autoquantity0,R.id.autoquantity1,R.id.autoquantity2,R.id.autoquantity3};
  int[] etpriceid = new int[]{R.id.autoprice0,R.id.autoprice1,R.id.autoprice2,R.id.autoprice3} ;
  int[] productid = new int[] {R.id.autoproduct0,R.id.autoproduct1,R.id.autoproduct2,R.id.autoproduct3};

then in the oncreate

  for(int i=0; i<=3; i++) 
    { 
    etprice[i] = (EditText)getActivity().findViewById(etpriceid[i]);
    etquantity[i] = (EditText)getActivity().findViewById(etquantityid[i]);
    laygroup[i] = (LinearLayout)getActivity().findViewById(laygroupid[i]) ;
    etproduct[i] = (AutoCompleteTextView)getActivity().findViewById(productid[i]); 
    }  
Nasz Njoka Sr.
  • 1,138
  • 16
  • 27

2 Answers2

1

You need to declare the inital size for these arrays. See how to declare arrays with inital sizes in java

LinearLayout[] laygroup = new LinearLayout[10];
EditText[] etquantity = new EditText[10];
EditText[] etprice = new EditText[10]; 
AutoCompleteTextView[] = new etproduct EditText[10]; 
Panther
  • 8,938
  • 3
  • 23
  • 34
1

Try this..

You have to initialize the size arrays.

  LinearLayout[] laygroup = new LinearLayout[3];
  EditText[] etquantity = new EditText[3];
  EditText[] etprice = new EditText[3]; 
  AutoCompleteTextView[] = new etproduct EditText[3]; 
Hariharan
  • 24,741
  • 6
  • 50
  • 54
  • Thanks for this one though i found out that i could easily access the ids instead of defining them in an array statically i coud use the dynamic way of getting their ids – Nasz Njoka Sr. Oct 24 '14 at 06:48