3

GetLayoutInflater () in the fragment

 3 years ago
source link: https://www.codesd.com/item/getlayoutinflater-in-the-fragment.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

GetLayoutInflater () in the fragment

advertisements

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?


if you are in a fragment you want

getActivity().getLayoutInflater();

LayoutInflater.from(getActivity());

also you can do

View.inflate();

LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

Related Articles

Should business logic be in the fragment or activity above?

I'm trying to use fragments and a list view with an array adapter, and having trouble calling my method from the onClickListener in the array adapter. If I understand the pattern correctly, a fragment should be self-sufficient, so I want to put my bu

ListView is not displayed in the fragment

I implemented my own navigation drawer that comes from the left screen in my android application. The problem is that the ListView it is not visible and I can't figure out why. This is the method onCreateView of the fragment where the list is (first

Android - ListFragment in DialogFragment (AlertDialog): The fragment has no view

I'm trying to create a DialogFragment with a ListFragment nested inside of it. I'm using the nested fragment that was added in the 4.2.2 I'm using it with support library so my api version shouldn't matter (for the record, my os version is also 4.2.2

GoogleMap in the fragment is null

I'm trying to load a google map in a fragment. The problem is that when I make the call to get the GoogleMap object, the call to findFragmentById is always coming back null. I've looked at every post out there and tried almost all of them and can't f

Android: onCreateOptionsMenu is called but the action bar menu is not updated in the fragment

I am using drawerlayout in activity with several fragments. By clicking the navigation item, I switch the fragment this way: switch (index) { case 0: if (checkinFragment == null) { checkinFragment = new CheckinFragment(); ft.add(R.id.main_container,

Restore the Fragment state after changing configuration if the layout of the activity changes

My Activity has a one-pane layout in portrait and a two-pane layout in landscape, using Fragments. I'd like the system to restore all the views after an orientation change, but I don't know where to start. Is this even possible considering the layout

Android animation is not smooth between the fragment

Important information: These are my animations: R.anim.fragment_animation_in: <!-- The info window in animation --> <set xmlns:android="http://schemas.android.com/apk/res/android" > <alpha android:duration="500" android:

Javascript: get a notification when the fragment is added to the DOM

What I want I'm loading a fragment of HTML from server side with AJAX, and I'm appending it to the document, and I would like a way to get notified when the fragment is fully added into the dom. I'm doing something like this: // Load photos.html from

NullPointerException when using the fragment in Activity

There are some fragments in my activity. private MainFragment mMainFragment; ... //other fragments Here's my PagerAdapter. private class MainPagerAdapter extends FragmentPagerAdapter { ... @Override public Fragment getItem(int position) { if (DEBUG)

Do not reload the Fragment data after the back layer

I have a fragment (MyListFragment) which is a Fragment, i have a list there called myList this list gets filled with json data onCreateView(). myList -> onItemClick -> open details fragment after i press the back button the myList list gets reloaded

Refresh or force redraw the fragment

I have a fragment that inflates an xml layout. My requirement is to update the text size on all my views inside my fragment when my Activity is resumed. I tried fragment.getView().invalidate(); which didn't seem to do the work. I also tried fragment.

ProgressBar in the fragment

I have + and - buttons in fragment and by pressing them i need to change the progress of ProgressBar, but instead i get NullPointException In MainActivity: public void selectVentilatorFunction(View view) { prg = (ProgressBar)view.findViewById(R.id.ve

Delete only the fragment when you press

I create sample app to show some data to user when user start specific activity and click on specific button the app start new fragment (only fragment added to activity for now ) my problem is when user click back the fragment and the activity remove

How to make the fragment appear under TabLayout in the activity?

In my activity I have: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width=&

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK