刷新按钮的点击列表 [英] Refresh list on click of button
问题描述
我有一个按钮,列表Apply.When Apply按钮用户点击一个弹出被称为从用户输入一些值,service.When我得到成功响应我想刷新我的web服务发送的值到网上列表,以便在按钮上的文本是适用应改为应用
CustomAdapter
公共类BestCandidateCustomList延伸BaseAdapter {
上下文℃;
ArrayList的<&HashMap的LT;字符串,字符串>>数据;
私人ProgressDialog pDialog;
公共字符串费用,意见;
的EditText etCost,etComments;
字符串成功;
公共BestCandidateCustomList(上下文C,ArrayList的<&HashMap的LT;字符串,字符串>>数据){
超();
this.c = C;
this.data =数据;
} @覆盖
公众诠释的getCount(){
返回data.size();
} @覆盖
公共对象的getItem(int i)以{
返回null;
} @覆盖
众长getItemId(int i)以{
返回0;
} @覆盖
公共查看getView(最终诠释我,观景,ViewGroup中的ViewGroup){ 最后ViewHolder持有人;
如果(查看== NULL){
持有人=新ViewHolder();
鉴于= 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 =(按钮)view.findViewById(R.id.bt_apply);
view.setTag(保持器);
}其他{ 支架=(ViewHolder)view.getTag();
} 如果(data.get(I)获得(身份)。等于(空)){
holder.apply.setText(应用);
}其他{
holder.apply.setText(data.get(I)获得(身份));
如果(holder.apply.getText().equals(应用)){
holder.apply.setEnabled(假);
}
} //如果(holder.apply.getText().equals(应用)){
// holder.apply.setFocusable(假);
// holder.apply.setClickable(假);
// holder.apply.setFocusableInTouchMode(假);
// holder.apply.setEnabled(假);
//
//
//} holder.apply.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(查看视图){
最后对话的对话=新的对话框(C);
dialog.setContentView(R.layout.apply_popup);
dialog.setTitle(应用);
etCost =(EditText上)dialog.findViewById(R.id.et_cost);
etComments =(EditText上)dialog.findViewById(R.id.et_comments);
holder.ok =(按钮)dialog.findViewById(R.id.bt_ok);
holder.cancel =(按钮)dialog.findViewById(R.id.bt_cancel); holder.ok.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(查看视图){
字符串的requestId = data.get(I)获得(的requestId);
字符串资源ID = data.get(I)获得(RESOURCEID);
字符串requestorId = data.get(I)获得(requestorId);
字符串实体code = data.get(I)获得(实体code); [应用] =新应用();
apply.execute(的requestId,RESOURCEID,requestorId,实体code);
dialog.dismiss();
}
}); holder.cancel.setOnClickListener(新View.OnClickListener(){
@覆盖
公共无效的onClick(查看视图){
dialog.dismiss();
}
});
dialog.show();
}
});
holder.name.setText(data.get(I)获得(名字));
holder.age.setText(data.get(I)获得(时代));
holder.gender.setText(data.get(I)获得(性别));
holder.profession.setText(data.get(I)获得(专业));
holder.mobile.setText(data.get(I)获得(手机));
holder.expYrs.setText(data.get(I)获得(EXP));
返回视图。
} 类ViewHolder {
TextView的名称;
TextView的性别;
TextView的年龄;
TextView的专业;
TextView中移动;
TextView的expYrs;
TextView的mnths;
按钮适用;
OK按钮,取消;
} 公共类应用扩展的AsyncTask<字符串,字符串,字符串> {
字符串VENDORID =设定preference.getVendorId(C);
字符串userid =设置preference.getUserId(C);
串strCost = etCost.getText()的ToString();
串strComments = etComments.getText()的ToString(); @覆盖 保护字符串doInBackground(字符串...字符串){
串响应= Htt的prequest.post(https://beta135.hamarisuraksha.com/web/WebService/HsJobService.asmx/AddjobApplications\").send(IJob_Request_ID =+串[0] +与& IJob_Resource_ID =+串[1] +与& IJob_Requestor_ID =+串[2] +与& IEntity_ code =+串[3] +与& Vendor_IEntity_ code =+ VENDORID + &安培; Applied_By_Company_IEntity_ code =+ VENDORID +&放大器; Create_User_Id =+用户id +&放大器; Estimated_Cost =+ strCost +&安培;评论=+ strComments)。体(); 响应= response.replaceAll(&下; [^]的计算值*>中,).replaceAll(\\ N,);
Log.e(最佳人选,+响应);
返回响应;
} @覆盖
在preExecute保护无效(){
super.on preExecute();
pDialog =新ProgressDialog(C);
pDialog.setMessage(请稍候...);
pDialog.setCancelable(假);
pDialog.show();
}@覆盖
保护无效onPostExecute(String s)将{
super.onPostExecute(多个);
尝试{
的JSONObject的JSONObject =新的JSONObject(S);
成功= jsonObject.getString(成功); 如果(success.equals(0)){
Toast.makeText(C,应用SUCESSFUL,Toast.LENGTH_LONG).show();
}其他{
Toast.makeText(C,应用SUCESSFUL,Toast.LENGTH_LONG).show();
}
}赶上(JSONException E){
e.printStackTrace();
}
如果(pDialog.isShowing()){
pDialog.dismiss();
} }
}
}
表类
公共类BestCandidate延伸活动{
私人的ListView lvBestCanditate;
BestCandidateCustomList customList;
上下文C =这一点;
我的意图;
TextView的工作code,类;
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.best_candidate_list);
初始化();
} 私人无效初始化(){
I =新意图();
lvBestCanditate =(ListView控件)findViewById(R.id.listView);
工作code =(的TextView)findViewById(R.id.tv_job_ code);
类别=(的TextView)findViewById(R.id.tv_category);
customList =新BestCandidateCustomList(C,SearchJobsCustomList.candidateArray);
lvBestCanditate.setAdapter(customList);
lvBestCanditate.invalidateViews(); 工作code.setText(SearchJobsCustomList.job code);
category.setText(SearchJobsCustomList.category);
}
}
创建一个的ArrayList<整数GT;状态
与同尺寸为的ArrayList<&HashMap的LT;字符串,字符串>>数据;
现在,只要你发出请求并获得成功,该位置添加到状态
。然后里面getView()方法:
如果(status.contains(新的整数(位置))){
button.setText(应用);
}
其他{
button.setText(应用);
}
此外,做出 adapter.notifyDataSetChanged()的调用
您已经添加了位置,状态数组列表后。这将确保该列表将被刷新。
I have a list with button Apply.When the user clicks on the apply button an popup is called from which user enters some values and sends the values to the web service.When i get success response the webservice i want to refresh my list so that the text on button that is Apply should be changed to Applied
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 ();
}
}
}
}
List Class
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);
}
}
Create an ArrayList<Integer> status
with the same size as ArrayList<HashMap<String, String>> data;
Now, whenever you make the request and get success, add the position to status
. Then inside getView() method :
if(status.contains(new Integer(position))) {
button.setText("Applied");
}
else {
button.setText("Apply");
}
Also, make a call to adapter.notifyDataSetChanged()
after you've added the position to status arraylist. This'll ensure that the list is refreshed.
这篇关于刷新按钮的点击列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!