Got the fragment list adaptor working a little better

Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-05-11 12:05:43 -04:00
parent 69597150ea
commit 756f5aea86

View File

@@ -24,6 +24,7 @@ import com.TwentyCodes.android.LocationRinger.debug.Debug;
/** /**
* This Adaptor Class will be used to display fragments in a ListFragment. * This Adaptor Class will be used to display fragments in a ListFragment.
* TODO * TODO
* + Get this code working
* + Add/Remove fragments on the fly * + Add/Remove fragments on the fly
* @author ricky barrette * @author ricky barrette
*/ */
@@ -114,20 +115,21 @@ public class FragmentListAdaptor extends BaseAdapter {
convertView.setTag(holder); convertView.setTag(holder);
//add the fragment to the new view //add the fragment to the new view
transaction.add(holder.view.getId(), getItem(position), holder.tag); // transaction.add(holder.view.getId(), getItem(position), holder.tag);
transaction.replace(holder.view.getId(), getItem(position),holder.tag);
} else { } else {
// Get the ViewHolder back to get fast access to the Old Views // Get the ViewHolder back to get fast access to the Old Views
holder = (Holder) convertView.getTag(); holder = (Holder) convertView.getTag();
Fragment shown = mFragmentManager.findFragmentByTag(holder.tag); Fragment shown = mFragmentManager.findFragmentByTag(holder.tag);
//replace the old fragment with a new one //replace the old fragment with a new one
transaction.addToBackStack(holder.tag);
holder.tag = createTag(position); holder.tag = createTag(position);
if(shown != null) if(shown != null)
transaction.remove(shown); transaction.remove(shown);
transaction.add(holder.view.getId(), getItem(position), holder.tag); // transaction.add(holder.view.getId(), getItem(position), holder.tag);
transaction.addToBackStack(null); transaction.replace(holder.view.getId(), getItem(position),holder.tag);
} }
transaction.commit(); transaction.commit();
return convertView; return convertView;