There are two identical View's, in them onDraw() and OnTouchEvent() methods. Separately, each works perfectly. But when adding them to the Activity , only the one that was added last works.
How to fix?
public class PlayActivity extends AppCompatActivity{ RelativeLayout rlPlay; int wrapContent = RelativeLayout.LayoutParams.WRAP_CONTENT; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_play); rlPlay=(RelativeLayout) findViewById(R.id.rlPlay); RelativeLayout.LayoutParams lParams = new RelativeLayout.LayoutParams(wrapContent,wrapContent); Protect1 pt1=new Protect1(this); Protect2 pt2=new Protect2(this); rlPlay.addView(pt1,lParams); rlPlay.addView(pt2,lParams); } }