Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8783071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:44:06+00:00 2026-06-13T20:44:06+00:00

I have arraylist and all data nulldate and date add in one array list.and

  • 0

I have arraylist and all data nulldate and date add in one array list.and i display in listview all data.but my problem is i get nulldate first and avalible date in last i want to null date data before available date. and i want to sorting available date and null date data no sorting and and just list view in add.please help me….!!!!!!!!!!!

public class Approval extends Activity {
    protected static final All_Approval_data_dto All_Approval_data_dto = null;

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        finish();
        list.clear();
    }

    private String assosiatetoken;
    ArrayList<All_Approval_data_dto> list = new ArrayList<All_Approval_data_dto>();
    ArrayList<All_Approval_Key_dto> alist = new ArrayList<All_Approval_Key_dto>();
    ArrayList<String> catState = new ArrayList<String>();
    ArrayList<String> uniCatState = new ArrayList<String>();
    ArrayList<ArrayList<All_Approval_data_dto>> masterState = new ArrayList<ArrayList<All_Approval_data_dto>>();
    private String req_id;
    ListView lv;
    Button back;
    ExpAdapter1 expAdapter;
    private Spinner spndata;
    String[] reqspinner = { "Request Date", "Last Update", "Submitter",
            "Owner", "State" };
    ArrayAdapter<String> adapter;
    private ExpandableListView exlistView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.approval);
        assosiatetoken = MyApplication.getToken();
        alist = DBAdpter.recursUserData(assosiatetoken);
        for (int i = 0; i < alist.size(); i++) {
            req_id = alist.get(i).requestId;
            list = DBAdpter.approvalUserData(assosiatetoken, req_id);

        }

        // setState();
        new doinbackground(this).execute();
        spndata = (Spinner) findViewById(R.id.list_all_quize);

        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_spinner_item, reqspinner);
        spndata.setAdapter(adapter);
        lv = (ListView) findViewById(R.id.listapprovaldata);
        lv.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> a, View v, int position,
                    long id) {
                Intent edit = new Intent(Approval.this, Approval_webview.class);
                // edit.putExtra("Cat_url", url_link);

                startActivity(edit);
            }
        });
        exlistView = (ExpandableListView) findViewById(R.id.ExpList);
        spndata.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int position, long arg3) {

                switch (position) {
                case 0:
                    lv.setVisibility(View.VISIBLE);
                    exlistView.setVisibility(View.GONE);
                    Collections.sort(list, byDate);
                    for (int i = 0; i < list.size(); i++) {
                        Log.v("log_tag", "Data " + list.get(i).lastModifiedDate);
                        if (list.get(i).lastModifiedDate != null) {

                            Log.v("log_tag", "sorting "
                                    + list.get(i).lastModifiedDate);
                            lv.setAdapter(new MyListAdapter(
                                    getApplicationContext(), list));

                        }

                    }

                    break;
                case 1:
                    lv.setVisibility(View.VISIBLE);
                    exlistView.setVisibility(View.GONE);
                    Collections.sort(list, byDate1);
                    for (int i = 0; i < list.size(); i++) {
                        if (list.get(i).state != null) {
                            lv.setAdapter(new MyListAdapter(
                                    getApplicationContext(), list));
                        }
                    }
                    break;
                case 2:

                    break;

                case 3:

                    break;

                default:
                    break;
                }

            }

            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
            }

        });

    }

    static final Comparator<All_Approval_data_dto> byDate = new Comparator<All_Approval_data_dto>() {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");

        @SuppressWarnings("unused")
        public int compare(All_Approval_data_dto ord1,
                All_Approval_data_dto ord2) {
            java.util.Date d1 = null;
            java.util.Date d2 = null;
            try {

                if (d1 == null) {
                    return (d2 == null) ? 0 : -1;
                } else if (d2 == null) {
                    return 1;
                }
                d1 = sdf.parse(ord1.lastModifiedDate);
                d2 = sdf.parse(ord2.lastModifiedDate);
            } catch (java.text.ParseException e) {
                // TODO Auto-generated catch block`
                e.printStackTrace();
            }
            // return (d1.compareTo(d2) > 0 ? 1 : -1);
            return (d1.getTime() > d2.getTime() ? -1 : 1); // descending
        }

    };

    /*
     * static final Comparator<AnalysisDto> byRatio = new
     * Comparator<AnalysisDto>() {
     * 
     * 
     * public int compare(Date date1, Date date2) { return
     * (date1.compareTo(date2)>0 ? 1 : -1); } };
     */
    static final Comparator<All_Approval_data_dto> byDate1 = new Comparator<All_Approval_data_dto>() {
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");

        @SuppressWarnings("unused")
        public int compare(All_Approval_data_dto ord1,
                All_Approval_data_dto ord2) {
            java.util.Date d1 = null;
            java.util.Date d2 = null;
            try {

                if (d1 == null) {
                    return (d2 == null) ? 0 : -1;
                } else if (d2 == null) {
                    return 1;
                }
                d1 = sdf.parse(ord1.submitDate);
                d2 = sdf.parse(ord2.submitDate);

            } catch (java.text.ParseException e) {
                // TODO Auto-generated catch block`
                e.printStackTrace();
            }
            // return (d1.compareTo(d2) > 0 ? 1 : -1);
            return (d1.getTime() > d2.getTime() ? -1 : 1); // descending
            // return (d1.getTime() > d2.getTime() ? 1 : -1); //ascending
        }
    };

    class doinbackground extends AsyncTask<Void, Void, Void> {
        ProgressDialog pd;
        private Context ctx;

        public doinbackground(Context c) {
            ctx = c;
        }

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pd = new ProgressDialog(ctx);
            pd.setMessage("Loading...");
            pd.show();

        }

        @Override
        protected Void doInBackground(Void... params) {
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);
            pd.cancel();

        }

    }

    public class MyListAdapter extends BaseAdapter {
        private ArrayList<All_Approval_data_dto> list;

        public MyListAdapter(Context mContext,
                ArrayList<All_Approval_data_dto> list) {
            this.list = list;
        }

        public int getCount() {
            return list.size();
        }

        public All_Approval_data_dto getItem(int position) {
            return list.get(position);
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View convertView, ViewGroup parent) {

            LayoutInflater inflator = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            convertView = inflator.inflate(R.layout.custom_approval_data, null);
            TextView req_id = (TextView) convertView.findViewById(R.id.req_txt);
            TextView date = (TextView) convertView.findViewById(R.id.date_txt);
            TextView owner = (TextView) convertView
                    .findViewById(R.id.owner_txt);
            TextView state = (TextView) convertView
                    .findViewById(R.id.state_txt);
            req_id.setText(list.get(position).requestId + " - "
                    + list.get(position).title);
            date.setText(list.get(position).lastModifiedDate + " - "
                    + list.get(position).submitDate);
            owner.setText(list.get(position).submitter);
            state.setText(list.get(position).state);
            return convertView;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:44:07+00:00Added an answer on June 13, 2026 at 8:44 pm

    replace your try/catch block with this

     try {
    
                if (ord1 == null) {
                    return (ord2 == null) ? 0 : 1;
                } else if (ord2 == null) {
                    return -1;
                }
                d1 = sdf.parse(ord1.lastModifiedDate);
                d2 = sdf.parse(ord2.lastModifiedDate);
            } catch (java.text.ParseException e) {
                // TODO Auto-generated catch block`
                e.printStackTrace();
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a listview that's populated by rows that get their data from a
I have a little problem with getting all data from SQLite database and showing
I have developed an app in which I display data in Gridview . All
I have an arraylist called fetchContactName() which returns all names (31) in my contact
I have ArrayList>. In another activity I want to access all values stored in
I have arraylist myorderdata . I want to retrieve this arraylist to one String
I have a Arraylist List<?> myList=new ArrayList(); myList = fetchQuery(); //fetches the list of
I have defined an ArrayList in my main class where I am loading data
I have a database where I store two different kinds of data. One table
I have this error on one of my sites. Searched thought all project found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.