Listview item not Display in the Fragment Android











up vote
0
down vote

favorite












I have Navigation Drawer with Fragment. I want to Open Fragment on Navigation Drawer. No any Error comes in code but Listview Item Not Display in Fragment. Only Blank Page Display. Following Code. Plzz Help Me.



fragment_blank_fragment_trip2.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.administrator.vtsapplication.BlankFragmentTrip2">

<ListView
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

</LinearLayout>


Activity_listview.xml



<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >




BlankFragmenttrip2.java



package com.example.administrator.vtsapplication;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class BlankFragmentTrip2 extends Fragment {
public BlankFragmentTrip2() {
// Required empty public constructor
}
ViewGroup vg;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"};
vg = (ViewGroup) inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray);

ListView listView = (ListView) vg.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
return inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
}

}









share|improve this question






















  • remove the last line, I think that is returning an empty view. just return the vg and do not send ViewGroup as the method onCreateView()'s return type is only View
    – Devendra Singh
    May 21 '16 at 12:38












  • Thank You for reply me.
    – Monark Patel
    May 23 '16 at 2:47















up vote
0
down vote

favorite












I have Navigation Drawer with Fragment. I want to Open Fragment on Navigation Drawer. No any Error comes in code but Listview Item Not Display in Fragment. Only Blank Page Display. Following Code. Plzz Help Me.



fragment_blank_fragment_trip2.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.administrator.vtsapplication.BlankFragmentTrip2">

<ListView
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

</LinearLayout>


Activity_listview.xml



<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >




BlankFragmenttrip2.java



package com.example.administrator.vtsapplication;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class BlankFragmentTrip2 extends Fragment {
public BlankFragmentTrip2() {
// Required empty public constructor
}
ViewGroup vg;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"};
vg = (ViewGroup) inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray);

ListView listView = (ListView) vg.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
return inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
}

}









share|improve this question






















  • remove the last line, I think that is returning an empty view. just return the vg and do not send ViewGroup as the method onCreateView()'s return type is only View
    – Devendra Singh
    May 21 '16 at 12:38












  • Thank You for reply me.
    – Monark Patel
    May 23 '16 at 2:47













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have Navigation Drawer with Fragment. I want to Open Fragment on Navigation Drawer. No any Error comes in code but Listview Item Not Display in Fragment. Only Blank Page Display. Following Code. Plzz Help Me.



fragment_blank_fragment_trip2.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.administrator.vtsapplication.BlankFragmentTrip2">

<ListView
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

</LinearLayout>


Activity_listview.xml



<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >




BlankFragmenttrip2.java



package com.example.administrator.vtsapplication;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class BlankFragmentTrip2 extends Fragment {
public BlankFragmentTrip2() {
// Required empty public constructor
}
ViewGroup vg;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"};
vg = (ViewGroup) inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray);

ListView listView = (ListView) vg.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
return inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
}

}









share|improve this question













I have Navigation Drawer with Fragment. I want to Open Fragment on Navigation Drawer. No any Error comes in code but Listview Item Not Display in Fragment. Only Blank Page Display. Following Code. Plzz Help Me.



fragment_blank_fragment_trip2.xml



<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.administrator.vtsapplication.BlankFragmentTrip2">

<ListView
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>

</LinearLayout>


Activity_listview.xml



<?xml version="1.0" encoding="utf-8"?> 
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16dip"
android:textStyle="bold" >




BlankFragmenttrip2.java



package com.example.administrator.vtsapplication;


import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class BlankFragmentTrip2 extends Fragment {
public BlankFragmentTrip2() {
// Required empty public constructor
}
ViewGroup vg;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"};
vg = (ViewGroup) inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray);

ListView listView = (ListView) vg.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
return inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
}

}






android xml listview layout fragment






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 21 '16 at 12:33









Monark Patel

4711




4711












  • remove the last line, I think that is returning an empty view. just return the vg and do not send ViewGroup as the method onCreateView()'s return type is only View
    – Devendra Singh
    May 21 '16 at 12:38












  • Thank You for reply me.
    – Monark Patel
    May 23 '16 at 2:47


















  • remove the last line, I think that is returning an empty view. just return the vg and do not send ViewGroup as the method onCreateView()'s return type is only View
    – Devendra Singh
    May 21 '16 at 12:38












  • Thank You for reply me.
    – Monark Patel
    May 23 '16 at 2:47
















