kayveesin
kayveesin

Reputation: 433

unable to set properties of editText

I am defining an EditText array in a class outside any methods.

I want to use the first member of the EditText[] in the onCreate method. Will i have to define it again in the onCreate method to set the properties of the EditText.

EditText items[]=new EditText[30];
EditText rates[]=new EditText[30];
EditText quants[]=new EditText[30];

int no,id;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


    setContentView(R.layout.activity_main);

    items[0].setHint("Enter the item");
    items[0].setId(0);

Upvotes: 0

Views: 75

Answers (2)

Exceptional
Exceptional

Reputation: 3004

First it has to be casted!! Else you can't!.

Here You Go!!!

RelativeLayout relative_layout;
private TextView tv[] = new TextView[27];
tv[0] = (TextView) relative_layout.findViewById(R.id.tv1);

tv[i].setText("HELLO");

Upvotes: 0

CodingIntrigue
CodingIntrigue

Reputation: 78545

You've declared a new array, but you haven't added any objects to it. You need to do this:

items[0] = new EditText(this);
items[0].setHint("Enter the item");
items[0].setId(0);

This is assigning the value at items index 0 to a new EditText object, otherwise the value at items[0] would be null.

Upvotes: 4

Related Questions