How come position information isn't being passed to my fragments? - android

I have an Activity that is largely unmodified form the default Android Studio example for a tabbed activity. Its FragmentPagerAdapter is modified to display all 50 United States, with 50 corresponding tabs displaying their names. This works until a fragment is destroyed, but when it's re-created, it's not told which tab it's on. Why does this happen?
The following are all the methods that I think could be part of the problem:
public class MainQuizActivity extends Activity implements ActionBar.TabListener {
...
public class SectionsPagerAdapter extends FragmentPagerAdapter {
...
#Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page.
// Return a PlaceholderFragment (defined as a static inner class below).
return
questionFragments[position] == null
? questionFragments[position] = QuestionFragment.newInstance(position)
: questionFragments[position];
}
...
}
...
}
...
public class QuestionFragment extends Fragment {
...
public static QuestionFragment newInstance(int stateIndex) {
System.out.println("Creating new instance for state #" + stateIndex);
QuestionFragment fragment = new QuestionFragment();
Bundle args = new Bundle();
args.putInt(States.BUNDLE_KEY, stateIndex);
fragment.setArguments(args);
return fragment;
}
...
#Override
public View onCreateView(
LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
System.out.println("~onCreateView");
View rootView = inflater.inflate(
R.layout.fragment_main_quiz, container, false);
webView = (WebView)rootView.findViewById(R.id.webView);
initState(savedInstanceState);
return rootView;
}
private void initState(Bundle args) {
if (state == null) {
System.out.println("Bundle: " + args);
if (args == null)
args = getArguments();
System.out.println("Bundle is now: " + args);
int stateIndex = args.getInt(States.BUNDLE_KEY);
System.out.println("Gonna be state #" + stateIndex);
state = States.values()[stateIndex];
System.out.println("Gonna be " + state);
}
else
System.out.println("State already exists! (yay!)");
String path = state.getImageURL();
System.out.println("Opening image at " + path);
webView.loadUrl(path);
webView.setBackgroundColor(0x00000000);
}
#Override
public void onCreate(Bundle savedInstanceState) {
System.out.println("~onCreate");
super.onCreate(savedInstanceState);
if (webView == null)
webView = (WebView)(getActivity().findViewById(R.id.webView));
System.out.println("onCreate: webView == " + webView);
System.out.println("onCreate: bundle == " + savedInstanceState);
if (webView != null
&& savedInstanceState != null)
initState(savedInstanceState);
}
...
}
I saved this in the bundle with the key States.BUNDLE_KEY (which is "STATE"), but the bundle it's given does not have that key in it the second time. For debugging purposes, I overrode all on* methods that deal with loading and unloading with empty ones like:
#Override public void onResume(){
System.out.println("~onResume");
super.onResume();}
Of course, there are also more debugging outputs that I threw in.
I hope this video I recorded helps illustrate the issue: http://youtu.be/cmbR_2rvpX4
The console dump for the video is in this pastebin: http://pastebin.com/rxAP7qda
And, if all this still doesn't help, here's its git: https://github.com/Supuhstar/US-State-Quiz-App
Even after all this, I feel I'm not giving the right information. Please ask for less or more if you think this can be put better.

You're not initializing things properly in your QuestionFragment. First of all there's no need to call the initState(savedInstanceState); method in both the onCreate() and onCreateView() callbacks. Call it in onCreateView() and remove entirely the onCreate() method:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
System.out.println("~onCreateView");
View rootView = inflater.inflate(R.layout.fragment_main_quiz, container, false);
webView = (WebView)rootView.findViewById(R.id.webView);
guessSpinner = (Spinner)getActivity().findViewById(R.id.guess_spinner);
initState();
initGuesser();
return rootView;
}
Your initState(savedInstanceState) method is also a bit too complicated for what it should do:
private void initState() {
Bundle args = getArguments();
if (args == null) {
throw new IllegalArgumentException("The arguments should be valid!");
}
System.out.println("Bundle is now: " + args);
int stateIndex = args.getInt(States.BUNDLE_KEY);
System.out.println("Gonna be state #" + stateIndex);
state = States.values()[stateIndex];
System.out.println("Gonna be " + state);
String path = state.getImageURL();
System.out.println("Opening image at " + path);
webView.loadUrl(path);
webView.setBackgroundColor(getResources().getColor(R.color.transparent));
}

Related

