2016-03-07 61 views
0

我是Android開發的新手,目前我面臨着我的項目的問題,我想將我的應用程序連接到本地主機,我已經看到了如何做到這一點,並拿起最簡單的使用JSON,因此我停下來實現我的TextWatcher將其添加到該代碼的方式。剩下的事情,我已經做了,因爲它需要在步驟。如何在我的Json準備好時實現TextWatcher?

請看看我的代碼,告訴我什麼是我的錯誤?

這是我的Java代碼:

public class MyActivity extends Activity implements TextWatcher { 
HttpClient httpClient; 
private HttpPost mhttpPost; 

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


    String[] mobileArray = {"Laptops","IPhone","WindowsMobile","Blackberry","WebOS","Ubuntu","Windows7","Max OS X"}; 
    ArrayAdapter adapter = new ArrayAdapter<String>(this,R.layout.list_item,mobileArray); 
    ListView listView = (ListView) findViewById(R.id.listView); 
    listView.setAdapter(adapter); 

    httpClient = new DefaultHttpClient(); 
    mhttpPost = new HttpPost("http://10.0.2.1/index/get_for_mobile"); 

    try { 
     HttpResponse response = httpClient.execute(mhttpPost); 
     HttpEntity ent = response.getEntity(); 
     String temp = EntityUtils.toString(response.getEntity()); 
    } 
    catch (Exception e){} 

} 
private TextWatcher search = new TextWatcher() { 
    @Override 
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { 

    } 

    @Override 
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) { 

    } 

    @Override 
    public void afterTextChanged(Editable editable) { 

    } 
}; 

}

,這裏是我的XML代碼:

<!-- The primary full-screen view. This can be replaced with whatever view 
    is needed to present your content, e.g. VideoView, SurfaceView, 
    TextureView, etc. --> 

<!-- This FrameLayout insets its children based on system windows using 
    android:fitsSystemWindows. --> 
<SearchView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:id="@+id/searchView" 

     android:layout_marginBottom="48dp" /> 

<ListView 
     android:layout_width="wrap_content" 
     android:layout_height="399dp" 
     android:id="@+id/listView" 
     android:layout_gravity="right|top" 
     android:choiceMode="multipleChoice" android:clickable="true"/> 

+0

編輯的代碼沒有工作:( –

回答

0

您還沒有添加textwatcher到Ë ditText或任何視圖,其中您要處理的文本事件。請參閱http://developer.android.com/reference/android/text/TextWatcher.html 爲什麼您需要實現將json結束到本地主機的textwacther。

+0

我需要添加TextWatcher實現當我輸入我的IP連接到本地主機它不進行進一步 –

+0

嘗試添加完成按鈕yourEditText.setImeOptions(EditorInfo.IME_ACTION_DONE)我搜索查看原因;或android:imeOptions =「actionDone」而不是文本監視器,並在完成單擊按鈕時添加代碼以調用發佈請求 –

相關問題