Java 无法接受回收器视图上的浮动输入
我正在开发一个审核应用程序,提交审核时,审核人必须包括餐厅的坐标,然后填写地图 但是我正在努力学习如何接受浮点输入,字符串输入工作得很好。我在下面的代码中强调了我遇到困难的地方,我尝试使用“Float.valueOf”,但是这导致了我的应用程序崩溃 谢谢你的帮助Java 无法接受回收器视图上的浮动输入,java,android,android-recyclerview,Java,Android,Android Recyclerview,我正在开发一个审核应用程序,提交审核时,审核人必须包括餐厅的坐标,然后填写地图 但是我正在努力学习如何接受浮点输入,字符串输入工作得很好。我在下面的代码中强调了我遇到困难的地方,我尝试使用“Float.valueOf”,但是这导致了我的应用程序崩溃 谢谢你的帮助 public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { View
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_new_note, container, false);
mAttractionName = view.findViewById(R.id.Submit_attractionName);
mReview = view.findViewById(R.id.Submit_review);
mAttractionAddress =
view.findViewById(R.id.Submit_attraction_Address);
mCuisine = view.findViewById(R.id.Submit_Cuisine);
mLat = view.findViewById(R.id.Submit_latitude);
mLong = view.findViewById(R.id.Submit_longitude);
mCreate = view.findViewById(R.id.create);
mCancel = view.findViewById(R.id.cancel);
mCancel.setOnClickListener(this);
mCreate.setOnClickListener(this);
getDialog().setTitle("New Attraction");
return view;
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.create:{
// insert the new note
String attractionName = mAttractionName.getText().toString();
String review = mReview.getText().toString();
String attractionAddress = enter code
heremAttractionAddress.getText().toString();
String cuisine = mCuisine.getText().toString();
Float latitude = mLat.getText().toString(); (ISSUES HERE)
Float longitude = mLong.getText().toString();
if(!attractionName.equals("")){
mSUBMITACTIVITY.createNewNote(attractionName, re`enter
code here`view, cuisine, attractionAddress, latitude, longitude);
getDialog().dismiss();
}
else{
Toast.makeText(getActivity(), "Enter an Attraction",
Toast.LENGTH_SHORT).show();
}
break;
}
case R.id.cancel:{
getDialog().dismiss();
break;
}
}
}
编辑文本的XML
<android.support.design.widget.TextInputLayout
android:id="@+id/content_wrapper4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<android.support.design.widget.TextInputEditText
android:id="@+id/Submit_latitude"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/note_latitude"
android:imeOptions="actionNext"
android:inputType="numberDecimal|numberSigned" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/content_wrapper5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<android.support.design.widget.TextInputEditText
android:id="@+id/Submit_longitude"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/note_longitude"
android:imeOptions="actionNext"
android:inputType="numberDecimal|numberSigned" />
您必须以字符串形式获取输入,然后将其转换
您必须以字符串形式获取输入,然后将其转换
String latitude = mLat.getText().toString();
float f = Float.parseFloat(latitude);