Reputation: 81
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!
Upvotes: 1
Views: 54
Reputation: 4831
You can set any integer value in setID method. But remember the following, while you set the ID.
For example, if creating and numbering several views representing items, you could use their item number.
Example -
int i=10;
submitButton.setId(i);
Upvotes: 2