0

我收到以下来源的 3 个错误 - 谁能解释我做错了什么?

错误 -

minEdit 无法解析或不是字段 TimePicker 的 setText(String) 方法未定义 TimePicker 的 setText(String) 方法未定义

附言

后两个发生在以下行:

         timeEt.setText(extras.getString("time"));
         minEt.setText(extras.getString("min"));




    <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="fill_parent" 
   android:layout_height="wrap_content" android:layout_weight="1">

   <LinearLayout android:id="@+id/linearLayout"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical" 
      android:padding="5dp">

      <EditText android:id="@+id/nameEdit"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content" 
         android:imeOptions="actionNext" 
         android:hint="@string/name_hint"
         android:inputType="textPersonName|textCapWords"/>

      <EditText android:id="@+id/capEdit"
         android:layout_width="fill_parent" 
         android:layout_height="wrap_content" 
         android:imeOptions="actionNext" 
         android:hint="@string/cap_hint"
         android:inputType="textPersonName|textCapWords"/>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Data Limit"
        android:textColor="#ffffff"
        android:textAppearance="?android:textAppearanceMedium" />

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:gravity="left"
            android:textColor="#ffffff"
            android:text="10MB" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:gravity="right"
            android:textColor="#ffffff"
            android:text="Unlimited Data" />
    </LinearLayout>

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Bandwidth Limit"
        android:textColor="#ffffff"
        android:textAppearance="?android:textAppearanceMedium" />

    <SeekBar
        android:id="@+id/seekBar1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:gravity="left"
            android:textColor="#ffffff"
            android:text="10kbs" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1.0"
            android:textColor="#ffffff"
            android:gravity="right"
            android:text="Unlimited Bandwidth" />
    </LinearLayout>

    <TextView
        android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:textAppearanceSmall" />

    <TextView
        android:id="@+id/TextView02"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="WiFi Time Limit"
        android:textColor="#ffffff"
        android:textAppearance="?android:textAppearanceMedium" />

    <TimePicker
        android:id="@+id/timeEdit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:layout_weight="1.0" />



    <EditText
        android:id="@+id/codeEdit"
        android:inputType="textUri"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:ems="10"
        android:lines="1"
        android:hint="@string/code_hint"
        android:imeOptions="actionNext" />




      <Button android:id="@+id/saveBtn" 
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginTop="15dp"
         android:layout_gravity="center_horizontal"
         android:text="@string/save_btn"/>
   </LinearLayout>
</ScrollView>

爪哇:

import android.app.Activity;
import android.app.AlertDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.ViewGroup;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.TimePicker;

public class AddEditCountry extends Activity {

     private long rowID; 
     private EditText nameEt;
     private EditText capEt;
     private EditText codeEt;
     private TimePicker timeEt;
     private TimePicker minEt;

       @Override
       public void onCreate(Bundle savedInstanceState) 
       {
          super.onCreate(savedInstanceState); 
          setContentView(R.layout.add_country);

          nameEt = (EditText) findViewById(R.id.nameEdit);
          capEt = (EditText) findViewById(R.id.capEdit);
          codeEt = (EditText) findViewById(R.id.codeEdit);
          timeEt = (TimePicker) findViewById(R.id.timeEdit);
          minEt = (TimePicker) findViewById(R.id.minEdit);


          Bundle extras = getIntent().getExtras(); 

          if (extras != null)
          {
             rowID = extras.getLong("row_id");
             nameEt.setText(extras.getString("name"));  
             capEt.setText(extras.getString("cap"));  
             codeEt.setText(extras.getString("code"));
             timeEt.setText(extras.getString("time"));
             minEt.setText(extras.getString("min"));
          }

          Button saveButton =(Button) findViewById(R.id.saveBtn);
          saveButton.setOnClickListener(new OnClickListener() {

              public void onClick(View v) 
              {
                 if (nameEt.getText().length() != 0)
                 {
                    AsyncTask<Object, Object, Object> saveContactTask = 
                       new AsyncTask<Object, Object, Object>() 
                       {
                          @Override
                          protected Object doInBackground(Object... params) 
                          {
                             saveContact();
                             return null;
                          }

                          @Override
                          protected void onPostExecute(Object result) 
                          {
                             finish();
                          }
                       }; 

                    saveContactTask.execute((Object[]) null); 
                 }

                 else
                 {
                    AlertDialog.Builder alert = new AlertDialog.Builder(AddEditCountry.this);
                    alert.setTitle(R.string.errorTitle); 
                    alert.setMessage(R.string.errorMessage);
                    alert.setPositiveButton(R.string.errorButton, null); 
                    alert.show();
                 }
              } 
         });
       }


           private void saveContact() 
           {
              DatabaseConnector dbConnector = new DatabaseConnector(this);

              if (getIntent().getExtras() == null)
              {
                  dbConnector.insertContact(nameEt.getText().toString(),
                          capEt.getText().toString(),
                          timeEt.getCurrentHour().toString(),
                          minEt.getCurrentMinute().toString(),
                          codeEt.getText().toString());
              }
              else
              {
                 dbConnector.updateContact(rowID,
                    nameEt.getText().toString(),
                    capEt.getText().toString(),
                    timeEt.getCurrentHour().toString(),
                    minEt.getCurrentMinute().toString(),/* Storing as String*/
                    codeEt.getText().toString());
              }
           }
}
4

1 回答 1

2

未为 TimePicker 定义方法 setText(String)

TimePicker没有 setText() 方法,您必须使用setCurrentHour(Integer)setCurrentMinute(Integer)更改值。

minEdit 无法解析或不是字段

意味着您尝试访问的是具有名称的变量,minEdit但您尚未在任何地方声明它。可能你在声明它的地方打错了。我实际上在您的代码中找不到任何 minEdit 字段,所以我无法猜测错误的真正来源。

于 2013-03-23T21:55:30.797 回答