2015-11-12 159 views
0

我在我的視圖中有一個editText。他們是一個else if語句連接到editText。當你鍵入某個單詞時,一些代碼將會運行。輸入文本字段(Android)

但是,當我在代碼沒有運行關鍵字類型。我認爲問題在於他們是一個輸入密鑰。我只是輸入單詞,如果我之後再輸入,它只是創建一個新行,而不是輸入文本。
這裏是從我的其他的代碼,如果

public void editText (String editText) 
{ 
    final ImageView image = (ImageView) findViewById(R.id.image1); 
    final ImageView image1 = (ImageView) findViewById(R.id.imageView2); 
    if(editText=="closer") 
    { 
     ((ViewGroup.MarginLayoutParams) image.getLayoutParams()).topMargin += 1; 
//    image.setRotation(image.getRotation() + 1); 
     image.requestLayout(); 
     ((ViewGroup.MarginLayoutParams) image1.getLayoutParams()).topMargin -= 1; 
//    image2.setRotation(image2.getRotation() + 1); 
    } 
+2

我們就一定能幫助你,但請告訴我們你做了什麼.. – Lal

+0

請告訴我們你有什麼到目前爲止已經試過或澄清你的問題,所以我們可以理解你的要求。 –

+0

@lal。我只是更新了與其他代碼的問題。 – iIveTh3PaST

回答

0

比較字符串時,你應該使用.equals代替==,所以它應該是

if(editText.equals("closer")) 

而且,我可以在看評論,你只是在你的onCreate上調用方法,所以當它被創建時,它會被調用一次。 如果你希望每個東西在編輯文本輸入的時間來檢查,你應該使用偵聽器這樣的:

yourEditTextName.addTextChangedListener(new TextWatcher() { 

    public void afterTextChanged(Editable s) { 

    // this code will be called everytime the text changes 
    editText(yourEditTextName.getText().toString()); 

    } 

    public void beforeTextChanged(CharSequence s, int start, int count, int after) {} 

    public void onTextChanged(CharSequence s, int start, int before, int count) {} 

});