カスタム トースト (アイコンとメッセージ付き) を表示しようとすると、いくつかの問題が発生します。これがコードです。
private void makeToast(String text, int icon) {
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast,(ViewGroup) findViewById(R.id.message));
((TextView) layout.findViewById(R.id.message)).setText(text);
layout = inflater.inflate(R.layout.custom_toast,(ViewGroup) findViewById(R.id.icon));
// 0 - Exclamation, 1 - Noow icon
if(icon == 0){
((ImageView) layout.findViewById(R.id.icon)).setImageResource(R.drawable.exclamation);
}else if(icon == 1){
((ImageView) layout.findViewById(R.id.icon)).setImageResource(R.drawable.nicon);
}
Toast toast = new Toast(getBaseContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
}
2番目のパラメータが0または1のときのアイコンとメッセージを変更したいです。2番目のレイアウトの呼び出しに問題があることはわかっていますが、解決方法がわかりません。
ありがとうございます。
編集:
このメソッドは、AsyncTask の onPostExecute から呼び出します。これを言い忘れました。
Thread [<11> AsyncTask #1] (Suspended (exception RuntimeException))
ThreadPoolExecutor.runWorker(ThreadPoolExecutor$Worker) line: not available
ThreadPoolExecutor$Worker.run() line: not available
Thread.run() line: not available
編集2:
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
makeToast("loading nightclubs...", 1);
}
}
編集3:
@Override
protected void onPostExecute(List<Category> result) {
Log.i("result", result.toString());
// Cargamos el listado a pasarle a categoryId en la
// consulta
for (int k = 0; k < result.size(); k++) {
ALLOFTHEM += result.get(k).getId();
if (k < result.size() - 1) {
ALLOFTHEM += ",";
}
}
Log.i("POST", ALLOFTHEM);
}
解決しました!!!
利用した...
runOnUiThread(new Runnable() {
public void run() {
makeToast("loading nightclubs...", 1);
}
});
...UI で乾杯したいときはいつでも、うまくいきます。
皆さんのお陰で。