将文本发送到文本视图中的新意图

时间:2014-08-30 12:47:15

标签: android eclipse android-intent textview case

代码与此类似:

所以我得到一个按钮,打开一个新的意图,并有一个代码随机选择一个不同的案例。像

情形1:      的System.out.println( “A”);  打破; 案例2:      的System.out.println( “B”);  打破;

因此代码选择了一个,但我的问题是我希望将该文本发送给新意图并作为新意图中的文本,任何想法都不喜欢?

5 个答案:

答案 0 :(得分:0)

您需要在每个案例中创建新意图,并在intent.putExtra()方法

中将文本值作为字符串对象传递
Intent intent = new Intent(context,youractivity.class);  
intent.putExtra("deal", yourstingobject);

答案 1 :(得分:0)

我可以从您的问题中得到的是,您希望将字符串发送到活动并设置 活动中的字符串到textview

        case 1:
               Intent i=new Intent(this,Other.class);
               i.putExtra("key", "Any String");
               startActivity(i);

其他课程

       String value=getIntent().getStringExtra("key");
       now set the string in textview

答案 2 :(得分:0)

在Intent中添加文字。

Intent intent = new Intent(getApplicationContext(),
   MySecondClass.class);

   intent.putExtra("name", name);
   startActivity(intent);

MySecondClass.java

中的意图中获取价值
 Intent intent =  getIntent();

 String name    =  intent.getStringExtra("name");

答案 3 :(得分:0)

这是代码:

Intent intent = new Intent(thisActivity,secondActivity.class);
intent.putExtra("extraText", "number");
startActivity(intent);

并在第二项活动中:

Long number=getIntent().getExtras().getLong("extraText");

答案 4 :(得分:0)

// SenderActivity

Intent intent=new Intent(SenderActivity.this,ReceiverActivity.class);
intent.putExtra("yourKey",anystring);
startActivity(intent);

// ReceiverActivity:

String senderMessage= getIntent().getExtras().getString(("yourKey")).toString();