There is bug which is not yet resolved that is, in the search by customer name option menu when user inputs the data and without closing the keyboard option if user clicks "Submit" button and closes the Keyboard option, in this scenario we are getting the data from the server.
In the other scenario that is if user enters the data in the search field and immediately closes the keyboard option and then clicks the "Submit" button, in this case data is not displayed in the popup box of listview.
public class SearchDetails extends Activity {
ListView lv;
ArrayList<ProjectVO> list;
SearchAdapter dataAdapter;
EditText searchBox,searchBox1 ;
String custSearch,flatSearch;
ArrayList<ProjectVO> searchList;
ArrayList<ProjectVO> searchList1;
ArrayList<ProjectVO> seachLis,seachLis1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_layout);
searchList = new ArrayList<ProjectVO>();
searchList1= new ArrayList<ProjectVO>();
searchBox = (EditText) findViewById(R.id.editText1);
searchBox.requestFocus();
searchBox.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//seachLis.clear();
// TODO Auto-generated method stub
searchList.clear();
searchBox.setText("");
searchBox.setFocusable(true);
dataAdapter.notifyDataSetChanged();
}
});
Button btn=(Button)findViewById(R.id.button1);
Button btn1=(Button)findViewById(R.id.button2);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
custSearch= searchBox.getText().toString();
searchBox.setFocusable(false);
//getCustomerDetails();
String url = "http://198.2.2.2:8080/CRMApps/CRMControllerServlet?action=searchCustomerName";
Log.v("JSON Data Activity", url);
new GrabURL1().execute(url);
}
});
ListView lv = (ListView) findViewById(R.id.listView1);
lv.setFocusable(false);
dataAdapter = new SearchAdapter(this,R.layout.list_of_search, searchList);
//if(dataAdapter)
dataAdapter.notifyDataSetChanged();
lv.setAdapter(dataAdapter);
searchBox.setFocusable(true);
btn1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
searchList.clear();
}
});
}
private void displayData1(String response)
{
JSONObject responseObj = null;
try
{
Gson gson = new Gson();
responseObj = new JSONObject(response);
Log.d("TestTag", "Response from server displaydata:"+response);
JSONArray ListObj = responseObj.getJSONArray("customerSearchList");
//list = new ArrayList<ProjectVO>();
for (int i=0; i<ListObj.length(); i++)
{
String info = ListObj.getJSONObject(i).toString();
ProjectVO list1 = gson.fromJson(info, ProjectVO.class);
searchList.add(list1);
Log.d("TestTag","searchList"+searchList.toString());
}
}
catch (JSONException e) {
e.printStackTrace();
}
}
class GrabURL1 extends AsyncTask<String, Void, String> {
private static final int REGISTRATION_TIMEOUT = 3 * 1000;
private static final int WAIT_TIMEOUT = 30 * 1000;
private final HttpClient httpclient = new DefaultHttpClient();
final HttpParams params = httpclient.getParams();
HttpResponse response;
private String content = null;
private boolean error = false;
private ProgressDialog dialog = new ProgressDialog(SearchDetails.this);
protected void onPreExecute() {
dialog.setMessage("Getting your data... Please wait...");
/*new Handler().postDelayed(new Runnable() {
public void run() {
dialog.dismiss();
}
}, 300);*/
dialog.show();
}
protected String doInBackground(String... urls) {
String URL = null;
try {
URL = urls[0];
HttpConnectionParams.setConnectionTimeout(params, REGISTRATION_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, WAIT_TIMEOUT);
ConnManagerParams.setTimeout(params, WAIT_TIMEOUT);
HttpPost httpPost = new HttpPost(URL);
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("customerName", custSearch.toString()));
Log.d("TestTag","CustomerNmae custSearch"+custSearch);
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(httpPost);
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
content = out.toString();
} else{
//Closes the connection.
Log.w("HTTP1:",statusLine.getReasonPhrase());
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {
Log.w("HTTP2:",e );
Log.d("TestTag","CustomerNmae ClientProtocolException"+e);
content = e.getMessage();
error = true;
cancel(true);
} catch (IOException e) {
Log.w("HTTP3:",e );
content = e.getMessage();
error = true;
cancel(true);
}catch (Exception e) {
Log.w("HTTP4:",e );
content = e.getMessage();
error = true;
cancel(true);
}
return content;
}
protected void onCancelled() {
dialog.dismiss();
Toast toast = Toast.makeText(SearchDetails.this, "Error connecting to Server", Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 25, 400);
toast.show();
}
protected void onPostExecute(String content) {
dialog.dismiss();
Toast toast;
if (error) {
toast = Toast.makeText(SearchDetails.this, content, Toast.LENGTH_LONG);
toast.setGravity(Gravity.TOP, 25, 400);
toast.show();
} else {
JSONObject responseObj = null;
try
{
displayData1(content);
}
}
}
0 comments:
Post a Comment