我有一個列表按鈕Apply.When用戶單擊應用按鈕時調用彈出窗口是從哪個用戶輸入一些值並將值發送到Web服務。當我得到成功響應web服務我想刷新我的列表,以便在按鈕上的文字是應用應改爲應用刷新列表點擊按鈕
CustomAdapter
public class BestCandidateCustomList extends BaseAdapter {
Context c;
ArrayList<HashMap<String, String>> data;
private ProgressDialog pDialog;
public String cost, comments;
EditText etCost, etComments;
String success;
public BestCandidateCustomList(Context c, ArrayList<HashMap<String, String>> data) {
super();
this.c = c;
this.data = data;
}
@Override
public int getCount() {
return data.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return 0;
}
@Override
public View getView(final int i, View view, ViewGroup viewGroup) {
final ViewHolder holder;
if (view == null) {
holder = new ViewHolder();
view = LayoutInflater.from (c).inflate (R.layout.best_candidate_custom_list, viewGroup, false);
// view.setTag (resultp);
holder.name = (TextView) view.findViewById (R.id.tv_name);
holder.gender = (TextView) view.findViewById (R.id.tv_gender);
holder.age = (TextView) view.findViewById (R.id.tv_age);
holder.profession = (TextView) view.findViewById (R.id.tv_profession);
holder.mobile = (TextView) view.findViewById (R.id.tv_mobile);
holder.expYrs = (TextView) view.findViewById (R.id.tv_exp_yrs);
holder.mnths = (TextView) view.findViewById (R.id.tv_exp_mnths);
holder.apply = (Button) view.findViewById (R.id.bt_apply);
view.setTag (holder);
} else {
holder = (ViewHolder) view.getTag();
}
if (data.get (i).get ("status").equals ("null")) {
holder.apply.setText ("Apply");
} else {
holder.apply.setText (data.get (i).get ("status"));
if (holder.apply.getText().equals ("Applied")) {
holder.apply.setEnabled (false);
}
}
// if (holder.apply.getText().equals ("Applied")) {
// holder.apply.setFocusable (false);
// holder.apply.setClickable (false);
// holder.apply.setFocusableInTouchMode (false);
// holder.apply.setEnabled (false);
//
//
// }
holder.apply.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View view) {
final Dialog dialog = new Dialog (c);
dialog.setContentView (R.layout.apply_popup);
dialog.setTitle ("Apply");
etCost = (EditText) dialog.findViewById (R.id.et_cost);
etComments = (EditText) dialog.findViewById (R.id.et_comments);
holder.ok = (Button) dialog.findViewById (R.id.bt_ok);
holder.cancel = (Button) dialog.findViewById (R.id.bt_cancel);
holder.ok.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View view) {
String requestId = data.get (i).get ("requestId");
String resourceId = data.get (i).get ("resourceId");
String requestorId = data.get (i).get ("requestorId");
String entityCode = data.get (i).get ("entityCode");
Apply apply = new Apply();
apply.execute (requestId, resourceId, requestorId, entityCode);
dialog.dismiss();
}
});
holder.cancel.setOnClickListener (new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
});
holder.name.setText (data.get (i).get ("name"));
holder.age.setText (data.get (i).get ("age"));
holder.gender.setText (data.get (i).get ("gender"));
holder.profession.setText (data.get (i).get ("profession"));
holder.mobile.setText (data.get (i).get ("mobile"));
holder.expYrs.setText (data.get (i).get ("exp"));
return view;
}
class ViewHolder {
TextView name;
TextView gender;
TextView age;
TextView profession;
TextView mobile;
TextView expYrs;
TextView mnths;
Button apply;
Button ok, cancel;
}
public class Apply extends AsyncTask<String, String, String> {
String vendorId = SettingPreference.getVendorId (c);
String userId = SettingPreference.getUserId (c);
String strCost = etCost.getText().toString();
String strComments = etComments.getText().toString();
@Override
protected String doInBackground(String... strings) {
String response = HttpRequest.post ("https://beta135.hamarisuraksha.com/web/WebService/HsJobService.asmx/AddjobApplications").send ("IJob_Request_ID=" + strings[0] + "&IJob_Resource_ID=" + strings[1] + "&IJob_Requestor_ID=" + strings[2] + "&IEntity_Code=" + strings[3] + "&Vendor_IEntity_Code=" + vendorId + "&Applied_By_Company_IEntity_Code=" + vendorId + "&Create_User_Id=" + userId + "&Estimated_Cost=" + strCost + "&Comments=" + strComments).body();
response = response.replaceAll ("<[^>]*>", "").replaceAll ("\n", "");
Log.e ("best candidates", "" + response);
return response;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog (c);
pDialog.setMessage ("Please wait...");
pDialog.setCancelable (false);
pDialog.show();
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute (s);
try {
JSONObject jsonObject = new JSONObject (s);
success = jsonObject.getString ("success");
if (success.equals ("0")) {
Toast.makeText (c, "Apply sucessful", Toast.LENGTH_LONG).show();
} else {
Toast.makeText (c, "Apply sucessful", Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
if (pDialog.isShowing()) {
pDialog.dismiss();
}
}
}
}
列表類
public class BestCandidate extends Activity {
private ListView lvBestCanditate;
BestCandidateCustomList customList;
Context c = this;
Intent i;
TextView jobCode, category;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate (savedInstanceState);
setContentView (R.layout.best_candidate_list);
initialize();
}
private void initialize() {
i = new Intent();
lvBestCanditate = (ListView) findViewById (R.id.listView);
jobCode = (TextView) findViewById (R.id.tv_job_code);
category = (TextView) findViewById (R.id.tv_category);
customList = new BestCandidateCustomList (c, SearchJobsCustomList.candidateArray);
lvBestCanditate.setAdapter (customList);
lvBestCanditate.invalidateViews();
jobCode.setText (SearchJobsCustomList.jobCode);
category.setText (SearchJobsCustomList.category);
}
}
服務器響應後,修改您的列表數據並通知您的適配器。 –