我遇到一些問題時,我試圖顯示自定義吐司(使用圖標和消息)。這是代碼。更改自定義吐司中的文本和圖標?
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();
}
我想更改圖標和消息時,第二個參數是0或1。我知道這個問題是在調用第二佈局,但我不知道如何解決它。
謝謝你。
編輯:
我打電話從onPostExecute中的AsyncTask此方法。我忘了說這個。
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敬酒和它的作品好。
感謝大家。
是什麼錯誤?把你的logcat的消息 –
好,一秒^^對不起 – MAOL
加滿日誌.. –