gpt4 book ai didi

java - 无法在回收器 View 上接受 float 输入

转载 作者:行者123 更新时间:2023-12-02 01:32:07 25 4
gpt4 key购买 nike

我正在开发一个评论应用程序,在提交评论时,评论者必须包含餐厅的坐标,然后该坐标将填充 map 。

但是我正在努力解决如何接受浮点输入,字符串输入工作正常。我在下面的代码中突出显示了我遇到困难的地方,我尝试使用“Float.valueOf”,但这导致我的应用程序崩溃。

感谢任何帮助,谢谢。

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;
}
}
}

EditText 的 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);

您必须以字符串形式输入,然后将其转换。

关于java - 无法在回收器 View 上接受 float 输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55879897/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com