[英]custom setMessage dialog TextView cannot be cast to java.lang.CharSequence
我正在嘗試從對話框中打印一條消息,該消息來自API,並且我假裝將其打印在我為其設置的TextView中,以下是我要執行的操作和錯誤日志:
close = new AlertDialog.Builder(LembrarSenha.this);
close.setCancelable(true);
close.setIcon(R.drawable.ic_launcher);
String msg = mNovaSenhaRest.getNovaSenha(value).getMsg();
LayoutInflater inflater = getLayoutInflater();
View view=inflater.inflate(R.layout.titlebar, null);
TextView informativo = (TextView) view.findViewById(R.id.informacao);
informativo.setText(msg); // Line 149
close.setMessage((CharSequence) informativo);
close.setView(view);
日志:
java.lang.ClassCastException: android.widget.TextView cannot be cast to java.lang.CharSequence
10-14 16:54:25.048 22956-22956/br.com. W/System.err﹕ at br.com..LembrarSenha$asyncTask$1.run(LembrarSenha.java:149)
(LembrarSenha.java:149)=“ informativo.setText(msg);”
您不應該將TextView初始化為:
TextView informativo = (TextView) view.findViewById(R.id.informacao);
?
因為您正在嘗試向對話框添加自定義視圖。 您可以為視圖充氣,但是在初始化TextView時,不會在自定義布局中查找它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.