I have a custom view (DrawFigures) which has an onTouch method to perform a series of actions. There's a layout that has a few buttons, a TextView and a RelativeView to add the custom view dynamically. Then, in the MainActivity.class, I need to receive the value of some attributes in the DrawFigures when the onTouch method is called in this custom view, in order to show them in TextView components.
Here is the code of the custom view:
public abstract class DrawFigures extends View{
private float value1;
public boolean onTouch(Motion Event){
int action = event.getAction();
if(action==MotionEvent.ACTION_MOVE){
// ... methods that provoke that value1 changes
}else if(action==MotionEvent.ACTION_DOWN){
// ...
}else if(action==MotionEvent.ACTION_UP){
// ...
}
}
// ...
return true;
}
I haven't been able to receive the value1 to show it in the TextView of the MainActivity while it's changing because of the onTouch method of the DrawFigures. How could be this problem solved? Implement an OnTouch method in the MianActivity? How to do it? The MainActivity.class looks like this:
public class MainActivity extends Activity implements View.OnTouchListener{
DrawFigures fig;
TextView txtInfo;
// ...
public void btnSecRec(View v){
int id = v.getId();
if (id == R.id.btnSecRec){
RelativeLayout parent = (RelativeLayout)findViewById(R.id.viewDatosSec);
parent.removeAllViews();
fig = new DrawRectangleWithDimensions(this);
fig.setOnTouchListener(this);
fig.setFigure(10, 40);
parent.addView(fig);
}
}
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_MOVE) {
if (fig.touching == true) {
String value = Float.toString(fig.getChangingDimensionValue());
txtInfo.setText(value);
}
}
return true;
}
}