为了账号安全,请及时绑定邮箱和手机立即绑定

如何处理用户的潜在选择

如何处理用户的潜在选择

暮色呼如 2022-08-03 15:48:13
我正在学习android / java,我正在创建一个进行转换的应用程序。我遇到的问题是,由于用户必须选择要转换的单位和要转换为的单位,因此可以进行许多不同的组合。我需要一个可以确定选择了哪个单位的解决方案,以便我可以使用分配给每个单位的值进行计算。下面是代码。提前感谢您的任何回应。多姆。<?xml version="1.0" encoding="utf-8"?><android.widget.RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:app="http://schemas.android.com/apk/res-auto"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context=".MainActivity">    <TextView        android:id="@+id/title"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_centerHorizontal="true"        android:layout_marginTop="15dp"        android:text="Conversions"        android:textSize="20sp" />    <TextView        android:id="@+id/weight"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/title"        android:text="Weight"        android:textSize="20sp"        android:layout_marginLeft="10dp"/>    <Spinner        android:id="@+id/spin1"        android:layout_width="150dp"        android:layout_height="50dp"        android:layout_below="@+id/weight"        >    </Spinner>    <Spinner        android:id="@+id/spin2"        android:layout_width="150dp"        android:layout_height="50dp"        android:layout_below="@+id/weight"        android:layout_toRightOf="@id/to">    </Spinner>    <TextView        android:id="@+id/to"        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_below="@id/weight"        android:layout_marginLeft="10dp"        android:layout_marginRight="10dp"        android:layout_toRightOf="@id/spin1"        android:text="-->"        android:textSize="25sp" />    }}
查看完整描述

1 回答

?
MMTTMM

TA贡献1869条经验 获得超4个赞

我正在设想一个应用程序,它可以在不同的测量单位(英尺,英里,米等)之间转换输入距离。以下是我要做的:

创建两个双精度类型的变量,分别名为 和 。当用户从每个微调器中选择一个选项时,这将设置相应的转换因子值。inputConversionFactoroutputConversionFactor

输入输入距离时,请使用 在内部将此距离转换为米。然后用于从仪表转换为所需的输出单位。inputConversionFactoroutputConversionFactor

通过这种方式,您将问题分解为两个独立的步骤。您不必担心如何在任意两个任意单位之间进行转换,因为您始终将输入转换为米,然后将米转换为输出单位类型。


查看完整回答
反对 回复 2022-08-03
  • 1 回答
  • 0 关注
  • 86 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号