2014-05-01 123 views
-2

我跑过的另一个问题这样的响应:的EditText场缺少方法

如果你检查的EditText的文档,你会发现一个setText()方法。它需要一个字符串和一个TextView.BufferType。

如果是这样,那么加入一个EditText widgit并指定

final EditText TextAdd=(EditText) findViewById(R.id.editTextAdd); 

当我尝试使用setText()我有TextAdd的唯一选择了。是:

`equals(Object o)` 
`getClose()` 
`hashCode()` 
`notify()` 
`notifyAll()` 
`toString()` 
`wait()` 

我为什么不允许setText()没有任何其他的方法?我在这里错过了什么?

[编辑] 谢谢你,user1199931,我习惯于不允许编辑后的网站。

这是我正在使用的代码。我已经改变了TextAddtxtAnswer ...

package com.example.add; 

import android.os.Bundle; 
import android.app.Activity; 
import android.view.Menu; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 

public class Add<EditText> extends Activity 
{ 
    Button buttonAdd ; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.add); 

     final EditText txtAnswer=(EditText) findViewById(R.id.editTextAnswer); 
     buttonAdd = (Button) findViewById(R.id.buttonAdd); 
     buttonAdd.setOnClickListener(new View.OnClickListener() 
      { 
      @Override 
      public void onClick(View v) 
       { 
        // Error line 
      txtAnswer. // Here I have no option for setText() 
       } 
      } 
     ); 

    } 
} 
+0

我不明白这个问题。 –

+0

发布您正在尝试运行的代码并不起作用。 – nKn

回答

0

你是不是把括号。

((EditText)findViewById(R.id.editTextAdd)).setText();

+0

对不起,给出的错误信息。 “最后”一行是定义TextAdd。后来在程序中我想使用TextAdd.setText(),我没有这个选项。我得到错误“方法setText()未定义类型EditText” – user3594341

+0

这没有多大意义。你在问题中列出的那些方法是Object类的方法。换句话说,它们适用于每个对象。你没有使用类变量并试图访问另一个函数中的TextAdd? – ashishduh

+0

好问题。我将发布.java – user3594341