我知道有很多关于android listview多选的教程和解决方案。但是我在为我的实现找到正确的解决方案时遇到了麻烦。 我有来自json对象的listview,如下所示。关于以下实现的多个select的实现,我有一个问题。以下是扩展Asynctask的类。现在我想在其中实现多个选择。要直接多次选择删除多个项目。我怎么能采用我的代码。
我知道有很多实现,但我在项目的最后,我已经实现了所有列表视图,如下所示,现在无法更改所有内容。
提前致谢
@Override
protected JSONObject doInBackground(String... args) {
user = db.getUserDetails();
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.getSiteList(user.get("uid"), user.get("uauth"));
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
try {
if(json.has("error_msg")){
pDialog.dismiss();
String err = json.getString("error_msg");
site_error.setText(err);
site_error.setVisibility(View.VISIBLE);
//Toast.makeText(getApplicationContext(), "Dont have any Location", Toast.LENGTH_LONG).show();
}else{
pDialog.dismiss();
// Now since we dont have any error lets put this in the list view.
site = json.getJSONArray(TAG_SITE);
for(int i = 0; i < site.length(); i++){
JSONObject c = site.getJSONObject(i);
//put json obkject on variable
String id = c.getString(TAG_ID);
String location = c.getString(TAG_LOCATION);
// Adding value HashMap key => value
HashMap<String, String> map = new HashMap<String, String>();
map.put(TAG_ID, id);
map.put(TAG_LOCATION, location);
sitelist.add(map);
// Finding the list view
list=(ListView)findViewById(R.id.sitelist);
// Put data on listview content
ListAdapter adapter = new SimpleAdapter(SitePage.this, sitelist,
R.layout.site_list,
new String[] {TAG_LOCATION,TAG_ID}, new int[] {
R.id.siteLocation});
list.setAdapter(adapter);
// List View click event
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/*Open the new activity for single transaction detail*/
Intent intent = new Intent(SitePage.this, AddNewSite.class);
intent.putExtra("site", sitelist.get(+position).get("site_location"));
intent.putExtra("siteid", sitelist.get(+position).get("site_id"));
startActivity(intent);
//Toast.makeText(SitePage.this, "You Clicked at "+sitelist.get(+position).get("site_id"), Toast.LENGTH_SHORT).show();
}
});
}
}
}catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}