I'm trying to show my results search in a ListView
on the Fragment
, but it fails on:
LayoutInflater inflater = getLayoutInflater();
The method getLayoutInflater(Bundle) in the type Fragment is not applicable for the arguments ()
This is my code:
public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = getLayoutInflater(); View row; row = inflater.inflate(R.layout.list_single, parent, false); TextView textview = (TextView) row.findViewById(R.id.TextView01); ImageView imageview = (ImageView) row .findViewById(R.id.ImageView01); textview.setText(data_text[position]); imageview.setImageResource(data_image[position]); return (row); }
How can I fix this?
According to the Android documentation, a fragment is a part of applications user interface that is bound to an activity. Fragments have their lifecycle and layouts or UI components. Fragments help enrich your UI design, pass data between different screens, and adapt to different device configurations.
LayoutInflater is a class used to instantiate layout XML file into its corresponding view objects which can be used in Java programs. In simple terms, there are two ways to create UI in android. One is a static way and another is dynamic or programmatically.
if you are in a fragment you want
getActivity().getLayoutInflater();
or
LayoutInflater.from(getActivity());
also you can do
View.inflate();
or
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
In Activity you can use like this:
this.getLayoutInflater();
For Fragment you need to replace keyword "this" with "getActivity()"
getActivity().getLayoutInflater();
Hope this will help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With