将TextView更改为整数值

时间:2012-01-08 18:55:33

标签: android integer textview

该值已从其他类中插入。我想将TextEdit编辑为此值。

public class Second extends Activity {

    TextView reslt;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
        reslt = (TextView) findViewById(R.id.tvResult);

    }

    public static void insert(int firstResult) {
        // TODO Auto-generated method stub

有人帮忙吗?

我正在尝试制作Integer,“firstResult”是TextView,“reslt”。

这是我从中插入整数的地方:

public class DataHelper extends Activity{

    public static void insert(String firstFB, String firstRL) {
        // TODO Auto-generated method stub
        Integer a = new Integer(firstFB).intValue();
        Integer b = new Integer(firstRL).intValue();
        int firstResult = a / b;
        Second.insert(firstResult);

我尝试过使用“reslt.editText(firstResult);”在“public static void insert”下但是它给了我一个错误,说我不能对非静态字段结果进行静态引用。

任何帮助都将受到重视。我是新手。

1 个答案:

答案 0 :(得分:1)

将“静态”视为定义单个全局引用。但是,您可能有多个“Second”类的实例,每个实例都有多个TextView。因此,编译器无法知道要使用文本更新哪个 reslt

您可以通过更改TextView reslt;' line to静态TextView reslt;来编译它。 - 但这可能不是你想要的。相反,您可能应该从insert方法中删除static,并保留对要插入的“Second”类的实例的引用。

相关问题