简体   繁体   中英

Pass the value from 1st activity to 2nd activity in android

As am getting article title on textview on first activity.how can i pass these textview to next activity...

I have used below code:

    for ( j = 0; j <Appscontent.Sub_arraylisttwo.size(); j++) 
      {
         LinearLayout ly = new LinearLayout(this);
         ly.setOrientation(LinearLayout.VERTICAL);
            ly.setOnClickListener(mArticleClick);
         TextView tv = new TextView(this);
         tv.setText(Appscontent.Sub_arraylisttwo.get(j));   

        ly.addView(tv);
        lLayout.addView(ly);
     }

       int num=Integer.parseInt(number);
       number=String.valueOf(num=num+1);
        System.out.println("the Number Value Is"+number);
          Appscontent.Sub_arraylisttwo.clear();

       hSroll.addView(lLayout);
       viewLayout.addView(headerText);
      viewLayout.addView(hSroll);
       verticalLayout.addView(viewLayout);

      Log.i("12", "" + lLayout.getChildCount());}
         }
      private OnClickListener   mArticleClick   = new OnClickListener() {

                                @Override
                                public void onClick(View v) {

                                Intent in = new Intent(MainActivity.this, SubCate.class);

                               startActivity(in); 

                                }
                            };

Here i have to click one article means that article name only pass to next activity and display that article title.. how can i do ??? please give me solution for these ???

if you want to use intents:

while going to the ListActivity pass data by..

intent.putExtra("Title", yourstring);
intent.putExtra("Content", yourstring);
startActivity(intent);

and to recover it in second activity use:

title= getIntent().getExtras().getString("Title");

...and so on..

//to pass :
 Intent in = new Intent(MainActivity.this, SubCate.class);
in.putExtra("name", "Artical Name");  
 startActivity(in);


// to retrieve object in second Activity
getIntent().getSerializableExtra("name");
 public void onClick(View view)
 {
    public void run()
    {
            Intent i=new Intent(activity1.this,activity2.class);
            i.putExtra("somename", variable1);
            i.putExtra("somename1", variable2);         

    }
 }

In the second activity

     Bundle extras = getIntent().getExtras();
    if (extras != null) {
        one= extras.getDouble("somename");
        two = extras.getDouble("somename2");

    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM