I take the text from an example:
TextView date = null;
try {
date = (TextView) getLayoutInflater().inflate(
R.layout.some_textview, null);
} catch (Exception e) {
e.printStackTrace();
}
I created my own text view:
public class MyTextView extends TextView{
public MyTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MyTextView(Context context) {
super(context);
}
}
Now I want to use those:
MyTextView my = (MyTextView)date;
I get exeption for this:
java.lang.ClassCastException: android.widget.TextView cannot be cast to com.myapp.name.MyTextView
So how should this be done?
Thank.
Edit:
If I declare datehow MyTextView, I still get the same exception, ther is my xml some_textview:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="This is a template for date text view"
/>
source
share