viewpager2 get adapter of current fragment cause NullPointerException

I use mAdapter.getTotalPriceInRecyclerView() to get total price in current selected page in viewpage2+Tablayout.
but it will cause NullPointerException because the mAdapter created in onCreateView method.
How could I make sure mAdapter has been initialed?
I use viewpage2 to create new Fragment (TheFragmentClass.newInstance()) rather than beginTransaction().commit
private boolean createFragment(int tabLimited) {
if (mVp2Adapter.getItemCount() >= tabLimited) {
return false;
}
String tabText = getTimeOfHMS();
SettlementProductItemFragment fragment = SettlementProductItemFragment.newInstance(); // new intance
mVp2Adapter.addFragment(tabText, fragment); // add to viewpage2's adapter
mTabSettlementProduct.selectTab(mTabSettlementProduct.getTabAt(
mVp2Adapter.getItemCount() - 1));
return true;
}
public void addFragment(String title, Fragment fragment) {
if (mFragmentTitles.contains(title)) {
Log.e(TAG, "addFragment failed: mFragmentTitles.contains(" + title + ")");
return;
}
mFragments.put(title, fragment);
mFragmentTitles.add(title);
updateHashMap();
notifyItemInserted(mFragmentTitles.size() - 1);
}
Here's my SettlementProductItemFragment class.
public class SettlementProductItemFragment extends Fragment {
private RecyclerView mRvProductInFragment;
public SettlementProductItemFragment() {
}
public static SettlementProductItemFragment newInstance() {
SettlementProductItemFragment fragment = new SettlementProductItemFragment();
Bundle args = new Bundle();
fragment.setArguments(args);
return fragment;
}
private SettlementProductItemRecyclerViewAdapter mAdapter;
public double getTotalPriceInFragment() {
if (mAdapter == null) {
throw new NullPointerException("mAdapter(SettlementProductItemRecyclerViewAdapter) CAN NOT BE NULL");
}
return mAdapter.getTotalPriceInRecyclerView();
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_settlement_product_item_list, container, false);
Log.e("getTotalPriceInFragment", "onCreateView: " + view.getClass().toString());
// Set the adapter
if (view instanceof RecyclerView) {
Context context = view.getContext();
mAdapter = new SettlementProductItemRecyclerViewAdapter(context, getProducts());
mRvProductInFragment = (RecyclerView) view;
mRvProductInFragment.setLayoutManager(new LinearLayoutManager(context));
mRvProductInFragment.setAdapter(mAdapter);
}
return view;
}
}
Since you use ViewPager2 you have setOffscreenPageLimit method (offscreenPageLimit property in Kotlin) it will retain (and precreate also) your fragment when you initilize your ViewPager2.
The problem that i see in your code is that you modify items in ViewPager adapter. It isn't default snippet for using viewPager2 + tabs, so make sure you do it well, check for ViewPager2 samples by Google
Alternatively, you can create property in your SettlementProductItemFragment e.g isInitialized and observe it in your host fragment. In that way i suppose you have to use Architecture Components like ViewModel + Livedata

Fragment - wait for onCreateView() to complete before running methods

