I would like to add a custom property to a group of EditTexts that are created programmatically. I have three different sensors set up via an Arduino, and I would like this custom attribute to be used by the app to dictate which sensor to read from.
Is there a way to create a custom attribute so that I can declare the setting like editTextX.setSensorType(0)
?
Here is the code that I'd be using this with:
if (check for certain j value) {
rowjlabel.setText(" %");
// read from tilt sensor, or "dimensionj.setSensorType(tilt);"
} else if (check for other j value) {
rowjlabel.setText(" in.");
// read from height sensor, or "dimensionj.setSensorType(height);"
} else {
rowjlabel.setText(" in.");
//read from distance sensor, or "dimensionj.setSensorType(distance);"
}
Sure, you can subclass EditText and add any fields or methods you need. Something like this (note, you will need a bit more code than this, like a constructor):
Then you just have to use that class in place of EditText in your application.