1

I looked at: How to set Id of dynamic created layout?.

and did the following:

//in my .java file (in OnCreate)
submitButton.setId(R.id.dynSubmitButton);

in my listener method:

public void addListenerOnButton() {

    final Context context = this;
    submitButton = (Button) findViewById(R.id.dynSubmitButton);

    submitButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Intent intent = new Intent(context, ActivityResults12.class);
            startActivity(intent);

        }
    });
}

I then got an error on submitButton.setId(R.id.dynSubmitButton); which I fixed by clicking on it and choosing Create constant 'dynSubmitButton' in type 'id'. I get the following error:

[2015-01-09 14:13:18 - Application] R.java was modified manually! Reverting to generated version!

Community
  • 1
  • 1
Jesse Galdamez
  • 81
  • 1
  • 2
  • 11

1 Answers1

2

You can set any integer value in setID method. But remember the following, while you set the ID.

  1. Manually set ids using someView.setId(int);
  2. The int must be positive.

For example, if creating and numbering several views representing items, you could use their item number.

Example -

 int i=10;
 submitButton.setId(i);
Prem
  • 4,823
  • 4
  • 31
  • 63