Android 将TextView更改为整数值
该值已从另一个类插入。我希望编辑文本编辑为该值Android 将TextView更改为整数值,android,integer,textview,Android,Integer,Textview,该值已从另一个类插入。我希望编辑文本编辑为该值 public class Second extends Activity { TextView reslt; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState);
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”作为文本视图,“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);
我曾尝试在“publicstaticvoidinsert”下使用“reslt.editText(firstResult);”,但它给了我一个错误,告诉我不能对非静态字段结果进行静态引用
任何帮助都将受到重视。我是个新手。将“静态”视为定义单个全局引用。但是,您可能有多个“第二”类的实例,每个实例都有多个文本视图。因此,编译器无法知道要用文本更新哪个reslt
您可以通过更改
TextView reslt;'行到
静态文本视图reslt;'-但这可能不是你想要的。相反,您可能应该从insert方法中删除static
,并保留对要插入的“第二个”类实例的引用。我没有做后者。第一个建议奏效了。非常感谢你!