I was able to make custom toast using this code
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(); However, since I do not understand the purpose of LayoutInflater, I modified the code to this...
Toast toast = new Toast(getApplicationContext()); toast.setView(findViewById(R.id.custom_toast)); toast.setDuration(Toast.LENGTH_SHORT); toast.show(); And I get RuntimeException saying "setView must have been called"..
Why can't I just assign the view to toast without using
LayoutInflater?What is the purpose of
LayoutInflaterin general so that I can apply this experience to other custom views?
Edit: I am using these codes in onListItemClick() interface method.. after the content is set..