2011-06-11 108 views
0
package com.example.android.home; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.*; 
import android.view.*; 
public class HomeActivity extends Activity { 
    /** Called when the activity is first created. */ 
    private EditText input; 
    private EditText result; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     input = (EditText) findById(R.id.input1); 
     result = (EditText) ***findById***(R.id.result); //Error:Undefined for the type HomeActivity 

     input.addKeyListener(new View.OnKeyListener() { Error: Undefined for the type EditText 
      public boolean onKey(View v, int keycode, KeyEvent keyevent) {  
       if (keyevent.getAction() == KeyEvent.ACTION_UP) {    
        doCalculation();  
        }   
       return false;  
       }  
      }); 
      } 
    private void doCalculation() 
    { 
      String strValue = input.getText().toString(); 
      int resultt = Integer.parseInt(strValue) * 2; 
      result.setText("Result: "+ resultt); 

    } 

} 
+2

向我們展示您的main.xml佈局。 – 2011-06-11 11:28:57

+0

你能發佈你的主佈局的xml嗎? – Flo 2011-06-11 11:29:30

+1

它甚至如何編譯。它應該是'findViewById()'而不是'findById()' – Varun 2011-06-11 11:59:37

回答

1

正如@Varun所說的,沒有findById()方法。您可能正在考慮findViewById()

您可以通過檢查任何示例Android活動並查看它如何訪問小部件來發現這一點。 SDK安裝中有許多示例活動,還有在線。