Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在onPost Execute中编码listview ArrayAdapter?_Android_Listview_Dialog_Android Arrayadapter - Fatal编程技术网

Android 如何在onPost Execute中编码listview ArrayAdapter?

Android 如何在onPost Execute中编码listview ArrayAdapter?,android,listview,dialog,android-arrayadapter,Android,Listview,Dialog,Android Arrayadapter,我试图在onPostExecute中显示列表视图,我尝试了不同的方法,但无法显示数据。我没有在logcat中得到任何错误,也没有看到任何forceclose class LoadAlltopics extends AsyncTask<String, String, String> { @Override protected void onPreExecute() { super.onPreExecute();

我试图在
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);
class LoadAlltopics扩展异步任务{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
pDialog=新建进度对话框(Topic.this);
setMessage(“正在加载主题,请稍候…”);
pDialog.setUndeterminate(假);
pDialog.setCancelable(假);
pDialog.show();
}
受保护的字符串doInBackground(字符串…args){
List params=new ArrayList();
JSONObject json=jsonParser.makeHttpRequest(url_get_topicid,“get”,params);
System.out.println(“集团成功1”);
Log.d(“所有组:,json.toString());
System.out.println(“集团成功”);
试一试{
int success=json.getInt(TAG_success);
System.out.println(“集团成功2”);
如果(成功==1){
System.out.println(“集团成功3”);
groups=json.getJSONArray(标记组);
System.out.println(“结果成功+++”+组);
对于(int i=0;ivalue
地图放置(标记主题名称,tname);
//map.put(TAG_LEVELNAME,lname);
//将哈希列表添加到ArrayList
groupList.add(map);
tnamelist.add(tname);
System.out.println(“主题成功”);
}
List newList=newarraylist(newhashset(tnamelist));
对于(int j=0;j请尝试使用以下代码:

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


lv.setadapter(新建ArrayAdapter(主题.this,R.layout.list_行,groupnamelist));

setadapter(新建ArrayAdapter(主题.this,R.layout.list_行,groupnamelist));
应该是
lv.setadapter(主题.this,R.layout.list行,groupnamelist))
也粘贴适配器类。代码可能有很多问题。什么数据类型是
tnamelist
?什么是
setadapter()
?什么是
list\u row.xml
?@ρρK i add lv现在显示错误,我像这样更改了ArrayAdapteradapter=newArrayAdapter(Topic.this,android.R.layout.simple\u list\u item\u 1,groupnamelist);setadapter(adapter);现在我也没有收到任何错误,也没有看到任何错误data@Santhosh很抱歉,我是android新手,我没有编写适配器类。你能帮我编写适配器类吗?你能为此编写代码吗?我试图得到错误E/AndroidRuntime(724):java.lang.IllegalStateException:ArrayAdapter要求资源ID为TextView E/AndroidRuntime(724):位于android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:347)为此,我应该编写任何适配器类,但如果代码在静态值中,我得到了我能看到的值,但在执行后,我写了我看不到的数据使用这个lv.setadapter(新的ArrayAdapter(Topic.this,android.R.layout.simple_list_item_1,groupnamelist));问题在于你的布局xml.你能发布xml和适配器代码吗,或者你能使用android定义的布局4.它的成功非常感谢你兄弟..我得到了数据..但它显示在顶部我想显示在中心你能帮我做点什么吗?我已经做了同样的事情我犯了一个小错误我没有放lv.真的我没有大脑..谢谢