在我的應用程序T有自定義ListView與2個按鈕。現在我想要的是當用戶點擊ListView中的特定按鈕調用異步任務時,將少量參數發送到服務器。參數來自ArrayList.Now我將如何知道從ListView中點擊了哪個按鈕,並且在該特定位置,應該從ArrayList發送相同的數據。找出哪個按鈕被點擊從自定義列表
CustomAdapter.Java
public class SearchJobsCustomList extends BaseAdapter implements View.OnClickListener {
Context c;
ArrayList<HashMap<String, String>> data;
HashMap<String, String> resultp = new HashMap<String, String>();
public SearchJobsCustomList(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(int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = LayoutInflater.from (c).inflate (R.layout.custom_search_jobs_lists, viewGroup, false);
resultp = data.get (i);
view.setTag (resultp);
TextView JobCode = (TextView) view.findViewById (R.id.tv_job_code);
TextView Category = (TextView) view.findViewById (R.id.tv_name);
TextView ExpYrs = (TextView) view.findViewById (R.id.tv_exp_yrs);
TextView ExpMnths = (TextView) view.findViewById (R.id.tv_exp_mnths);
TextView Date = (TextView) view.findViewById (R.id.tv_date);
Button bestCandidate = (Button) view.findViewById (R.id.bt_best_candidates);
Button appliedJobs = (Button) view.findViewById (R.id.bt_applied_jobs);
bestCandidate.setOnClickListener (this);
appliedJobs.setOnClickListener (this);
if (resultp.get ("counts").equals (0)) {
bestCandidate.setFocusable (false);
bestCandidate.setText (0);
} else {
bestCandidate.setText (resultp.get ("counts"));
}
if (resultp.get ("applied").equals (0)) {
appliedJobs.setFocusable (false);
appliedJobs.setText (0);
} else {
appliedJobs.setText (resultp.get ("applied"));
}
JobCode.setText (resultp.get ("code"));
Category.setText (resultp.get ("category"));
ExpYrs.setText (resultp.get ("minExp"));
ExpMnths.setText (resultp.get ("maxExp"));
Date.setText (resultp.get ("postedOn"));
}
return view;
}
@Override
public void onClick(View view) {
switch (view.getId()){
case R.id.bt_best_candidates:
BestCandidateDisplay display=new BestCandidateDisplay();
display.execute();
}
}
public class BestCandidateDisplay extends AsyncTask<String,String,String>{
@Override
protected String doInBackground(String... strings) {
String response= HttpRequest.post ("https://beta135.hamarisuraksha.com/web/WebService/HsJobService.asmx/GetBestCandidates").send ("Vendor_IEntity_Code=" + "&IJob_Req_ID=" + resultp.get ("reqId") + "&IJob_Requestor_ID=" + resultp.get ("iReqId") + "&Mode=" + "TTL").body();
return null;
}
}
}
列表圖像
tysm它工作:) – Anuj
很高興幫助你。 –