我正试图在我的EditText中传递一个onCreate值。(我不认为这是可能的,但我不知道该怎么办!)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_maps);
}
public void userClick(View v) {
EditText mEditText1 = (EditText)findViewById(R.id.number1i);
String val1 = mEditText1.getText().toString();
EditText mEditText2 = (EditText)findViewById(R.id.number2i);
String val2 = mEditText2.getText().toString();
double dVal1 = Double.parseDouble(val1);
double dVal2 = Double.parseDouble(val2);
marker(dVal1,dVal2);
}
marker(double Lat, double Long) {
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(Lat,Long)));
}运行该应用程序时,Google中没有标记(用户通过EditText设置纬度和经度值)。
我无法在EditText中添加onCreate值,因为它们将变为空值。
如何在onCreate方法中传递用户集值,即
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_maps);
googleMap.addMarker(new MarkerOptions()
.position(new LatLng(Lat,Long)));
}这显然给了我一个错误,因为Lat和Long是无法识别的。
我通过onClick从EditText按钮调用下面的方法,然后调用前面的方法,其中我想要放置EditText值
public class UserInput extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.input);
}
public void Input(View v) {
Intent i = new Intent(v.getContext(), UserInput.class);
startActivity(i);
}
}发布于 2013-12-05 14:25:27
如果从另一个活动传递编辑文本数据,则需要获取该活动中的数据,并按如下方式设置有效负载:
String lat = myLatitudeEditText.getText().toString();
String long = myLongitudeEditText.getText().toString();
Intent myIntent = new Intent(getApplicationContext(), secondActivity.class);
myIntent.putExtra("lat",lat);
myIntent.putExtra("long",long);
startActivity(myIntent);现在在第二个活动的onCreate中:
String latitude = getIntent().getExtras().getString("lat");
String longitude = getIntent().getExtras().getString("long");现在你已经收到了你传入的短信。希望这解决了您的查询。
https://stackoverflow.com/questions/20402083
复制相似问题