【发布时间】:2016-06-11 23:12:21
【问题描述】:
我的 autocompletexview 与 WebServices 连接。当我的 autocompleteextview 加载数据集时,例如:
巴塞罗那 塞维利亚 加的斯 卡斯特利翁 马德里 卡斯蒂列哈 卡斯蒂利亚
当我写“Ca”时,只有这个选项可用
卡斯特利翁 卡斯蒂列哈 卡斯蒂利亚
这个不显示重音词(加的斯)。
这是我的代码
public class MainActivity extends Activity {
InputStream is=null;
String result=null;
String line=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy= new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://www.aaaaaa.com/aaaaaa.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("Pass 1", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 1", e.toString());
Toast.makeText(getApplicationContext(), "Invalid IP Address",
Toast.LENGTH_LONG).show();
}
try
{
BufferedReader reader = new BufferedReader
(new InputStreamReader(is,"iso-8859-1"),8);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.e("Pass 2", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 2", e.toString());
}
try
{
JSONArray JA=new JSONArray(result);
JSONObject json= null;
final String[] str1 = new String[JA.length()];
for(int i=0;i<JA.length();i++)
{
json=JA.getJSONObject(i);
str1[i]=json.getString("nombre");
}
final AutoCompleteTextView text = (AutoCompleteTextView)
findViewById(R.id.autoCompleteTextView1);
final List<String> list = new ArrayList<String>();
for(int i=0;i<str1.length;i++)
{
list.add(str1[i]);
}
Collections.sort(list);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>
(getApplicationContext(), android.R.layout.simple_spinner_item, list);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
text.setThreshold(1);
text.setAdapter(dataAdapter);
text.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getBaseContext(), list.get(arg2).toString(),
Toast.LENGTH_SHORT).show();
}
});
}
catch(Exception e)
{
Log.e("Fail 3", e.toString());
}
}
我想写字符 "a" 并得到包含字符 "a", "á", "â", ...
谢谢!
【问题讨论】:
-
我认为这个问题出在服务器端而不是应用程序上,不是吗?
-
我认为是特殊字符问题
-
恕我直言 op 应该在 db 中使用规范化的单词创建单独的列。因此搜索将在规范化列上,但结果将来自未规范化。这可以以相反的方式使用。在应用程序中你写“ć”,但在将字符发送到服务器之前你首先标准化为“c”并搜索。
-
@deadfish 该应用程序运行良好,在前面的示例中,如果我键入“Cá”然后显示选项“Cádiz”,问题是键盘应用程序通常不使用重音字符。谢谢
标签: android autocompletetextview