I'm struggling with a puzzling sequence of events relating to a Fragment. I'm trying to add a fragment to an Activity, and then call a method inside the fragment to update some text. However, what I am finding is that the method is being processed in the fragment before onCreateView() finishes, which leaves me with a null View object, and my method fails. Here is the Activity code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log_entry_details);
fragmentManager = getSupportFragmentManager();
titleBarFragment = new TitleBarVerticalFragment();
fragmentTransaction = fragmentManager.beginTransaction ();
fragmentTransaction.add(R.id.log_entry_title_frame, titleBarFragment);
fragmentTransaction.commit();
titleBarFragment.updateTitleBar("Edit Log Entry", 20, false);
}
Seems simple enough. Here is the TitleBarVerticalFragment class:
public class TitleBarVerticalFragment extends TitleBarFragment {
#Inject SharedVisualElements sharedVisualElements;
View view;
TextView titleLabel;
public TitleBarVerticalFragment() {
// add this line for any class that want to use any of the singleton objects
Injector.INSTANCE.getAppComponent().inject(this);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
Log.d(Constants.TAG, "title fragment onCreateView()");
view = inflater.inflate(R.layout.fragment_title_bar_vertical, container, false);
ImageView logoImage = (ImageView) view.findViewById(R.id.logo_vertical);
titleLabel = (TextView) view.findViewById(R.id.verticalTitleLabel);
titleLabel.setTextColor(sharedVisualElements.secondaryFontColor());
titleLabel.setTypeface(sharedVisualElements.font());
titleLabel.setTextSize(20);
logoImage.setImageDrawable(sharedVisualElements.logoImage());
logoImage.setBackgroundColor(Color.TRANSPARENT);
return view;
}
public void updateTitleBar(String text, int textSize, boolean titleLabelIsHidden) {
Log.d(Constants.TAG, "about to update title bar text");
if (view == null) {
Log.d(Constants.TAG, "vertical title fragment is null");
return;
}
if (titleLabel == null)
titleLabel = (TextView) view.findViewById(R.id.verticalTitleLabel);
if (titleLabel == null) {
Log.d(Constants.TAG, "vertical title label is null");
return;
}
Log.d(Constants.TAG, "updating title text: " + text);
titleLabel.setText(text);
titleLabel.setTextSize(textSize);
}
Note the order of this logcat output. Notice how onCreateView() seems to run after the updateTitleBar() method? How can that be?
about to update title bar text vertical title fragment is null
title fragment onCreateView()
How can I ensure that onCreateView() runs before I call any of the fragment's other methods? Thank you.
Try running fragmentManager.executePendingTransactions() after fragmentTransaction.commit(); and before titleBarFragment.updateTitleBar("Edit Log Entry", 20, false);
Just use onStart() on your activity
Define a listener interface and implement it in your Activity.
interface LyfecycleListener {
void onCreatedView();
}
in your Activity:
#Override
protected void onCreate(Bundle savedInstanceState) {
...
this.titleBarFragment = new TitleBarVerticalFragment();
this.titleBarFragment.setListener(this)
...
}
#Override
public void onCreatedView() {
titleBarFragment.updateTitleBar("Edit Log Entry", 20, false);
}
in your Fragment:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
...
this.listener.onCreatedView();
}

Android childfragments from viewpager getActivity returns null