remove the last line, I think that is returning an empty view. just return the vg and do not send ViewGroup as the method onCreateView()'s return type is only View
– Devendra Singh
May 21 '16 at 12:38






remove the last line, I think that is returning an empty view. just return the vg and do not send ViewGroup as the method onCreateView()'s return type is only View
– Devendra Singh
May 21 '16 at 12:38














Thank You for reply me.
– Monark Patel
May 23 '16 at 2:47




Thank You for reply me.
– Monark Patel
May 23 '16 at 2:47












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted











You should use your Fragment as this. You are not returning your View.




public class BlankFragmentTrip2 extends Fragment {

String mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"};

public BlankFragmentTrip2() {
// Required empty public constructor
}


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

View rootView = inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray);

ListView listView = (ListView) rootView.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
return rootView;
}

}





share|improve this answer





















  • Thank You for Reply. Its Work and My Problem was solve by using your code.. Thank you.
    – Monark Patel
    May 23 '16 at 2:46











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37362974%2flistview-item-not-display-in-the-fragment-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted











You should use your Fragment as this. You are not returning your View.




public class BlankFragmentTrip2 extends Fragment {

String mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"};

public BlankFragmentTrip2() {
// Required empty public constructor
}


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

View rootView = inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray);

ListView listView = (ListView) rootView.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
return rootView;
}

}





share|improve this answer





















  • Thank You for Reply. Its Work and My Problem was solve by using your code.. Thank you.
    – Monark Patel
    May 23 '16 at 2:46















up vote
0
down vote



accepted











You should use your Fragment as this. You are not returning your View.




public class BlankFragmentTrip2 extends Fragment {

String mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"};

public BlankFragmentTrip2() {
// Required empty public constructor
}


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

View rootView = inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray);

ListView listView = (ListView) rootView.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
return rootView;
}

}





share|improve this answer





















  • Thank You for Reply. Its Work and My Problem was solve by using your code.. Thank you.
    – Monark Patel
    May 23 '16 at 2:46













up vote
0
down vote



accepted







up vote
0
down vote



accepted







You should use your Fragment as this. You are not returning your View.




public class BlankFragmentTrip2 extends Fragment {

String mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"};

public BlankFragmentTrip2() {
// Required empty public constructor
}


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

View rootView = inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray);

ListView listView = (ListView) rootView.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
return rootView;
}

}





share|improve this answer













You should use your Fragment as this. You are not returning your View.




public class BlankFragmentTrip2 extends Fragment {

String mobileArray = {"Android", "IPhone", "WindowsMobile", "Blackberry", "WebOS", "Ubuntu", "Windows7", "Max OS X"};

public BlankFragmentTrip2() {
// Required empty public constructor
}


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

View rootView = inflater.inflate(R.layout.fragment_blank_fragment_trip2, container, false);
ArrayAdapter adapter = new ArrayAdapter<String>(getActivity(), R.layout.activity_listview, mobileArray);

ListView listView = (ListView) rootView.findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
return rootView;
}

}






share|improve this answer












share|improve this answer



share|improve this answer










answered May 21 '16 at 12:38









Jay Rathod RJ

7,92041935




7,92041935












  • Thank You for Reply. Its Work and My Problem was solve by using your code.. Thank you.
    – Monark Patel
    May 23 '16 at 2:46


















  • Thank You for Reply. Its Work and My Problem was solve by using your code.. Thank you.
    – Monark Patel
    May 23 '16 at 2:46
















Thank You for Reply. Its Work and My Problem was solve by using your code.. Thank you.
– Monark Patel
May 23 '16 at 2:46




Thank You for Reply. Its Work and My Problem was solve by using your code.. Thank you.
– Monark Patel
May 23 '16 at 2:46


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f37362974%2flistview-item-not-display-in-the-fragment-android%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

What visual should I use to simply compare current year value vs last year in Power BI desktop

How to ignore python UserWarning in pytest?

Alexandru Averescu