如何刷新列表在Android中查看?

时间:2013-03-20 12:01:18

标签: android android-listview refresh

我正在使用.net网络服务。我想在ListView中获取列表。现在它向我显示了第一个列表,但是当我尝试使用相同的方法再次获取它时,它在日志中给我一个响应但不在列表中显示。

我在mAdapter.notifyDataSetChanged();中使用了Adapter,但它无效。请帮忙。感谢

我的代码:

Intent mIntent = getIntent();
    mIntent.getStringExtra("folder_name");
    Id = mIntent.getStringExtra("folder_ID");
    mIntent.getStringExtra("item_parent");
    User_ID = mIntent.getStringExtra("User_ID");

    subfolderTreedata();   
}
    public void subfolderTreedata() {
    try {
  --------
  --------
  --------  //some code here...

 SoapObject SubfolderResponse = (SoapObject)envelope.getResponse();

        Log.i("SubFolders", SubfolderResponse.toString());

        String File_Ext=" ";

        subfoldersitem = new String[SubfolderResponse.getPropertyCount()];

        System.out.println(subfoldersitem.length);

        for(int i=0; i < SubfolderResponse.getPropertyCount(); i++) {
            SoapObject SingleSubFolder = (SoapObject)SubfolderResponse.getProperty(i);

            subfoldersitem[0] = SingleSubFolder.getProperty(1).toString();
            subfoldersitem[1] = SingleSubFolder.getProperty(0).toString();
            subfoldersitem[2] = SingleSubFolder.getProperty(3).toString();

            if(KEY_SUBJECTTYPE.equalsIgnoreCase("Folder")) {

            item = new FolderList(Folderimages[0], subfoldersitem[0], subfoldersitem[1], subfoldersitem[2]);
            Subfolderdata.add(item);

            } else{

                StringTokenizer tokens = new StringTokenizer(Name, ".");
                @SuppressWarnings("unused")
                String first_string = tokens.nextToken();
                File_Ext = tokens.nextToken();

                    if(File_Ext.equalsIgnoreCase("TIF")) {
                        item = new FolderList(TIFimages[0], subfoldersitem[0], subfoldersitem[1], subfoldersitem[2]);
                        Subfolderdata.add(item);

                    } else {
                        item = new FolderList(noImage[0], subfoldersitem[0], subfoldersitem[1], subfoldersitem[2]);
                        Subfolderdata.add(item);  }
        }
    }
            subfolderslistview = (ListView)findViewById(R.id.subfolderslistview);

            mAdapter = new LazyAdapter(this, R.layout.jpg_row, Subfolderdata);
            subfolderslistview.setAdapter(mAdapter);
            mAdapter.notifyDataSetChanged();

            subfolderslistview.setOnItemClickListener(new OnItemClickListener() {

                public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                    LazyAdapter ca = (LazyAdapter)parent.getAdapter();
                    FolderList item_name = (FolderList)ca.getItem(position);
                    FolderList DocumentID = (FolderList)ca.getItem(position);
                    FolderList type = (FolderList)ca.getItem(position);

                    Intent mIntent = new Intent();  
                    mIntent.putExtra("item_name", item_name.folder_name);
                    mIntent.putExtra("item_id", DocumentID.ID);
                    mIntent.putExtra("item_type", type.type);

                    mIntent.getStringExtra("item_name");

                    String Type = mIntent.getStringExtra("item_type");

                    Log.i("Type", Type);

                    if(Type.equalsIgnoreCase("Folder")){

                        Id = mIntent.getStringExtra("item_id");
                        mAdapter.notifyDataSetChanged();
                        subfolderTreedata();

                    } else {

                        Intent i = new Intent(getApplicationContext(), Display_image.class);
                        i.putExtra("item_name", item_name.folder_name);
                        i.putExtra("ID", DocumentID.ID);
                        i.putExtra("item_type", type.type);
                        i.putExtra("User_ID",User_ID);

                        i.getStringExtra("item_name");
                        Id = i.getStringExtra("ID");
                        i.getStringExtra("item_type");
                        Log.i("id", Id);
                        startActivity(i);
                        }
                     }
                 });

1 个答案:

答案 0 :(得分:1)

public void list() {
    mAdapter = new LazyAdapter(this, R.layout.jpg_row, Subfolderdata);
    subfolderslistview.setAdapter(mAdapter);
}

像这样使用list();

从你想要的地方调用此方法。