我想知道我的代码在 android 2.2 和 3.2 上运行得非常好,但在 android 4.x 上总是崩溃。
android最新版本如何解决?
search_btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
EditText search_text = (EditText) findViewById(R.id.SearchBox);
String search_txt_enter = search_text.getText().toString();
if(search_txt_enter.equals(""))
{
Toast.makeText(getBaseContext(),"All field are required",Toast.LENGTH_SHORT).show();
}
else
{
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mobile.xxxxx.com/search.php");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("search", search_txt_enter.trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
InputStream inputStream = response.getEntity().getContent();
inputStream.close();
}
catch (ClientProtocolException e)
{
// TODO Auto-generated catch block
}
catch (IOException e)
{
// TODO Auto-generated catch block
}
}
}
});