将非活动类之间的变量传递给android活动类 [英] Pass variable between non-activity class to android activity class

查看:151
本文介绍了将非活动类之间的变量传递给android活动类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一个变量从(非)活动类传递给一个nameget(android activity)类。在文本视图中显示传递的变量值。请通过此示例告诉我需要做什么。如何将其传递给android活动

I need to pass a variable from (around)non-activity class to an nameget(android activity)class . Display the passed variable value in text view.. Please tel me what needs to do from this example. How to pass it to android activity

public class around(non-activity class)
{
    String name = "arjun";
    //how to pass this name value to an below activity
    nameget nam = new nameget();
    String new = nam.get(name);
}

public class nameget extends Activity(android activity class)
{
   public String get(String name)
   {
      String got = name;
      TextView t1 = (TextView)findViewById(R.id.textView1);
      t1.setText(name);
    }
}


推荐答案

尝试这个,在你的活动类中声明你的非活动类。

Try this, declare your non activity class in you activity class.

 public class around(non-activity class)
{
Public static String name;
 name = "arjun";
//how to pass this name string to an below activity
}

 public class nameget extends Activity(android activity class)
  {
  around ar = new around();
  //declare non activity class here

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
TextView t1 = (TextView)findViewById(R.id.textView1);
t1.setText(ar.name);
 }
 }

这篇关于将非活动类之间的变量传递给android活动类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