两个AutoCompleteTextView中只有一个显示建议

时间:2013-03-07 14:03:15

标签: autocompletetextview

我在同一页面上有两个AutoCompleteTextView控件:ACTV1和ACTV2,只有一个(ACTV1)显示来自我的数据库的建议。对于每个数据绑定操作,我已经制作了一个java类:ACTV1.java和ACTV2.java。   但是如果我在我的清单文件中为ACTV2.java类添加一个intent过滤器(MAIN,LAUNCHER)并在运行配置ACTV2.java中设置为Launch Action,那么我将不再获得有关ACTV1控制的建议,但这次我会获得ACTV2控制的建议。 这两个java类只是区别于某些常量/控件名称的名称。

      package com.fishing2;


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONObject;
import android.app.Activity;

import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;


public class CompleteBalti extends Activity {

    //private CustomAutoCompleteView CompleteBalti;
    private ArrayAdapter<String> adaperbalti; 
    @Override  
      public void onCreate(Bundle savedInstanceState) {  
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_partida);



    }

    final TextWatcher textChecker = new TextWatcher() {  
        public void afterTextChanged(Editable s) {}  

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

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

              adaperbalti.clear();
              callPHP1();  

        }       
    };  

    private void callPHP1(){  
    String result = "";       
    InputStream is=null; 
    AutoCompleteTextView CompleteBalti = (AutoCompleteTextView) findViewById(R.id.nume_localitate);
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();  
    nameValuePairs.add(new BasicNameValuePair("st",CompleteBalti.getText().toString()));

    {   

        try{ 
                HttpClient httpclient = new DefaultHttpClient();  
                HttpPost httppost = new HttpPost("http://192.168.3.159/wtf/balti.php");  
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs,"utf-8"));  
                HttpResponse response = httpclient.execute(httppost);  
                HttpEntity entity = response.getEntity();  
                is = entity.getContent();  
             BufferedReader reader = new BufferedReader(new InputStreamReader(is,"utf-8"),8);  
                StringBuilder sb = new StringBuilder();  
                String line = null;  
                while ((line = reader.readLine()) != null) {                                      
                        sb.append(line + "\n");  
                }  
                is.close();  

                result=sb.toString(); 
                result = result.substring(1);
        }catch(Exception e){  
                Log.e("log_tag", "Error in http connection "+e.toString());  
        }  



         try{
             JSONArray jArray = new JSONArray(result);
             JSONObject json_data = null;

             for (int i=0;i<jArray.length(); i++)
             {   
                  json_data = jArray.getJSONObject(i);
                 adaperbalti.add(json_data.getString("nume_balta"));
             }

            } catch(Exception e1){  
                Log.e("log_tag", "Error converting result "+e1.toString());   

            }     
    }  



                                                      }



                        }

0 个答案:

没有答案