J'utilise TextView personnalisé. Mais quand je le récupère en utilisant find view par Id, j'obtiens ClassCastException. Je l'utiliser dans un fichier XML comme ceci:ClassCastException dans findViewById lors de l'utilisation de la vue personnalisée
<View class="com.android.smsapp.MsgTextView" android:id="@+id/text"
et l'utiliser dans le fichier java comme celui-ci.
MsgTextView text = (MsgTextView) row.findViewById(R.id.text);
Qu'est-ce que je fais mal?
@Pavandroid
Je l'ai inclus dans le fichier correct
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);
}
}`
Aussi Quand je suis bien, LogCat montre une ligne de plus
03-19 14:30:41.476: E/AndroidRuntime(24089): Caused by: java.lang.NoSuchMethodException: MsgTextView(Context,AttributeSet).. But I have defined this constructor.
juste usee com.android.smsapp.MsgTextView au lieu de textview dans la partie xml et assurez-vous que votre MsgTextView classe étend textview –