Android can';t创建多项选择列表视图

Android can';t创建多项选择列表视图,android,listview,listactivity,Android,Listview,Listactivity,这是我的代码,我无法创建多选模式列表视图。 数据由jason获取并在listview中设置。 我想在列表视图中选择多选模式 public class ExamView extends ListActivity{ private ProgressDialog pDialog; Intent activity; // URL to get contacts JSON // JSON Node names private static final String TAG_USERMST = "pro

这是我的代码,我无法创建多选模式列表视图。 数据由jason获取并在listview中设置。 我想在列表视图中选择多选模式

public class ExamView extends ListActivity{

private ProgressDialog pDialog;
Intent activity;
// URL to get contacts JSON

// JSON Node names
private static final String TAG_USERMST = "products";
private static final String TAG_QID = "que_id";
private static final String TAG_QUE = "question";
private static final String TAG_QANS = "ans";
JSONArray products = null;

// Hashmap for ListView
ArrayList<HashMap<String, String>> contactList;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.user_activity_lv);

contactList = new ArrayList<HashMap<String, String>>();

ListView lv = getListView();
    new GetContacts().execute();
}
private class GetContacts extends AsyncTask<Void, Void, Void> {

@Override
protected void onPreExecute() {
    super.onPreExecute();
    // Showing progress dialog
    pDialog = new ProgressDialog(ExamView.this);
    pDialog.setMessage("Exam Paper is downloading...");
    pDialog.setCancelable(false);
    pDialog.show();

}
@Override
protected Void doInBackground(Void... arg0) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();

// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.GET);

Log.d("Response: ", "> " + jsonStr);

if (jsonStr != null) {

try {
        JSONObject jsonObj = new JSONObject(jsonStr);

        // Getting JSON Array node
        products = jsonObj.getJSONArray(TAG_USERMST);

        // looping through All Contacts
        for (int i = 0; i < products.length(); i++) {
            JSONObject c = products.getJSONObject(i);

            String queid = c.getString(TAG_QID);
            String que = c.getString(TAG_QUE);
            String queans = c.getString(TAG_QANS);

            // tmp hashmap for single contact
            HashMap<String, String> product = new HashMap<String, String>();

            // adding each child node to HashMap key => value
            product.put(TAG_QID,queid);
            product.put(TAG_QUE, que);
            product.put(TAG_QANS, queans);


            // adding contact to contact list
            contactList.add(product);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    } else {
        Log.e("ServiceHandler", "Couldn't get any data from the url");
    }

    return null;
}


@Override
protected void onPostExecute(Void result) {
    super.onPostExecute(result);
    // Dismiss the progress dialog
    if (pDialog.isShowing())
        pDialog.dismiss();
    /**
     * Updating parsed JSON data into ListView
     * */
    ListAdapter adapter = new SimpleAdapter(
            ExamView.this, contactList,
            R.layout.user_list_item_lbl, new String[] { TAG_QID, TAG_QUE,
                    TAG_QANS }, new int[] { R.id.name,
                    R.id.email, R.id.mobile });

    setListAdapter(adapter);
}
}
公共类ExamView扩展了ListActivity{
私人对话;
意图活动;
//获取联系人JSON的URL
//JSON节点名称
私有静态最终字符串标记_USERMST=“products”;
私有静态最终字符串标记_QID=“que_id”;
私有静态最终字符串标记_QUE=“question”;
私有静态最终字符串标记_QANS=“ans”;
JSONArray产品=null;
//ListView的Hashmap
ArrayList联系人列表;
创建时受保护的void(Bundle savedInstanceState){
//TODO自动生成的方法存根
super.onCreate(savedInstanceState);
setContentView(R.layout.user\u activity\u lv);
contactList=新的ArrayList();
ListView lv=getListView();
新建GetContacts().execute();
}
私有类GetContacts扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
//显示进度对话框
pDialog=newprogressdialog(ExamView.this);
setMessage(“试卷正在下载…”);
pDialog.setCancelable(假);
pDialog.show();
}
@凌驾
受保护的Void doInBackground(Void…arg0){
//创建服务处理程序类实例
ServiceHandler sh=新的ServiceHandler();
//向url发出请求并获得响应
字符串jsonStr=sh.makeServiceCall(url,ServiceHandler.GET);
Log.d(“响应:”、“>”+jsonStr);
if(jsonStr!=null){
试一试{
JSONObject jsonObj=新的JSONObject(jsonStr);
//获取JSON数组节点
products=jsonObj.getJSONArray(TAG_USERMST);
//通过所有触点循环
对于(int i=0;ivalue
产品放置(标签、标识);
产品。放置(标记,标记);
产品。put(标签号、QUANS);
//将联系人添加到联系人列表
联系人列表。添加(产品);
}
}捕获(JSONException e){
e、 printStackTrace();
}
}否则{
Log.e(“ServiceHandler”,“无法从url获取任何数据”);
}
返回null;
}
@凌驾
受保护的void onPostExecute(void结果){
super.onPostExecute(结果);
//关闭进度对话框
if(pDialog.isShowing())
pDialog.disclose();
/**
*将解析的JSON数据更新到ListView中
* */
ListAdapter=新的SimpleAdapter(
ExamView.this,contactList,
R.layout.user_list_item_lbl,新字符串[]{TAG_QID,TAG_QUE,
TAG_QANS},新int[]{R.id.name,
R.id.email,R.id.mobile});
setListAdapter(适配器);
}
}
getListView().setChoiceMode(ListView.CHOICE\u MODE\u MULTIPLE);
setListAdapter(新的ArrayAdapter(MainActivity.this,android.R.layout.simple\u list\u item\u multiple\u selection,array\u sort));
使用这个代码对我有用。 这里array_sort是一个arraylist,即要显示的所有项目的列表。
使用此选项可以选择多个项目。

请参阅链接或Thnks以获得快速回复。我已在项目中实现了代码,并生成错误类型missmatch无法将void转换为listview
 getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
 setListAdapter(new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_multiple_choice, array_sort));