我能夠使用此代碼的Android定製的祝酒詞
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom_toast_layout, (ViewGroup)findViewById(R.id.custom_toast));
TextView text = (TextView) layout.findViewById(R.id.toast_tv);
text.setText("Hello! This is a custom toast!");
Toast toast = new Toast(getApplicationContext());
toast.setDuration(Toast.LENGTH_LONG);
toast.setView(layout);
toast.show();
然而,由於我不明白的LayoutInflater
目的是爲了使自定義的敬酒,我修改了代碼,這...
Toast toast = new Toast(getApplicationContext());
toast.setView(findViewById(R.id.custom_toast));
toast.setDuration(Toast.LENGTH_SHORT);
toast.show();
我得到RuntimeException說「setView必須被調用」..
爲什麼我不能將視圖分配給烤麪包而不使用
LayoutInflater
?LayoutInflater
的目的通常是什麼,以便我可以將此體驗應用於其他自定義視圖?
編輯: 我正在使用onListItemClick()
接口方法..內容設置之後,這些代碼..
我認爲一個很好的問題是「LayoutInflater在內部做什麼」? – Behnam