English 中文(简体)
如何在两项活动之间进行扼杀
原标题:How to pass string between two activities

I have two activities A and B, and from activity A, I click on a button that opens a dialog box which contains a form consisting of two edit text fields and a button(the button in the dialog box is used to start activity B). So, my question is: how do I pass a string from activity B to activity A, but without closing the dialog box(the string will be used to fill one of the two edit text fields).

最佳回答

你们需要创建一个类别来储存变量。 活动 B的使用确定了变数的价值,制造的舱面储存了该变量,而活动A则获得了变数的价值。

  1. 创立一个班级:GlobalVars.java。 这一类:

    公共部门:全球 B. 扩大适用范围{

    private static String var2;
    
    public static String getVar() {
        return var2;
    iii
    
    public static void setVar(String var) {
    var2 = var;
    iii
    

    iii

活动 B 将这一条放在适当的位置:

String something;
GlobalVars.setVar(something);

活动 适当地点:

String getsomething = GlobalVars.getVar();

而这样说!

问题回答

当活动B的回报产生时,你想要保留方言。 如果是这样的话,你可以打开关于积极结果的方言:

  1. Activity A
  2. Click on button open dialogbox
  3. start Activity B
  4. return result to Activity A
  5. onActivityResult will call
  6. open dialog box again

注:活动A不得是单一Task、单一Instance、单一Top。

也许利用共享优惠!

你可以利用广播系统向另一个活动发送含有数据的内容。

Search google or stackoverflow there are a lot of tutorials and examples of how to achieve this. as i understand you want activity a to get notified and fill a field based on some action in the dialog.

我所建议的是这样做的一种方式。 其他答复也为同一问题提供了不同的解决办法。 你们还可以在建立你的方言时进行一个接口,该方言将从方言中调取,并在第一项活动中有所作为。

我认为,你需要使用静态和静态的全球变量以及主动性Res()。 如果你想把客户与以前的客户接洽到新的客户。 附录 活动

撰写“EditClient”活动

Bundle extras = getIntent().getExtras();
  if (extras != null) 
  {
      String name = extras.getString(ClientList.KEY_Client);//ClientList.KEY_Client is global static variable of "ClientList" Activity.

      if (name != null) 
      {
          nameText.setText(name);//"nameText" is a EditText object represent EditText view
      }

  }




相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签