Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to display swipe image only once in android
    primarykey
    data
    text
    <p>I applied view pager swipe where it switch over to image and after that i kept a button,where it switch over to another activity.When i open next time, it should not show swipe image.It should directly open Activity.How to do this? I used preference but i don't know where to implement.</p> <p>My code are as follows:</p> <p><strong>MainActivity.java</strong></p> <pre><code>public class MainActivity extends FragmentActivity { static final int ITEMS = 2; //here i am displaying two times of ImageFragment MyAdapter mAdapter; ViewPager mPager; String status, city; boolean proceed = true; public static final String City = "city"; public static final String Activity = "activity"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mAdapter = new MyAdapter(getSupportFragmentManager()); mPager = (ViewPager) findViewById(R.id.pager); status = preference.readString(getBaseContext(), preference.LOGGED_IN, ""); city = preference.readString(this, preference.CITY, ""); if (city.equals("") || (city == null)) { proceed = false; } if ((status == "") || (status == null)) { status = "true"; preference.writeString(getBaseContext(), preference.LOGGED_IN, status); } else if ((status.equals("true") &amp;&amp; (proceed))) { Intent i = new Intent(MainActivity.this, MainActivity1.class); i.putExtra("activity", "city"); startActivity(i); finish(); } mPager.setAdapter(mAdapter); Button button = (Button) findViewById(R.id.first); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { mPager.setCurrentItem(0); } }); button = (Button) findViewById(R.id.last); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { mPager.setCurrentItem(ITEMS); } }); } public static class MyAdapter extends FragmentPagerAdapter { public MyAdapter(FragmentManager fragmentManager) { super(fragmentManager); } @Override public int getCount() { return ITEMS; } @Override public Fragment getItem(int position) { switch (position) { case 0: // Fragment # 0 - This will show image return ImageFragment.init(position); case 1: // Fragment # 1 - This will show image return ImageFragment.init(position); default:// Fragment # 2-9 - Will show list return ImageFragment.init(position); } } } </code></pre> <p><strong>ImageFragment.java</strong></p> <pre><code> public class ImageFragment extends Fragment { int fragVal; Button imagev; static ImageFragment init(int val) { ImageFragment truitonFrag = new ImageFragment(); // Supply val input as an argument. Bundle args = new Bundle(); args.putInt("val", val); truitonFrag.setArguments(args); return truitonFrag; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); fragVal = getArguments() != null ? getArguments().getInt("val") : 1; } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View layoutView = inflater.inflate(R.layout.fragment_image, container, false); View tv = layoutView.findViewById(R.id.text); imagev=(Button)layoutView.findViewById(R.id.imageView2); imagev.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // here i am switching to another activity. when i open second time, this // MainActivity1 to get displayed Intent myIntent = new Intent(getActivity(), MainActivity1.class); getActivity().startActivity(myIntent); } }); ((TextView) tv).setText("Truiton Fragment #" + fragVal); return layoutView; } } </code></pre> <p><strong>MainActivity1.java</strong> </p> <pre><code> public class MainActivity1 extends Activity{ public static final String CITY = "city"; public static final String ACTIVITY = "activity"; String city,activity; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main1); city = preference.readString(this, preference.CITY, ""); Intent i = getIntent(); activity = i.getStringExtra(ACTIVITY); } } </code></pre> <p>But if i open second time, it doesn't display MainActivity1.java.Once gain it shows MainActivity.How to solve this? Please help me. And my preference code is here.</p> <p><a href="http://pastie.org/8405754" rel="nofollow">http://pastie.org/8405754</a></p> <p>Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload