0

i have the following code, and the problem, that my function rlposition() isn't available from outside the class.

public class RLbadge extends TextView {

    public RLbadge(Context context) {
        super(context);
        this.setTypeface(null, Typeface.BOLD);
        this.setTextColor(Color.WHITE);
        this.setBackgroundResource(R.drawable.badge);
        this.setTextSize(18);
    }

    public void rlposition(Button pButton) {
        // THIS FUNCTION ISNT SEEN FROM OUTSIDE WHY?
    }

    protected void onDraw (Canvas canvas) {
        super.onDraw(canvas);
    }
}

Why is the function rlposition not visible from outside of the class? Isn't it possible to add functionality to an extended TextView?

Sufian
  • 6,405
  • 16
  • 66
  • 120

2 Answers2

2

i now answered the question for myself and put it here maybe somebody needs the answer in the future.

The problem was this line of calling:

TextView badgeInfoscan = new RLbadge(this);
badgeInfoscan.rlposition(); // here the error comes

changed to

RLbadge badgeInfoscan = new RLbadge(this);
badgeInfoscan.rlposition(); // the function is visible
Kushal
  • 8,100
  • 9
  • 63
  • 82
2
 <YOURPACKAGENAME.MyTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="32sp"
        android:text="TEASTING" />

Here is Class

    public class MyTextView extends TextView {

    public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init(attrs);
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs);

    }

    public MyTextView(Context context) {
        super(context);
        init(null);
    }

    private void init(AttributeSet attrs) {
        // Do your staff
        }
    }

}
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198