Note that there are some explanatory texts on larger screens.

plurals
  1. POOnly one view is displayed in Android
    primarykey
    data
    text
    <p>I am new to Android. When i run this code, only one circle is displayed. If i remove view1, then view2 is displayed. but they are never displayed together!!! why is that? Any help would be appreciated.</p> <p>thanks</p> <pre><code>package com.dots; import android.app.Activity; import android.content.Context; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.os.Bundle; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class Dots1Activity extends Activity { private static final String TAG = "DotsActivity"; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout ll = new LinearLayout(this); ll.setOrientation(LinearLayout.HORIZONTAL); TextView label = new TextView(this); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); label.setText("Click the circle!"); CustomDrawableView view1 = new CustomDrawableView(this, 100, 100, 50, Color.RED); CustomDrawableView view2 = new CustomDrawableView(this, 200, 200, 25, Color.GREEN); CustomDrawableView view3 = new CustomDrawableView(this, 300, 300, 10, Color.WHITE); ll.addView(label, layoutParams); ll.addView(view1, layoutParams); ll.addView(view2, layoutParams); ll.addView(view3, layoutParams); setContentView(ll); } } class CustomDrawableView extends View implements OnClickListener{ private Context context; private int x, y, radius, color; public CustomDrawableView(Context context, int x, int y, int radius, int color) { super(context); this.context = context; this.x = x; this.y =y; this.radius = radius; this.color = color; setOnClickListener(this); } protected void onDraw(Canvas canvas) { super.onDraw(canvas); this.setBackgroundColor(Color.LTGRAY); Paint paint = new Paint (Paint.ANTI_ALIAS_FLAG); paint.setColor(color); canvas.drawCircle(x, y, radius, paint); } public void onClick(View v) { Toast.makeText(this.context, x+"-"+y+"-"+radius, Toast.LENGTH_SHORT).show(); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload