Replacing ListFragment with another ListFragment - android

I have two almost identical ListFragment A & B, except that they draw data from their respective Asynctasker.
onListItemClick at A will result in Fragment A being replaced by B. However, my app always get stuck at the constructor of its CustomAdapter in B.
private class CustomAdapter_B extends ArrayAdapter<MatchType> {
// Stuck Here
CustomAdapter_B() {
super(getActivity(), R.layout.color_match_type_s2, matches_type_s2);
}
Fragment A
public class Fragment A extends ListFragment implements AsyncTaskCompleteListener<ArrayList<MatchType>>{
ArrayList<MatchType> matches_type = new ArrayList<MatchType>();
private ProgressDialog dialog;
private static FirstPageFragmentListener main_caller;
#Override
public void onListItemClick(ListView l, View v, int position, long id) {
//Interface, triggering Fragment Replace in my Fragment Adapter
main_caller.onMySignalWithNum(1, (matches_type.get(position).getLink()));
}
#Override
public void onAttach(Activity activity) {
super.onAttach(activity);
this.dialog.show();
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// AsyncTasker to draw data for ArrayAdapter
LoadMatchType lmt = new LoadMatchType(this);
lmt.execute();
}
#Override
public void onTaskComplete(ArrayList<MatchType> result) {
dialog.dismiss();
//result.remove(result.size()-1);
matches_type = result;
setListAdapter(new CustomAdapter());
}
}
//Custom Adapter
private class CustomAdapter extends ArrayAdapter<MatchType> {
CustomAdapter() {
super(getActivity(), R.layout.color_match_type, matches_type);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = convertView;
if (row == null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
row = inflater.inflate(R.layout.color_match_type, parent, false);
}
TextView tv_type = (TextView) row.findViewById(R.id.textView_type);
tv_type.setText(matches_type.get(position).getType());
TextView tv_tweet = (TextView) row.findViewById(R.id.textView_tweet);
tv_tweet.setText(matches_type.get(position).getTweet());
TextView tv_tph = (TextView) row.findViewById(R.id.textView_tph);
tv_tph.setText(matches_type.get(position).getTph());
return row;
}
}
public static Fragment newInstance(
FirstPageFragmentListener pageFragmentListener) {
// TODO Auto-generated method stub
footOddsFragment frag = new footOddsFragment();
main_caller = pageFragmentListener;
return frag;
}
}
//INTERFACE
interface AsyncTaskCompleteListener<T> {
public void onTaskComplete(ArrayList<MatchType> result);
}
Fragment B is about the same.
The app will get stuck at Fragment B's CustomAdapter constructor and the screen will be blank.
Oh, and everything works fine if I abandon Fragment B and just call the Asynctasker_B in onListItemClick in Fragment A. Just that I can't press back to view the previous list.

Forget Fragment B. Override your back press, put an if in there to determine if List B is active, if it is, change it back, otherwise perform the normal back function.
public void onBackPressed() {
// Code here to change list or go back.
return;
}

Related

Android how to open fragment from listview element

In MainActivity is FrameLayout MainContainer. I load there a fragment TrainerMyGroups, there is a Listview where I add a few elements (each element has some strings) by use TrainerGroupsAdapter. Actually I want to replace fragment TrainerMyGroups by another (for example TrainersInfo) by click on list's element.
My TrainerGroupsAdapter is:
public class TrainerGroupsAdapter extends ArrayAdapter {
List list = new ArrayList();
public TrainerGroupsAdapter(Context context, int resource) {
super(context, resource);
}
static class Datahandler{
TextView name;
TextView when;
TextView where;
LinearLayout ll;
}
#Override
public void add(Object object) {
super.add(object);
list.add(object);
}
#Override
public int getCount() {
return this.list.size();
}
#Override
public Object getItem(int position) {
return this.list.get(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row;
row=convertView;
Datahandler handler;
SharedPreferences pref = getContext().getSharedPreferences("pref", Context.MODE_PRIVATE);
if(convertView==null){
LayoutInflater inflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row= inflater.inflate(R.layout.list_mygroups,parent,false);
handler = new Datahandler();
handler.name = (TextView) row.findViewById(R.id.trainermygroupslistname);
handler.where = (TextView) row.findViewById(R.id.trainermygroupslistwhere);
handler.when = (TextView) row.findViewById(R.id.trainermygroupslistwhen);
handler.ll=(LinearLayout) row.findViewById(R.id.trainermygroupslistlayout);
row.setTag(handler);
}
else {
handler = (Datahandler)row.getTag();
}
TrainerGroupsDataProvider dataProvider;
dataProvider = (TrainerGroupsDataProvider)this.getItem(position);
handler.name.setText(dataProvider.getName());
handler.when.setText(dataProvider.getWhen());
handler.where.setText(dataProvider.getWhere());
handler.ll.setBackgroundColor(Color.parseColor(pref.getString(TRANSP_KEY, "#CC") + dataProvider.getColor()));
handler.ll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
getFragmentManager().beginTransaction().replace(R.id.MainContainer, new TrainerInfo()).addToBackStack(null).commit();
}
});
return row;
}
}
It doesn't work but method OnClick is probably good because if I replace getFragmentManager().beginTransaction().replace(R.id.MainContainer, new TrainerInfo()).addToBackStack(null).commit(); to code for change some strings (name, when tc) it works. Problem is in getFragmentMenager(), Android Studio shows message that I have to create Getter and AS's suggestion is to generate in OnClick method:
private FragmentManager fragmentManager;
public FragmentManager getFragmentManager() {
return fragmentManager;
}
then problem is in the second argument in replace, I have error that it has to be Fragment (Im sure that TrainersInfo() is fragment because I use it in other place and it works).
How can I solve this problem or what is the best way to open fragment by click on lise's element in another fragment?
#UPDATE2
Better then replacing the Fragment inside the adapter is to say your activity that it should replace the fragment. This can be done with an interface which you implement inside your Activity:
public class TrainerGroupsAdapter extends ArrayAdapter {
// The interface which you have to implement in your activity
public interface OnChangeFragmentListener {
void changeFragment();
}
List list = new ArrayList();
private OnChangeFragmentListener m_onChangeFragmentListener;
public TrainerGroupsAdapter(Context context, int resource) {
super(context, resource);
m_onChangeFragmentListener = (OnChangeFragmentListener) context;
}
// Your other code
}
The OnClickListener in your getView Method:
handler.ll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Call the method which change the fragment
m_onChangeFragmentListener.changeFragment();
}
});
The Activity:
public class MainActivity extends AppCompatActivity implements TrainerGroupsAdapter.OnChangeFragmentListener {
//...
// Your Other code
// Implement the method which is called in the adapter and replace the fragment here
#Override
public void changeFragment() {
getFragmentManager().beginTransaction().replace(R.id.MainContainer, new TrainerInfo()).addToBackStack(null).commit();
}
}
#UPDATE1
You need an activity context for getSupportFragmentManager() and getFragmentManager().
You can change the Context parameter of the constructor to Activity and create a member variable in your class for the activity so you can use it later:
public class TrainerGroupsAdapter extends ArrayAdapter {
List list = new ArrayList();
private Activity m_activity;
public TrainerGroupsAdapter(Activity context, int resource) {
super(context, resource);
m_activity = context;
}
// Your other code
}
The OnClickListener in your getView method:
handler.ll.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
m_activity.getFragmentManager().beginTransaction().replace(R.id.MainContainer, new TrainerInfo()).addToBackStack(null).commit();
}
});
Was searching for a similar answer, and got one from a good friend and android dev. I think it's the easiest one to understand and implement. SO I am usually creating a helper class in which I put my two static functions for opening fragments (as replace or dialog):
For example the replace one:
public static void openFragmentReplace(Activity activity, int idOfPlacement, Fragment fragment)
final FragmentManager fm = ((FragmentActivity)activity).getSupportFragmentManager();
final FragmentTransaction fragmentTransaction = fm.beginTransaction();
fragmentTransaction.replace(idOfPlacement, fragment);
fragmentTransaction.commit();
}
and the dialog one:
public static void openFragmentAsDialog(Activity activity, DialogFragment fragment) {
final FragmentManager fm = ((FragmentActivity)activity).getSupportFragmentManager();
fragment.show(fm, "tag");
}
Then I just call it from where I want like this:
Helper.openFragmentReplace(getActivity(),R.id.PlaceForFragment,FragmentClass newFrag);
This seems like the best and easiest way to do it!
Hope it helps.

Android ViewPager onClickListener reacts even if other fragment is show

I have a ViewPager which holds two fragments. one fragment contains nothing and the other fragment contains a gridview with ImageViews.
The ImageViews have a onClickListener set.
Everything works fine so far... but when i am on the fragment which contains nothing and tap somewhere the onClickListener of the other fragments gridviews imagview reacts to my click even if its elements aren't visible.
I could change my onClickListener so that it checks which fragment is shown but is that really the way i should do it ??? it feels a bit dirty
This is my FragmentStatePageAdapter
public class OwnPagerAdapter extends FragmentStatePagerAdapter{
private BackgroundImage backgroundImage = new BackgroundImage();
private Apps apps = new Apps();
private Home_Screen ac;
public OwnPagerAdapter(FragmentManager fm, Home_Screen activity) {
super(fm);
this.ac = activity;
}
#Override
public Fragment getItem(int position) {
if(position == 0) {
return backgroundImage;
}else if(position == 1) {
return this.apps;
}
return null;
}
#Override
public int getCount() {
return 2;
}
}
This is my BaseAdapter
public class AppAdapter extends BaseAdapter {
private AppLauncher launcherListener = new AppLauncher();
private ArrayList<ApplicationInfo> appList;
private Context ctx;
public AppAdapter(ArrayList<ApplicationInfo> listOfApps, Context ctx){
this.appList = listOfApps;
this.ctx = ctx;
}
#Override
public int getCount() {
return this.appList.size();
}
#Override
public Object getItem(int i) {
ImageView v = new ImageView(this.ctx);
v.setImageDrawable(this.appList.get(i).loadIcon(this.ctx.getPackageManager()));
return v;
}
#Override
public long getItemId(int i) {
return 0;
}
#Override
public View getView(final int i, View view, ViewGroup viewGroup) {
if(view != null){
((ImageView) view).setImageDrawable(this.appList.get(i).loadIcon(this.ctx.getPackageManager()));
view.setTag(i);
return view;
}
ImageView v = new ImageView(this.ctx);
v.setImageDrawable(this.appList.get(i).loadIcon(this.ctx.getPackageManager()));
v.setScaleType(ImageView.ScaleType.CENTER);
v.setOnClickListener(launcherListener);
v.setTag(i);
return v;
}
private class AppLauncher implements View.OnClickListener {
#Override
public void onClick(View view) {
ctx.startActivity(ctx.getPackageManager().getLaunchIntentForPackage(appList.get((int) view.getTag()).packageName));
}
}
}
Thats my fragment class
public class Apps extends Fragment implements LoaderManager.LoaderCallbacks<ArrayList<ApplicationInfo>>{
private GridView gridview;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
getLoaderManager().initLoader(1, null, this).forceLoad();
View rootView = inflater.inflate(R.layout.fragment_apps, container, false);
this.gridview = (GridView)rootView.findViewById(R.id.apptable);
return rootView;
}
#Override
public Loader<ArrayList<ApplicationInfo>> onCreateLoader(int id, Bundle args) {
return new AppLoader(getActivity());
}
#Override
public void onLoadFinished(Loader<ArrayList<ApplicationInfo>> loader, ArrayList<ApplicationInfo> data) {
Toast.makeText(getActivity(), "Done with loading Apps", Toast.LENGTH_LONG).show();
this.gridview.setAdapter(new AppAdapter(data,getActivity()));
}
#Override
public void onLoaderReset(Loader<ArrayList<ApplicationInfo>> loader) {
}
}
While i cant find any specific cause to your problem i have to suggest a cleaner way of achieving the same result you're seeking, using an inner class just to capture click events is dirty and just unnecessary. it is quite possible that using this method will solve your problem as well.
Instead of using AppLauncher class which implements an OnClickListener and then set it manualy for each item, why not using an OnItemClickListener on the whole gridview ? it will take care of click events for each item and is specific only to items inside your gridview so you dont have to worry about any leaks like you would using inner classes.
In your fragment implement OnItemClickListener :
public class Apps extends Fragment implements LoaderManager.LoaderCallbacks<ArrayList<ApplicationInfo>>, OnItemClickListener
Then in your fragment's onCreate simply set the adapter to the gridview:
gridview.setOnItemClickListener(this);
and implement the necessary method:
#Override
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
getActivity().startActivity(getActivity().getPackageManager().getLaunchIntentForPackage(appList.get(position).packageName));
}
Now you can remove the OnClickListener logic from your gridview's adapter and it should work fine, my guess is it will also solve your problem, and even if not, hey at least you end up with a cleaner code.
Another thing i find odd about your code is that you override getItemId() yet always return 0, make sure this is the normal behaviour you're looking for since im not sure it is.
Good luck.

