我正在构建一个圆形区域计算器但由于某种原因我无法在TextView
中显示任何文本...我试图通过几种方式解决它但它仍然没有显示答案TextView
...我的最后一次尝试使用了与Google的消息应用培训相似的方式
http://developer.android.com/training/basics/firstapp/starting-activity.html
这是我的第一个Activity
:
public class CircleActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.circle_activity);
}
public void hhh(View view) {
EditText radius = (EditText)findViewById(R.id.radius);
Double radiusdb = Double.valueOf(radius.getText().toString());
Intent myintent = new Intent(CircleActivity.this,CircleResult.class);
myintent.putExtra("I", radiusdb);
startActivity(myintent);
}
}
这是Activity
所在的第二个TextView
:
public class CircleResult extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void meth7(){
Double RESULT = getIntent().getExtras().getDouble("I");
Double x = RESULT + 1;
Double FINAL = x * x * 22/7;
TextView FCR = new TextView(this);//CREATING the textview FinalCircleResult
String h = String.valueOf(FINAL);
setContentView(FCR);
FCR.setTextSize(45);
FCR.setText(h);
}
}
我不知道问题究竟是什么,无论如何,谢谢你的帮助。
这是我的圆形结果活动的xml布局
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/FCR"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="41dp" />
</RelativeLayout>
答案 0 :(得分:2)
问题是你的功能在任何地方都没有被调用,请查看下面的评论!
public class CircleResult extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// function not get called anywhere!!!
meth7();
}
/**
* the code of meth7() is actual dead as is not running, being called,
* anywhere in your activity
*/
public void meth7(){
Double RESULT = getIntent().getExtras().getDouble("I");
Double x = RESULT + 1;
Double FINAL = x * x * 22/7;
TextView FCR = new TextView(this);//CREATING the textview FinalCircleResult
String h = String.valueOf(FINAL);
setContentView(FCR);
FCR.setTextSize(45);
FCR.setText(h);
}
}
答案 1 :(得分:0)
我解决了问题!!!
关于我必须将on intent放在oncreate()方法中...感谢你的帮助(madlymad)