Example usage for android.widget SimpleAdapter setDropDownViewResource

List of usage examples for android.widget SimpleAdapter setDropDownViewResource

Introduction

In this page you can find the example usage for android.widget SimpleAdapter setDropDownViewResource.

Prototype

public void setDropDownViewResource(int resource) 

Source Link

Document

Sets the layout resource to create the drop down views.

Usage

From source file:com.pgmacdesign.lacunacompanion.fragments.MailFragment.java

public void refreshMail() {

    JSONObject hashOptions = new JSONObject();
    if (pageNum != 1)
        JsonParser.put(hashOptions, "page_number", pageNum);
    if (filterTag != "")
        JsonParser.put(hashOptions, "tags", filterTag);

    ClientSide.setContext(getActivity());
    JSONObject result = ClientSide.send(new Object[] { hashOptions }, "/inbox", "view_inbox");

    if (result != null) {
        JSONArray messages = JsonParser.getJA(result, "messages");
        List<Map<String, String>> mailList = new ArrayList<Map<String, String>>();
        ArrayList<String> mailIds = new ArrayList<String>(24); // Max numbers on each page is 25.

        boolean hasMail = false; // By default, so that there's no way to screw up.
        if (messages.length() > 0) {
            for (int i = 0; i < messages.length(); i++) {
                JSONObject message = JsonParser.getJO(messages, i);

                Map<String, String> datum = new HashMap<String, String>(2);
                datum.put("from", JsonParser.getS(message, "from"));
                datum.put("subject", JsonParser.getS(message, "subject"));
                mailList.add(datum);//from   w w w  .j  a v a  2  s  .co  m

                mailIds.add(JsonParser.getS(message, "id"));

                hasMail = true;
            }
        } else {
            Map<String, String> datum = new HashMap<String, String>(2);
            datum.put("from", "No new Mail available.");
            datum.put("subject", "Sorry. :(");
            mailList.add(datum);

            hasMail = false;
        }

        // Let the UI refresh when there's no mails.
        ListView mails = (ListView) getActivity().findViewById(R.id.mails);
        SimpleAdapter adapter = new SimpleAdapter(getActivity(), mailList, android.R.layout.simple_list_item_2,
                new String[] { "from", "subject" }, new int[] { android.R.id.text1, android.R.id.text2 });
        mails.setAdapter(adapter);

        if (hasMail == true) {
            final Object[] MAIL_IDS = mailIds.toArray();

            //spinnerReset = System.currentTimeMillis();
            mails.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> a, View v, int pos, long id) {
                    //if (System.currentTimeMillis() - spinnerReset < 1000) {
                    //Nothing!
                    //}
                    //else if (System.currentTimeMillis() - spinnerReset > 1000) {
                    String mailId = MAIL_IDS[pos].toString();

                    Intent intent = new Intent(getActivity(),
                            com.pgmacdesign.lacunacompanion.module.inbox.ViewMail.class);
                    intent.putExtra("mailId", mailId);

                    getActivity().startActivity(intent);
                    //}
                }
            });

            // Populate the pages Spinner.
            ArrayAdapter<String> pagesSpinnerAdapter = new ArrayAdapter<String>(getActivity(),
                    android.R.layout.simple_spinner_item);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            Spinner mailPages = (Spinner) getActivity().findViewById(R.id.mailPage);
            double pages = (double) Math.ceil(JsonParser.getL(result, "message_count") / 25);

            for (int i = 1; i < pages; i++) {
                pagesSpinnerAdapter.add("" + i);
            }

            mailPages.setAdapter(pagesSpinnerAdapter);
            mailPages.recomputeViewAttributes(mailPages);
            mailPages.setSelection(pageNum - 1);
        }
    }
}