开发者

How to unsort the sorted list when i click on Android listview header?

I've a list view and i created header (By using addHeader(layout)) to it, and my header having textviews and i created click event for one of the textviews in header and writen sorted code in the event.

package com.sample;



import java.util.Arrays;
import java.util.Collections;
import java.util.List;


import android.R.array;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;

public class SampleActivity extends Activity {
    /** Called when the activity is first created. */
       List<String> ls;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ListView lst=(ListView)findViewById(R.id.bookListView);
       View v = getLayoutInflater().inflate(
                R.layout.header, null);
        lst.addHeaderView(v);

              lst.setAdapter(new ArrayAdapter<String>
                   (this, android.R.layout.simple_list_item_1, COUNTRIES));
               ls=Arrays.asList(COUNTRIES);
              // Collections.sort(ls);
              TextView bt=(TextView)v.findViewById(R.id.item2);
              bt.setOnClickListener(new View.OnClickListener() {

                           @Override
                           public void onClick(View v) {
                  开发者_Python百科                // TODO Auto-generated method stub

                                   Arrays.sort(COUNTRIES);
                                   lst.invalidateViews();

         }});

          static final String[] COUNTRIES = new String[] {
          "Afghanistan", "japan", "China",  "Barma",

       };

}

And its working fine but i want to back unsort list from sorted list when i click again on the header so how can i do this one plz help me.

Thanks, @nag.


change the data(set unsorted data) which you set in the adapter while inititalizing it and use adapter.notifyDataSetChanged() to get the effect.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