I have an activity and with a button I am switching between the two fragments (MAIN & SETTINGS). In the MAIN fragment I have a ViewPager with 4 child fragments.
At first run everything works fine, but if I rotate the screen, the getActivity() for fragments within the ViewPager is returning null.
ActivityMain:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Add or show the fragments
showHideScreenFragment(FRAGMENT_MAIN);
}
private void showHideScreenFragment(String tag) {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
ft.setCustomAnimations(android.R.anim.fade_in, android.R.anim.fade_out);
// Get the fragment from the backstack if it is existing
BaseFragment oldFragment = getFragmentFromBackstack(tag);
// Get the current fragment from the layout
BaseFragment currentFragment = getCurrentFragment();
if (oldFragment == null) {
if (currentFragment != null) {
ft.hide(currentFragment);
}
ft.add(getMainContainerId(), getFragmentInstance(tag), tag);
}
else {
if (currentFragment != null) {
if (isSameFragment(oldFragment, currentFragment))
return;
ft.hide(currentFragment);
}
if (oldFragment.isHidden())
ft.show(oldFragment);
}
ft.commit();
fm.executePendingTransactions();
}
private BaseFragment getFragmentInstance(String tag) {
if (tag.equals(FRAGMENT_MAIN)) return getFragmentMain();
if (tag.equals(FRAGMENT_SETTINGS)) return getFragmentSettings();
throw new RuntimeException("Fragment not found !");
}
private FragmentMain getFragmentMain() {
return new FragmentMain();
}
private FragmentSettings getFragmentSettings() {
return new FragmentSettings();
}
private BaseFragment getFragmentFromBackstack(String tag) {
if (tag.equals(FRAGMENT_MAIN)) return getFragmentMainFromBackstack();
if (tag.equals(FRAGMENT_SETTINGS)) return getFragmentSettingsFromBackstack();
throw new RuntimeException("Fragment not found !");
}
private FragmentMain getFragmentMainFromBackstack() {
return (FragmentMain) getSupportFragmentManager().findFragmentByTag(FRAGMENT_MAIN);
}
private FragmentSettings getFragmentSettingsFromBackstack() {
return (FragmentSettings) getSupportFragmentManager().findFragmentByTag(FRAGMENT_SETTINGS);
}
private boolean isSameFragment(Fragment f1, Fragment f2) {
return f1.getTag().equals(f2.getTag());
}
FragmentMain:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main, container, false);
viewPager = (ViewPager) view.findViewById(R.id.viewPager);
// Add the 4 child fragments to the viewpager
populateViewPager();
// Debugging
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
_printFragmentStates();
}
}, 2500);
return view;
}
private void populateViewPager() {
ArrayList<BaseMainFragment> fragments = new ArrayList<BaseMainFragment>();
fragments.add(new FragmentSearch());
fragments.add(new FragmentFavorites());
fragments.add(new FragmentHouse());
fragments.add(new FragmentRoom());
adapterMain = new AdapterMain(getChildFragmentManager(), fragments);
viewPager.setOffscreenPageLimit(4);
viewPager.setAdapter(adapterMain);
}
// DEBUGGING
private void _printFragmentStates() {
Activity actSearch = null;
Activity actFav = null;
Activity actHouse = null;
Activity actRoom = null;
actSearch = getFragmentSearch().getActivity();
actFav = getFragmentFavorites().getActivity();
actHouse = getFragmentHouse().getActivity();
actRoom = getFragmentRoom().getActivity();
Functions.logd("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Functions.logd("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Functions.logd("Main fragment act, is null: " + (getActivity() == null));
Functions.logd("Search act, is null: " + (actSearch == null));
Functions.logd("Favorite act, is null: " + (actFav == null));
Functions.logd("House act, is null: " + (actHouse == null));
Functions.logd("Room act, is null: " + (actRoom == null));
Functions.logd("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Functions.logd("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
private FragmentSearch getFragmentSearch() {
return (FragmentSearch) adapterMain.getItem(0);
}
private FragmentFavorite getFragmentFavorite() {
return (FragmentFavorite) adapterMain.getItem(1);
}
private FragmentHouse getFragmentHouse() {
return (FragmentHouse) adapterMain.getItem(2);
}
private FragmentRoom getFragmentHouse() {
return (FragmentRoom) adapterMain.getItem(3);
}
As I said, at first run everything works fine, but after I rotate the screen, I am getting null for getActivity(); in the 4 child fragments: Search, Favorite, House and Room.
Logcat debug
1 run:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main fragment act, is null: false
Search act, is null: false
Favorite act, is null: false
House act, is null: false
Room act, is null: false
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
After screen orientation changed:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main fragment act, is null: false
Search act, is null: true
Favorite act, is null: true
House act, is null: true
Room act, is null: true
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
What am I doing wrong?
After hours of debugging, I figured out that if you're having only 1 fragment (without child or nested fragments) attached to your activity, then you don't need to re-add your fragment.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Add or show the fragments if the savedInstance is null, otherwise let the system reattach your fragment.
if (savedIstance == null)
showHideScreenFragment(FRAGMENT_MAIN);
}
You don't need to reattach the fragment, the android system will do this for you.
And the solution for getting NPE at getActivity(); in child fragments is:
Use FragmentStatePagerAdapter for your ViewPager's adapter.
and override the saved state method:
#Override
public Parcelable saveState() {
return null;
}
I don't know why, but setRetainInstance(false); does not helped me, and I think this will remain a mystery for me.
It's a good practice to follow a pattern like this when working with fragments :
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment, container, false);
}
#Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
view = view.findViewById(R.id.view);
}
#Override
public void onActivityCreated(#Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
// do your thing here
populateViewPager();
}
1) Use OnCreateView to set your fragment's view,
2) OnViewCreated to initialize view and
3) OnActivityCreated to setup things.
Using getActivity() inside OnActivityCreated ensures that getActivity() does not return null. This method gets called only after the activity is fully initialized. OnAttach, OnCreate, OnCreateView may get even before the activity is created.

how to pass string data from activity to fragment?

