0

So I have an object with a reference to view, and I'm trying to make it clickable but no luck. If you guys could help me I would appreciate it!

View CircleView; 

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LinearLayout base = new LinearLayout(this);
    base.setOrientation(LinearLayout.VERTICAL);


    CircleView = new CircleView(this);

    CircleView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(getBaseContext(), "text",Toast.LENGTH_LONG).show();

        }
    });


    base.addView(CircleView);

}

My class CircleView extends View as well.

T3KBAU5
  • 1,861
  • 20
  • 26
Greggz
  • 1,873
  • 1
  • 12
  • 31
  • Add your CircleView code to your post. It's possible that you did something in there that's changing how the OnClickListener behaves. – T3KBAU5 Nov 22 '14 at 01:45
  • http://stackoverflow.com/questions/4766938/custom-view-with-button-like-behavior-on-click-touch – Naveen Tamrakar Nov 22 '14 at 04:47
  • Have you tried to explicitly mentuoned that CircleView.setClickable(true); . Did my observation works for you? – Roll no1 Nov 22 '14 at 06:09

1 Answers1

0

Try it this way ...

View CircleView; 

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LinearLayout base = new LinearLayout(this);
    base.setOrientation(LinearLayout.VERTICAL);

 LayoutParams linLayoutParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 
        // set LinearLayout as a root element of the screen 
        setContentView(base , linLayoutParam);
    CircleView = new CircleView(this);
 LayoutParams circleViewParam = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        CircleView.setLayoutParams(circleViewParam);
    CircleView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(getBaseContext(), "text",Toast.LENGTH_LONG).show();

        }
    });


    base.addView(CircleView);

}
iMDroid
  • 2,108
  • 1
  • 16
  • 29