How to prevent my ListView inside a Fragment to store the selected item and highlight it?

I have got a fragment, that contains a ListView, where the user can select one item (single choice). The selected one is highlighted through a color. When replacing the fragment by another one and taking it back again, still the item is selected, although the fragments onAttach() ... onViewCreated methods are recalled.
How can I prevent my app from doing this? I would like to always have a fresh and unselected list, when I show the fragment containing the list view.
Here is my code:
public class ServerListFragment extends Fragment {
//////////////////////////
// CONSTANTS
//////////////////////////
private static final String TAG = ServerListFragment.class.getName();
//////////////////////////
// PRIVATE VARIABLES
//////////////////////////
private ServerListFragmentCallbacks mCallback;
private Button mNextButton;
private ListView mListView;
//////////////////////////
// CONSTRUCTOR
//////////////////////////
public ServerListFragment() {
}
//////////////////////////
// LIFECYCLE
//////////////////////////
// 1 ON ATTACH
#Override
public void onAttach(Activity activity) {
Log.i(TAG, "onAttach()");
super.onAttach(activity);
// set up callback reference
try {
mCallback = (ServerListFragmentCallbacks) activity;
} catch (ClassCastException e) {
throw new ClassCastException("Activity must implement ServerListFragmentCallbacks.");
}
}
// 2 ON CREATE
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i(TAG, "onCreateView()");
View v = inflater.inflate(R.layout.fragment_server_list, container, false);
return v;
}
// 3 ON CREATE VIEW
// 4 ON ACTIVITY CREATED
// 5 ON START
// 6 ON RESUME
// 7 ON PAUSE
// 8 ON STOP
// 9 ON DESTROY VIEW
// 10 ON DESTROY
// 11 ON DETACH
#Override
public void onDetach() {
Log.i(TAG, "onDetach()");
super.onDetach();
}
//////////////////////////
// OVERRIDE METHODS
//////////////////////////
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
Log.i(TAG, "onViewCreated()");
super.onViewCreated(view, savedInstanceState);
// next button
mNextButton = (Button) view.findViewById(R.id.server_list_next_button);
mNextButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mCallback.onServerListFragmentNextButtonClick();
}
});
// list view containing servers
mListView = (ListView) view.findViewById(R.id.server_list_view);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mListView.setSelection(position);
mListView.setItemChecked(position, true);
mNextButton.setEnabled(true);
}
});
mListView.setAdapter(new ServerListAdapter(getActivity(), DummyData.getServerList()));
}
//////////////////////////
// CALLBACK INTERFACE
//////////////////////////
public interface ServerListFragmentCallbacks{
public void onServerListFragmentNextButtonClick();
}
}
I hope someone is able to help.
Override onPause() in your fragment and call
mListView.setItemChecked(position, false);
also you will need to store the position of item that is checked globally, so that you can access the same in your onPause() method.

Displaying a view when clicking a item in listview

I have this listview which is a list of news items. I want to display a detailed version of a particular news item when that news item is clicked in the listview.
So far i was able to create the listview and display the news items in a listview. (NOTE: news items are taken from a JSON)
I was able to display a view when a news item is clicked in the listview. but the PROBLEM is when a listview item is clicked, a view of detailed version of news items is displayed BUT it shows all the detailed version of news.
I WANT TO SHOW ONLY THE DETAILED VERSION OF THE NEWS ITEM THAT WAS CLICKED. how can i do this?
after researching i think i should use a bundle for this.but i have no idea how to do this.
I'll post my classes here
NewsFragment.java
public class NewsFramgment extends Fragment {
private ListView listView;
private ArrayList<BaseElement> News;
private LazyAdapter adapter;
private Activity activity;
private CommonVariable commonVariable;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.news_fragment, container,
false);
activity = this.getActivity();
commonVariable = (CommonVariable) activity.getApplication();
listView = (ListView) view.findViewById(R.id.list);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,
int position, long id)
{
android.support.v4.app.Fragment detail = new NewsDetailFragment();
android.support.v4.app.FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().add(R.id.content_frame, detail).addToBackStack("back").commit();
}
});
new BackGround().execute();
return view;
}
public class BackGround extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
News = JSONServices.getNewsDescription();
return null;
}
#Override
/* check again */
protected void onPostExecute(Void result) {
commonVariable.setNewsDescription(News);
adapter = new LazyAdapter(News, activity,Element.NEWS_LIST.getType());
listView.setAdapter(adapter);
super.onPostExecute(result);
}
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
}
}
NewsDetailFramgment.java
public class NewsDetailFragment extends Fragment {
private View view1;
private ArrayList<BaseElement> newsdetail;
private LazyAdapter adapter;
private Activity activity;
private CommonVariable commonVariable;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.newsdetail_fragment, container,
false);
activity = this.getActivity();
commonVariable = (CommonVariable) activity.getApplication();
view1 = (View) view.findViewById(R.id.list);
new BackGround().execute();
return view;
}
public class BackGround extends AsyncTask<Void, Void, Void> {
#Override
protected Void doInBackground(Void... params) {
newsdetail = JSONServices.getNewsDescription();
return null;
}
#Override
/* check again */
protected void onPostExecute(Void result) {
commonVariable.setTheater(newsdetail);
adapter = new LazyAdapter(newsdetail, activity,Element.NEWS_DETAIL.getType());
((AdapterView<ListAdapter>) view1).setAdapter(adapter);
super.onPostExecute(result);
}
#Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
}
}
It looks like you're calling newsdetail = JSONServices.getNewsDescription(); and then assigning that result to your adapter in NewsDetailFragment. What is being returned by JSONServices.getNewsDescription();? I imagine it is all of the NewsDetail articles.
#Raghunandan is right, the example shows how to handle two fragments in an activity and show the 'Detail' fragment based on which item was selected in the 'News' list.
You could implement the calls in your parent Activity as shown in the example under 'Implement the Interface'.
YourParentActivity.java
public static class YourParentActivity extends Activity {
implements NewsFragment.OnHeadlineSelectedListener{
...
}
public void onArticleSelected(int position) {
NewsDetailFramgment articleFrag = (NewsDetailFramgment)
getSupportFragmentManager().findFragmentById(R.id.news_detail_framgment);
if (articleFrag != null) {
// If article frag is available, we're in two-pane layout...
// Call a method in the NewsDetailFramgment to update its content
articleFrag.updateArticleView(position);
} else {
// Otherwise, we're in the one-pane layout and must swap frags...
// Create fragment and give it an argument for the selected article
NewsDetailFramgment newFragment = new NewsDetailFramgment ();
Bundle args = new Bundle();
args.putInt(NewsDetailFramgment.ARG_POSITION, position);
newFragment.setArguments(args);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack so the user can navigate back
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(null);
// Commit the transaction
transaction.commit();
}
}
}
Notice that onArticleSelected() accepts int position? This is the position in the News Headlines adapter that was clicked. You can use this to get the corresponding News Detail item from your Details result.
This is purely an outline based on the example, but should show you what you need to do in your parent activity.
Read the example and add the relevant parts to your fragments (look at 'Define an Interface' for changes to your NewsFragment.java).
Edit
You need to define an interface in your NewsFragment class as shown in the documentation under 'Define an Interface'.
// Container Activity must implement this interface
public interface OnHeadlineSelectedListener {
public void onArticleSelected(int position);
}
This provides a callback to your parent class to handle when a news headline is pressed with the position of the headline which was selected. In the example it calls onArticleSelected(int position); in your parent activity to then populate the NewsDetailFragment.

Keep list fragment selected item position on orientation change

I have a list fragment on the left of another fragment and is essentially the standard click an item and update the right fragment pattern. When they click an item in the list fragment they are choosing the news article category and I need to keep whatever one is selected when they rotate the device. How do I do that? My current code doesn't work.
My code is as follows:
public class SideMenuFragment extends ListFragment {
ArrayList<SideItem> sideItems;
SideAdapter sideAdapter;
public SideMenuFragment() {
this.setRetainInstance(true);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.list, null);
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
sideItems = new ArrayList<SideItem>();
...add bunch of items
sideAdapter = new SideAdapter(getActivity(), sideItems);
getListView().setVerticalScrollBarEnabled(false);
setListAdapter(sideAdapter);
if (savedInstanceState != null) {
sideAdapter.setSelectedItem(savedInstanceState.getInt("sidePosition"));
sideAdapter.notifyDataSetChanged();
}
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("sidePosition", sideAdapter.getSelectedItem());
}
#Override
public void onListItemClick(ListView lv, View v, int position, long id) {
if (sideAdapter.getSelectedItem() != position) {
sideAdapter.setSelectedItem(position);
sideAdapter.notifyDataSetChanged();
}
switch (position) {
...switch the fragment depending on position.
}
}
// the meat of switching the above fragment
private void switchFragment(Fragment fragment, String title) {
if (getActivity() == null)
return;
if (getActivity() instanceof HomeActivity) {
HomeActivity a = (HomeActivity) getActivity();
a.switchContent(fragment, title);
}
}
}
First, add your Fragment in xml if the Activity layout.
In Activity onCreate
getFragmentManager().findFragmentById(R.id.youtfragmentid).setRetainInstance(true)
This means that the fragment will not be recreated on activity recreate.
Don't change your ListView in onActivityCreated - because it will be rebuilt every time orientation changes. If you set a new adapter - the states of children will be reseted.
Add checking for null or a boolean flag that the view already was created.
Next time onActivityCreated gets called, your list adapter should not change
if (sideAdapter == null) {
sideAdapter = new SideAdapter(getActivity(), sideItems);
getListView().setVerticalScrollBarEnabled(false);
setListAdapter(sideAdapter);
}
Also, don't create new view in onCreateView instead use previously created one.
private View v;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
if (v == null) {
v = inflater.inflate(R.layout.list, null);
} else {
// detatch from container and return the same view
((ViewGroup) getListView().getParent()).removeAllViews();
}
return v;
}

Categories

Resources