Friday 15 February 2013

android - Passing data from a view pager to a different activity -


The

I have a swipe at different string of an array of data in a visual pager application is working properly view pager The latter is displayed at a time. I have made a button, clicking on which should receive current content and will pass any other activity my code:

  / * Main activity * / public void Crate (bundled saved instenstate) {super.onCreate (savedInstanceState); Get views from // viewpager_main.xml setContentView (R.layout.activity_main); BTN = (button) VVBIID (R.B. button 1); Item = new string [] ( "Apple", "Movie", "Malone", "Popa", "forest", "Learn ViewPager Condition One"}; // viewpager_main.xml viewPager (= ViewPager) findViewById (R .id.pager); // test results see ViewPagerAdapter class adapter = new ViewPagerAdapter (this item); // does bind the adapter ViewPager viewPager.setAdapter (adapters); btn.setOnClickListener (new View.OnClickListener () {@Override public void onClick (View arg0) {// TODO auto-generated method stub intent i = new intent (getApplicationContext (), ContentActivity.class); i.putExtra ( "CurrentItem", before [0] .toString () ); Initial move Respect (i);}});}   

Below is ViewPagerAdapter class

  public class ViewPagerAdapter extends PagerAdapter {// variables declared REFERENCES: String [ ] before you; Leautinflet Flatr; public ViewPagerAdapter (rEFERENCES, string [] items) {this.context = context; This.quote = item;} @ override public boolean IsViewFromObject (see visual, object object) {return View == (( Relative layout) object); } @ Override Public Object Instant Item (View Group Container, status of int) {TextView Item; Inflater = (Layout Influen) Reference .getSystemService (References LAOUT_INFLATER_SERVICE); See Item View = inflater.inflate (R. LayOut. Activation_view_page_adapter, container, false); Txtitem = (TextView) itemView.findViewById (R.id.quote); Txtitem.setText (quote [status]); (ViewPager) container) .addView (itemView); See Return Items;   

Thanks in advance

It should work fine:

  btn.setOnClickListener (new View.OnClickListener () {@Override public void onClick (View arg0) {int CurrentItem = viewPager.getCurrentItem (); intent i = new intent (getApplicationContext (), ContentActivity. class); i.putExtra ( "CurrentItem", before [CurrentItem] .toString ()); startActivity (i);}});   

Good luck.

No comments:

Post a Comment