ListView not showing in fragment

I have implemented my own navigation drawer that comes from the left screen in an android app. The problem is ListView

it doesn't show up and I can't figure out why.

This is the onCreateView

snippet method that the list is in (first I initialize the layout header and then the list with my custom adapter):

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {


    View firstAccessView = inflater.inflate(R.layout.fragment_navigation_drawer, null);
    this.profileImageDrawer = (ImageView) firstAccessView.findViewById(R.id.imageViewProfileDrawer);
    RoundImage roundedImage = new RoundImage(BitmapFactory.decodeResource(getResources(), R.mipmap.iconuseranonymous));


    //this.profileImageDrawer.setImageDrawable(roundedImage);

    Picasso.with((Activity) getActivity()).load("https://graph.facebook.com/" + Profile.getCurrentProfile().getId() + "/picture?height=105&width=105")
            .placeholder(roundedImage)
               .transform(new CircleTransform()).fit().centerCrop().into(this.profileImageDrawer);
    this.nameSurnameDrawer = (TextView) firstAccessView.findViewById(R.id.textViewDrawner);
    this.nameSurnameDrawer.setText(Profile.getCurrentProfile().getFirstName() + " " + Profile.getCurrentProfile().getLastName());

    List<String> example = new ArrayList<String>();
    example.add("Profile");
    example.add("Ask");
    example.add("Logout");
    this.adapter = new DrawerAdapter(getActivity(), example);
    list = (ListView) firstAccessView.findViewById(R.id.listDrawer);
    list.setAdapter(adapter);

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    });


    list.setItemChecked(mCurrentSelectedPosition,true);

    return firstAccessView;
}

      

This is my adapter code

 private Activity context;
private List<String> list;
private View view;
private TextView textView;

public DrawerAdapter(Activity context, List<String> list) {
    super(context, R.layout.drawerlist_layout);
    this.context=context;
    this.list = list;

}

public View getView(int position, View convertView, ViewGroup parent) {

    LayoutInflater inflater = context.getLayoutInflater();
    view = inflater.inflate(R.layout.drawerlist_layout, null);

    textView = (TextView) view.findViewById(R.id.sectionDrawer);
    textView.setText(this.list.get(position));
    textView.setTextColor(Color.BLACK);

    return view;
}

      

and finally this is the layout of my fragment: at the top I have a header with an image and TextView

and then I have my customListView

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:layout_weight="0.40"
    android:background="#ffb200">

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:id="@+id/imageViewProfileDrawer"
        android:layout_gravity="left|center_vertical"
        android:layout_marginLeft="20px" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceSmall"
        android:text="Medium Text"
        android:id="@+id/textViewDrawner"
        android:layout_gravity="right|bottom"
        android:layout_marginBottom="10dp"
        android:layout_marginRight="10dp"
        android:textColor="#ffffff"
        android:textStyle="bold"
        android:textIsSelectable="true" />

</FrameLayout>


<ListView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="262dp" android:choiceMode="singleChoice"
    android:divider="#cecece" android:dividerHeight="1dp"
    android:background="#FFFFFF"
    tools:context="com.bellantoni.chetta.lieme.NavigationDrawerFragment"
    android:id="@+id/listDrawer"
    android:drawSelectorOnTop="false"
    android:smoothScrollbar="true"
    android:longClickable="false"
    android:nestedScrollingEnabled="false"
    android:footerDividersEnabled="false"
    android:headerDividersEnabled="true"
    android:paddingLeft="10dp"
    android:stackFromBottom="false"
    android:scrollingCache="false"
    android:paddingRight="10dp"
    android:textFilterEnabled="false"
    android:theme="@style/Base.Widget.AppCompat.ActionMode"
    android:textAlignment="center"
    android:transitionGroup="true"
    android:layout_weight="0.60" />

      

+3


source to share


2 answers


I found my mistake in this line of code:

super(context, R.layout.drawerlist_layout);



where I missed the third parameter which is equal in this case list

, so it should be

super(context, R.layout.drawerlist_layout,list);

+1


source


Set FameLayout

and ListView

layout_width

to 0dp

instead match_parent

if you want to use layout_weight.



0


source







All Articles