我无法让 EditText 在我的手表上工作。它适用于 Android Studio 上的模拟器,当我单击 edittext 字段时,会弹出一个单独的屏幕,您可以在其中放置数字。类似于计算器的 UI。当我单击手表上的 EditText 字段时,没有任何反应。我不能放置任何数字,按钮和微调器工作。
该应用程序接受用户的输入,并可以将其转换为其他测量值。
这是 activity_main.xml 文件
<?xml version="1.0" encoding="utf-8"?>
<android.support.wear.widget.BoxInsetLayout
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"
android:background="@color/dark_grey"
android:padding="@dimen/box_inset_layout_padding"
tools:context=".MainActivity"
tools:deviceIds="wear"
>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/blue"
android:padding="@dimen/inner_frame_layout_padding"
app:boxedEdges="">
<EditText
android:id="@+id/numberr"
android:layout_width="67dp"
android:layout_height="wrap_content"
android:layout_marginLeft="19dp"
android:layout_marginTop="100dp"
android:hint="#"
android:focusable="true"
android:focusableInTouchMode="true"
android:inputType="numberDecimal|numberSigned" />
<Spinner
android:id="@+id/spin"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_marginLeft="40dp"
android:entries="@array/choices"></Spinner>
<TextView
android:id="@+id/con"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dp"
android:layout_marginTop="190dp"
android:text="__"></TextView>
<Button
android:id="@+id/button1"
android:layout_width="69dp"
android:layout_height="50dp"
android:layout_marginLeft="120dp"
android:layout_marginTop="100dp"
android:text="Conv" />
</FrameLayout>
这是 MainActivity.java
package com.example.robertomejiajr.watch2;
import android.os.Bundle;
import android.support.wearable.activity.WearableActivity;
import android.text.TextUtils;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
import java.text.DecimalFormat;
import static android.widget.Toast.*;
public class MainActivity extends WearableActivity implements
AdapterView.OnItemSelectedListener {
//these are the options that are available
//Fahrenheit to Celsius
//Celsius to Fahrenheit
//Inch to Centimeter
//Centimeter to Inch
//Feet to Centimeter
//Centimeter to Feet
//Feet to Mile
//Mile to Feet
//Mile to Kilometer
//Kilometer to Mile
//Pound to Gram
//Gram to Pound
//Ounce to Milliliter
//Milliliter to Ounce
// This is value for user input
double n1;
// This is the value for the answer for any of the formulas
double y;
// This will determine what option the user
// chose for the spinner, default is first option
int n = 0;
Spinner spinner;
EditText et1;
Button button;
TextView conn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//this is for spinner
spinner = (Spinner) findViewById(R.id.spin);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.formulas, android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
///////////////// these are linking the EditText, TextView, Button, to
the variables
et1= (EditText)findViewById(R.id.numberr);
conn=(TextView)findViewById(R.id.con);
button =(Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Double num1=Double.parseDouble(et1.getText().toString());
n1 = num1;
conn.setText("" + n1);
DecimalFormat df2 = new DecimalFormat(".##");
DecimalFormat df5 = new DecimalFormat(".#####");
if (n == 0)
{
}
if (n == 1)
{
y = ( (n1 - 32.0) * (5.0/9.0) );
conn.setText(n1 + " °F = " + df2.format(y) + " °C");
}
if (n == 2)
{
y = (n1 * (9.0 / 5)) + 32;
conn.setText(n1 + " °C = " + df2.format(y) + " °F");
}
if (n == 3)
{
y = (n1 * 2.54);
conn.setText(n1 + " in = " + df2.format(y) + " cm");
}
if (n == 4)
{
y = (n1 / 2.54);
conn.setText(n1 + " cm = " + df2.format(y) + " in");
}
if (n == 5)
{
y = (n1 * 30.48 );
conn.setText(n1 + " ft = " + df2.format(y) + " cm");
}
if (n == 6)
{
y = (n1 / 30.48 );
conn.setText(n1 + " cm = " + df5.format(y) + " ft");
}
if (n == 7)
{
y = (n1 / 5280.0);
conn.setText(n1 + " ft = " + df5.format(y) + " M");
}
if (n == 8)
{
y = (n1 * 5280.0);
conn.setText(n1 + " M = " + df2.format(y) + " ft");
}
if (n == 9)
{
y = (n1 * 1.60934);
conn.setText(n1 + "M = " + df2.format(y) + " km");
}
if (n == 10)
{
y = (n1 / 1.60934);
conn.setText(n1 + " km = " + df5.format(y) + " M");
}
if (n == 11)
{
y = (n1 / .00220462262 );
conn.setText(n1 + " lb = " + df2.format(y) + " g");
}
if (n == 12)
{
y = (n1 * .00220462262 );
conn.setText(n1 + " g = " + df5.format(y) + " lb");
}
if (n == 13)
{
y = (n1 / 0.033814);
conn.setText(n1 + "oz = " + df2.format(y) + " ml");
}
if (n == 14)
{
y = (n1 * 0.033814);
conn.setText(n1 + " ml = " + df5.format(y) + " oz");
}
}
});
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int
position, long id) {
String selection = (String) parent.getItemAtPosition(position);
if (!TextUtils.isEmpty(selection)) {
if (selection.equals("Pick One")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 0;
}
if (selection.equals("Fahrenheit to Celsius")) {
Toast.makeText(this,String.valueOf(n1),
LENGTH_SHORT).show();
n = 1;
}
if(selection.equals("Celsius to Fahrenheit")) {
Toast.makeText(parent.getContext(), "hello", LENGTH_SHORT
).show();
n = 2;
}
if(selection.equals("Inch to Centimeter")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 3;
}
if(selection.equals("Centimeter to Inch")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 4;
}
if(selection.equals("Feet to Centimeter")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 5;
}
if(selection.equals("Centimeter to Feet")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 6;
}
if(selection.equals("Feet to Mile")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 7;
}
if(selection.equals("Mile to Feet")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 8;
}
if(selection.equals("Mile to Kilometer")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 9;
}
if(selection.equals("Kilometer to Mile")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 10;
}
if(selection.equals("Pound to Gram")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 11;
}
if(selection.equals("Gram to Pound")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 12;
}
if(selection.equals("Ounce to Milliliter")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 13;
}
if(selection.equals("Milliliter to Ounce")) {
Toast.makeText(this,selection, LENGTH_SHORT).show();
n = 14;
}
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
}