0

我正在尝试在中显示列表视图onPostExecute,我尝试以不同的方式进行操作,但无法显示数据。我在 logcat 中没有收到任何错误,也没有看到任何 forceclose。

 class LoadAlltopics extends AsyncTask<String, String, String> {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(Topic.this);
            pDialog.setMessage("Loading Topics. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }
        protected String doInBackground(String... args) {
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            JSONObject json = jsonParser.makeHttpRequest(url_get_topicid, "GET", params);
            System.out.println("Group Sucess1");

            Log.d("All Groups: ", json.toString());
            System.out.println("Group Success");
            try {
                int success = json.getInt(TAG_SUCCESS);
                System.out.println("Group Success2");
                if (success == 1) {
                    System.out.println("Group Success3");
                    groups = json.getJSONArray(TAG_GROUP);
                    System.out.println("Result Success+++"+groups);
                    for (int i = 0; i < groups.length();i++) {
                        JSONObject c = groups.getJSONObject(i);

                        String tname = c.getString(TAG_TOPICNAME);
                        System.out.println("Checking ::"+tname);
                        //String lname = c.getString(TAG_LEVELNAME);
                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();
                        // adding each child node to HashMap key => value
                        map.put(TAG_TOPICNAME, tname);
                        //map.put(TAG_LEVELNAME,lname);
                        // adding HashList to ArrayList
                        groupList.add(map);
                        tnamelist.add(tname);
                        System.out.println("Topic Sucess");
                    }
                    List<String> newList = new ArrayList<String>(new HashSet<String>(tnamelist));
                    for(int j=0;j<newList.size();j++){
                        List<String> temp=new ArrayList<String>();
                        System.out.println("TopicList Success"+tnamelist);
                        //for(int k=0;k<groupList.size();k++){
                            JSONObject c = groups.getJSONObject(j);
                            String tname = c.getString(TAG_TOPICNAME);
                            //String lname = c.getString(TAG_LEVELNAME);
                            //if(tname.equalsIgnoreCase(newList.get(j).toString())){
                            //      temp.add(lname);
                            System.out.println("Success Success Success :"+tname);
                            }
                        //lnamelist.add(temp);

                }else {             
                    showAlert();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }
        private void showAlert() {
            // TODO Auto-generated method stub

        }


        protected void onPostExecute(String file_url) {
            super.onPostExecute(toString());
            pDialog.dismiss();
            groupnamelist=new ArrayList<String>(new HashSet<String>(tnamelist));
            System.out.println("List Success :"+tnamelist);
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                viewList = Topic.this.getLayoutInflater().inflate(R.layout.topic_row, null);
                dialogMarketList = new Dialog(Topic.this);
                dialogMarketList.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialogMarketList.setContentView(viewList);      
                dialogMarketList.show();
            lvForDialog = (ListView) viewList.findViewById(R.id.ListView);
            ArrayAdapter<String> adapter =(new ArrayAdapter<String>(Topic.this,R.layout.list_row, groupnamelist));
            lvForDialog.setAdapter(adapter);
            //lv = (ListView) findViewById(R.id.ListView);
            //ArrayAdapter<String>adapter=new ArrayAdapter<String>(Topic.this,android.R.layout.simple_list_item_1,groupnamelist);
            //lv.setAdapter(adapter);
4

1 回答 1

1

试试这个代码:

lv = (ListView) findViewById(R.id.ListView);

lv.setadapter(new ArrayAdapter(Topic.this,R.layout.list_row,groupnamelist));

于 2013-01-11T07:13:50.260 回答