I want to pass string value from activity to fragment. For that I'm using bundle for transferring string value.
PUT STRING ACTIVITY
Passing string value :-
Bundle bundle = new Bundle();
bundle.putString("Value", resultp.get(CurrentProjectActivity.VALUE));
Log.d(TAG, "Value ::: " + resultp.get(CurrentProjectActivity.VALUE));
// set Fragmentclass Arguments
AmenetiesFragment fragobj = new AmenetiesFragment();
fragobj.setArguments(bundle);
In log I got "Value" value as well.
GET STRING VALUE IN FRAGMENT (IT IS NOT WORKING).
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_listview, container, false);
Bundle bundle = this.getArguments();
Log.d(TAG, "Value's value:) ::: " + bundle);
String strtext = bundle.getString("Value");
return rootView;
}
In log I'm getting NULL value for BUNDLE. Please help me to resolve this Issue. Thanks in advance.
I advice you to follow this link1 and this . You should use interface. Check here
Bundle bundle = new Bundle();
bundle.putString("edttext", "From Activity");
// set Fragmentclass Arguments
Fragmentclass fragobj = new Fragmentclass();
fragobj.setArguments(bundle);
and in the Frament task
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String strtext = getArguments().getString("edttext");
return inflater.inflate(R.layout.fragment, container, false);
}
Suppose you want to send String data from Activity to Fragment
In Fragment.java file add the following code,
public static String name= null;
public void setName(String string){
name = string;
}
In MainActivity.java from which you want to send String add the following code,
String stringYouWantToSend;
Fragment fragment = new Fragment();
fragment.setName(stringYouWantToSend);
The savedInstance variable will be empty the first time you run your app,
it only gets filled when the onSaveInstanceState method is called, this usually happens when you rotate the screen, then savedInstance variable will be populated. Try this :
if(savedInstance != null){
Log.d(TAG, "There's is something");
}else{
Log.d(TAG, "Nothing in there");
}
First time in logcat you will see the first message, try turning your device and the message in the else will show.
As #james said, the recommended way is to use interfaces, or have a field class but this increases coupling and destroys the whole point of fragments.
make public first in activity that object you required in fragment.
then you can use like ((ACtivityName)getActivity()).objectName;
i hope it help.this is not best way to pass data into fragment.
there are some other way also.
create constructor of your fragment class and pass it and save in fragment like:
public MyFragment(String data){
this.data = data;
}
also you can use as bundle #james answer.
EDIT:-
First Way
private class MyFeagment extends Fragment {
private String data;
private Object myObject;
public MyFeagment(String data, Object anyObject) {
this.data = data;
this.myObject = myObject;
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.i("My Fragment", "data :: " + data + " and myObject :"
+ myObject);
return super.onCreateView(inflater, container, savedInstanceState);
}
}
let's say it is your framgnet.
and put this code in your activity
FragmentManager manager = getSupportFragmentManager();
FragmentTransaction transaction = manager.beginTransaction();
transaction.add(R.id.fragment_container, new MyFeagment("My Data",
"data"));
transaction.commit();
Easiest Approach but not Recommended
You can access activity data from fragment:
Activity:
public class MyActivity extends Activity {
private String myString = "hello";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
...
}
public String getMyData() {
return myString;
}
}
Fragment:
public class MyFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
MyActivity activity = (MyActivity) getActivity();
String myDataFromActivity = activity.getMyData();
return view;
}
}

The FragmentPagerAdapter update the pages wrongly?

I am having strange issue in FragmentStatePagerAdapter.when i swipe front ,it works gud,when i swipe back it skip 2 fragments.how to resolve this?
is there any way to get current item no?
NavigationPagerAdapter
public static class NavigationPagerAdapter extends FragmentStatePagerAdapter {
public NavigationPagerAdapter(android.support.v4.app.FragmentManager fm ) {
super(fm);
}
#Override
public Fragment getItem(int i) {
Fragment fragment = new NaviagtionFragment();
Bundle args = new Bundle();
args.putInt("position", i); // Our object is just an integer :-P
fragment.setArguments(args);
return fragment;
}
#Override
public int getCount() {
// For this contrived example, we have a 100-object collection.
return 100;
}
#Override
public CharSequence getPageTitle(int position) {
return "OBJECT " + (position );
}
in fragment
public static class NaviagtionFragment extends Fragment {
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.item_pager, container, false);
Bundle args = getArguments();
int m= args.getInt("position");
Toast.makeText(c, ""+m, Toast.LENGTH_SHORT).show();//here i tracked the position of fragments when i swipe front ,its increasing 1,2,3,4,5,6,7 but when i swipe back it will go directly 7 -5 th position..
}}}
Toast is very slow and it is not good solution when you are swiping views, because it remains on the screen longer and can not reach to show all messages, so its better to check position in LogCat. Try this for items position and see position with Log:
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mNum = getArguments() != null ? getArguments().getInt("position") : 1;
Log.i("tag", "Item clicked: " + mNum);
}

Categories

Resources