Я использую пользовательский TextView. Но когда я получаю его с помощью поиска по идентификатору, я получаю ClassCastException. Я использую его в XML-файле, как это:
<View class="com.android.smsapp.MsgTextView"
android:id="@+id/text"
И используя его в java-файле вот так.
MsgTextView text = (MsgTextView) row.findViewById(R.id.text);
Что я делаю не так?
@ Pavandroid
Я включил его в правильный файл
package com.android.smsapp;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.TextView;
public class MsgTextView extends TextView {
private String sender;
MsgTextView(Context c){
super(c);
}
MsgTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
MsgTextView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public void setSender(String s) {
sender = s;
}
public String getSender() {
return (sender);
}
}`
Также Когда я проверил правильно, LogCat показывает еще одну строку
03-19 14:30:41.476: E/AndroidRuntime(24089): Caused by: java.lang.NoSuchMethodException: MsgTextView(Context,AttributeSet).. But I have defined this constructor.