そこで、このチュートリアルを使用して、画像を表示するカスタム トーストを作成しました。
ここでやりたいことは、画像リソースを渡して、トースト メソッドにその画像を表示するように指示できるようにすることです。
だから私はこれを持っています:
private void callToast(int image_resource)
{
LayoutInflater inflater = getLayoutInflater();
View v = inflater.inflate(R.layout.mycustomtoast, (ViewGroup) findViewById(R.id.toast_layout));
/*set the image*/
ImageView iv = (ImageView)findViewById(R.id.toast_iv);
iv.setImageResource(image_resource);
Toast t = new Toast(this);
t.setView(v);
t.setGravity(Gravity.CENTER,0,0);
t.show();
}
findViewById が null を返すようになりました...下にある XML が使用されていないため、わかりましたか?
カスタム トースト イメージ ビューのソースを変更するにはどうすればよいですか?