Example usage for android.widget AdapterView getItemAtPosition

List of usage examples for android.widget AdapterView getItemAtPosition

Introduction

In this page you can find the example usage for android.widget AdapterView getItemAtPosition.

Prototype

public Object getItemAtPosition(int position) 

Source Link

Document

Gets the data associated with the specified position in the list.

Usage

From source file:com.armtimes.dialogs.DialogSettings.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    View settingsView = getActivity().getLayoutInflater().inflate(R.layout.dialog_settings, null);

    // Initialize and set Storage Spinner adapter.
    Spinner storageSpinner = (Spinner) settingsView.findViewById(R.id.spinnerImageStorage);
    ArrayAdapter storageAdapter = ArrayAdapter.createFromResource(getActivity(), R.array.image_storage_array,
            android.R.layout.simple_spinner_item);
    storageAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    storageSpinner.setAdapter(storageAdapter);

    storageSpinner.setSelection(getImageStorage(getActivity()));

    storageSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override/*from   ww w.j a  v a2  s.  com*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            setImageStorage(position);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    // Initialize and set Saved news number Spinner Adapter
    Spinner savedNewsSpinner = (Spinner) settingsView.findViewById(R.id.spinnerStoredArticlesCount);
    ArrayAdapter savedNewsAdapter = ArrayAdapter.createFromResource(getActivity(),
            R.array.saved_articles_number_array, android.R.layout.simple_spinner_item);
    savedNewsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    savedNewsSpinner.setAdapter(savedNewsAdapter);

    int pos = savedNewsAdapter.getPosition(Integer.toString(getAllowedNewsCount(getActivity())));
    savedNewsSpinner.setSelection(pos);

    savedNewsSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            final String value = (String) parent.getItemAtPosition(position);
            setSavedNewsCount(value);
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    initImageQualityControllers(settingsView);
    initFontSizeStuff(settingsView);

    // Creates About Us Alert dialog which extends from DialogFragment.
    return new AlertDialog.Builder(getActivity()).setTitle(R.string.settings)
            .setNeutralButton(R.string.about_us_close, null).setView(settingsView).create();
}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleTimetableFragment.java

private void setupScheduleEntrySpinners(final View entryView, ScheduleItem scheduleItem,
        String[] routineNames) {//from   w  w w. j  a  v  a 2 s .co  m

    final Spinner routineSpinner = (Spinner) entryView.findViewById(R.id.entry_routine_spinner);
    final TextView doseTv = (TextView) entryView.findViewById(R.id.entry_dose_textview);
    //        final Spinner doseSpinner = (Spinner) entryView.findViewById(R.id.entry_dose_spinner);

    doseTv.setTag(scheduleItem);
    routineSpinner.setTag(scheduleItem);

    // set up the routine selection adapter
    updateRoutineSelectionAdapter(entryView, routineSpinner, routineNames);

    if (scheduleItem != null && scheduleItem.routine() != null) {
        String routineName = scheduleItem.routine().name();
        int index = Arrays.asList(routineNames).indexOf(routineName);
        routineSpinner.setSelection(index);
    } else {
        routineSpinner.setSelection(routineNames.length - 1);
    }

    doseTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDosePickerDialog((ScheduleItem) v.getTag(), (TextView) v);
        }
    });

    // set up the dose selection adapter
    //        ArrayAdapter<String> doseAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, doses);
    //        doseAdapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
    //        doseSpinner.setAdapter(doseAdapter);
    // select 1 pill by default
    //        doseSpinner.setSelection((int) scheduleItem.dose() - 1); // dose "1" is located at the index "0", and so on

    doseTv.setText(scheduleItem.displayDose());

    // setup listeners
    routineSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String selected = (String) adapterView.getItemAtPosition(i);
            Routine r = Routine.findByName(selected);
            ScheduleItem item = ((ScheduleItem) routineSpinner.getTag());

            if (r != null) {
                updateEntryTime(r, entryView);
            } else {
                updateEntryTime(null, entryView);
                showAddNewRoutineDialog(entryView);
            }
            Log.d(TAG, "Updated routine to " + (r != null ? r.name() : "NULL") + " on item " + item.getId());
            item.setRoutine(r);

            logScheduleItems();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });

    routineSpinner.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                if (((String) routineSpinner.getSelectedItem())
                        .equalsIgnoreCase(getString(R.string.create_new_routine))) {
                    showAddNewRoutineDialog(entryView);
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:com.saphion.stencilweather.activities.MainActivity.java

private void InitiateSearch() {

    initThreading();//from w w w .  j av  a2s .c o m

    setAdapters();

    toolbar.inflateMenu(R.menu.menu_add);

    toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            int menuItem = item.getItemId();
            switch (menuItem) {
            case R.id.action_search:
                IsAdapterEmpty();
                InitiateSearch.handleToolBar(MainActivity.this, card_search, toolbar, /*view_search,*/ listView,
                        edit_text_search, materialMenu);
                showDark();
                break;
            case R.id.action_more:
                initiateActions(true);
                return true;
            default:
                break;
            }
            return false;
        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            if (!(parent.getItemAtPosition(position).toString().equalsIgnoreCase("Loading...")
                    || parent.getItemAtPosition(position).toString().equalsIgnoreCase("No suggestions")
                    || parent.getItemAtPosition(position).toString().equalsIgnoreCase(
                            "Unable To Connect to Internet, Please Check Your Network Settings."))) {

                new GetLL(getBaseContext(), (WLocation) parent.getItemAtPosition(position)).execute();

                if (card_search.getVisibility() == View.VISIBLE) {
                    InitiateSearch.handleToolBar(MainActivity.this, card_search, toolbar,
                            /*view_search,*/ listView, edit_text_search, materialMenu);
                    hideDark();
                }
                listView.setVisibility(View.GONE);
                edit_text_search.setText("");
                ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                        .hideSoftInputFromWindow(edit_text_search.getWindowToken(), 0);

            }
        }
    });

    edit_text_search.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (edit_text_search.getText().toString().length() == 0) {
                clearSearch.setVisibility(View.GONE);
                suggestionAdapter.clear();
                IsAdapterEmpty();
                listView.setVisibility(View.GONE);
                pb.setVisibility(View.GONE);

                if (suggestionPending != null)
                    suggestionPending.cancel(true);

            } else {
                clearSearch.setImageResource(R.drawable.ic_close);
                IsAdapterEmpty();

                pb.setVisibility(View.VISIBLE);
                clearSearch.setVisibility(View.GONE);
                suggestionAdapter.clear();
                queueUpdate(1000 /* milliseconds */);

            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
    clearSearch.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (edit_text_search.getText().toString().length() > 0) {
                //                    mAsyncTask.cancel(true);
                edit_text_search.setText("");
                listView.setVisibility(View.GONE);
                suggestionAdapter.clear();
                //                    clearItems();
                ((InputMethodManager) MainActivity.this.getSystemService(Context.INPUT_METHOD_SERVICE))
                        .toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
                IsAdapterEmpty();
            }
        }
    });

}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

private void setupScheduleSpinner() {
    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(getActivity(), R.array.schedules_array,
            R.layout.spinner_text_item);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
    // Apply the adapter to the spinner
    scheduleSpinner.setAdapter(adapter);
    scheduleSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override// w ww.  ja v a 2 s.c  o  m
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String selected = (String) adapterView.getItemAtPosition(i);
            onScheduleSelected(selected, i);
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });
}

From source file:com.busticket.amedora.busticketsrl.TicketingHomeActivity.java

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.layout_ticket_home);
    myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
    setSupportActionBar(myToolbar);/*www .  j  a  v  a2s . co  m*/
    //synchTrips();
    assert getSupportActionBar() != null;
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);
    spBoard = (Spinner) findViewById(R.id.spBoard);
    spBuses = (Spinner) findViewById(R.id.spBusNo);
    spTrips = (Spinner) findViewById(R.id.spTripType);
    spHighlight = (Spinner) findViewById(R.id.spHighlight);
    mAccount = CreateSyncAccount(this);
    mQueue = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicket = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicketSynch = Volley.newRequestQueue(getApplicationContext());
    rQSyncBalance = Volley.newRequestQueue(getApplicationContext());
    rqTrip = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicketing = Volley.newRequestQueue(getApplicationContext());
    rQSyncTicketingSynch = Volley.newRequestQueue(getApplicationContext());
    //Key methods needed to be sent to server on activity created
    syncTicketing();
    syncTickets();

    apps = db.getApp(Installation.appId(getApplicationContext()));
    EMAIL = apps.getRoute_name();
    NAME = "CODE: " + apps.getAgent_code().toUpperCase() + " Trip: " + apps.getTripCount();
    // Get the content resolver for your app
    mResolver = getContentResolver();
    /*
     * Turn on periodic syncing
     */

    mTitle = mDrawerTitle = getTitle();
    ContentResolver.addPeriodicSync(CreateSyncAccount(this), AUTHORITY, Bundle.EMPTY, SYNC_INTERVAL);

    String[] tdata = populateTerminals();
    String[] bdata = populateBuses();
    ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spBoard.setAdapter(adapter);/**/

    ArrayAdapter Hadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, tdata);
    Hadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spHighlight.setAdapter(Hadapter);

    ArrayAdapter gadapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, bdata);
    gadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spBuses.setAdapter(gadapter);

    ArrayAdapter<CharSequence> tadapter = ArrayAdapter.createFromResource(this, R.array.tripTypes,
            android.R.layout.simple_spinner_item);
    tadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    /*ArrayAdapter badapter =new ArrayAdapter(this,android.R.layout.simple_spinner_item,bdata);
    badapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);*/
    spTrips.setAdapter(tadapter);

    spBuses.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            bus = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spBoard.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            board = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spHighlight.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            highlight = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    spTrips.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            ((TextView) parent.getChildAt(0)).setTextColor(Color.WHITE);
            //((TextView) parent.getChildAt(0)).setTextSize(25);
            trip = parent.getItemAtPosition(position).toString();

        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    btnGenerate = (Button) findViewById(R.id.btnGenerate);

    btnGenerate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // get a new activity to show invoice preview
            sendData();
        }
    });
    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

    mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size

    mAdapter = new DrawerAdapter(TITLES, ICONS, NAME, EMAIL, PROFILE); // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
    // And passing the titles,icons,header view name, header view email,
    // and header view profile picture

    // Setting the adapter to RecyclerView
    //mRecyclerView.setLayoutManager(mLayoutManager);                 // Setting the layout Manager
    LinearLayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
    mRecyclerView.setLayoutManager(layoutManager);
    mRecyclerView.setAdapter(mAdapter);
    Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);
    // Drawer object Assigned to the view

    mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.openDrawer,
            R.string.closeDrawer) {
        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
            // open I am not going to put anything here)
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            // Code here will execute once drawer is closed
            invalidateOptionsMenu();
        }
    }; // Drawer Toggle Object Made
    Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
    mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State

    final GestureDetector mGestureDetector = new GestureDetector(TicketingHomeActivity.this,
            new GestureDetector.SimpleOnGestureListener() {

                @Override
                public boolean onSingleTapUp(MotionEvent e) {
                    return true;
                }

            });

    mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
            View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY());
            if (child != null && mGestureDetector.onTouchEvent(motionEvent)) {
                Drawer.closeDrawers();
                if (recyclerView.getChildPosition(child) == 1) {

                } else if (recyclerView.getChildPosition(child) == 2) {
                    Intent intent = new Intent(TicketingHomeActivity.this, AccountActivity.class);
                    startActivity(intent);
                } else if (recyclerView.getChildPosition(child) == 3) {
                    Intent intent = new Intent(TicketingHomeActivity.this, TicketListActivity.class);
                    startActivity(intent);
                } else if (recyclerView.getChildPosition(child) == 4) {

                    syncTicketingSynchronize();
                    syncTicketsSynchronize();
                    synchAccount();
                    insertBuses();
                    //insertTerminals();

                    //syncTickets();

                    //dialog = ProgressDialog.show(TicketingHomeActivity.this, "", "Synchronizing App Data. Please wait...", true);
                    /*new Thread(new Runnable() {
                    @Override
                    public void run() {
                            
                        Looper.prepare();
                            
                        final Handler handler = new Handler();
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {*/

                    // insertTerminals();

                    // insertBuses();
                    //getTickets();

                    //Toast.makeText(TicketingHomeActivity.this, "Looper startes ", Toast.LENGTH_SHORT).show();
                    /*handler.removeCallbacks(this);
                            
                    Looper.myLooper().quit();
                    }
                    }, 30000);
                            
                    Looper.loop();
                    }
                    }).start();*/

                } else if (recyclerView.getChildPosition(child) == 5) {
                    if (apps.getLicenceNo() != null) {
                        Intent intent = new Intent(TicketingHomeActivity.this, TripHomeActivity.class);
                        startActivity(intent);

                    } else {
                        //Intent intent = new Intent(TicketingHomeActivity.this,TestPrintActivity.class);
                        //startActivity(intent);
                        Toast.makeText(TicketingHomeActivity.this,
                                "Application is in default mode you cannot use this menu", Toast.LENGTH_SHORT)
                                .show();
                    }

                } else if (recyclerView.getChildPosition(child) == 6) {
                    Intent intent = new Intent(TicketingHomeActivity.this, LogoutActivity.class);
                    startActivity(intent);
                    // Toast.makeText(TicketingHomeActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show();
                }
                return true;
            }
            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

        }
    });
    List<Ticket> issuedTickets = db.getIssuedTickets();
    Log.e("SYNC LOG", issuedTickets.toString());
}

From source file:es.usc.citius.servando.calendula.fragments.ScheduleImportFragment.java

private void setupScheduleEntrySpinners(final View entryView, ScheduleItem scheduleItem,
        String[] routineNames) {// ww  w. java2 s  .  c  o  m

    final Spinner routineSpinner = (Spinner) entryView.findViewById(R.id.entry_routine_spinner);
    final TextView doseTv = (TextView) entryView.findViewById(R.id.entry_dose_textview);
    //        final Spinner doseSpinner = (Spinner) entryView.findViewById(R.id.entry_dose_spinner);

    doseTv.setTag(scheduleItem);
    routineSpinner.setTag(scheduleItem);

    // set up the routine selection adapter
    updateRoutineSelectionAdapter(entryView, routineSpinner, routineNames);

    if (scheduleItem != null && scheduleItem.routine() != null) {
        String routineName = scheduleItem.routine().name();
        int index = Arrays.asList(routineNames).indexOf(routineName);
        routineSpinner.setSelection(index);
    } else {
        routineSpinner.setSelection(routineNames.length - 1);
    }

    doseTv.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDosePickerDialog((ScheduleItem) v.getTag(), (TextView) v);
        }
    });

    doseTv.setText(scheduleItem.displayDose());

    // setup listeners
    routineSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            String selected = (String) adapterView.getItemAtPosition(i);
            Routine r = Routine.findByName(selected);
            ScheduleItem item = ((ScheduleItem) routineSpinner.getTag());

            if (r != null) {
                updateEntryTime(r, entryView);
            } else {
                updateEntryTime(null, entryView);
                showAddNewRoutineDialog(entryView);
            }
            Log.d(TAG, "Updated routine to " + (r != null ? r.name() : "NULL") + " on item " + item.getId());
            item.setRoutine(r);

            logScheduleItems();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });

    routineSpinner.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {

                if (((String) routineSpinner.getSelectedItem())
                        .equalsIgnoreCase(getString(R.string.create_new_routine))) {
                    showAddNewRoutineDialog(entryView);
                    return true;
                }
            }
            return false;
        }
    });
}

From source file:com.procleus.brime.ui.LabelsFragment.java

@Override
public void onResume() {
    super.onResume();
    NotesDbHelperOld tn = new NotesDbHelperOld(getContext());
    labelsRetrieved = tn.retrieveLabel();
    listView = (ListView) getView().findViewById(R.id.listLabel);
    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),
            android.R.layout.simple_list_item_1, labelsRetrieved);
    listView.setAdapter(arrayAdapter);//from ww w. ja  v a2  s  .  c o m

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(final AdapterView<?> parent, View view, final int position, long id) {

            final Dialog dialog = new Dialog(getContext());
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            dialog.setCancelable(false);
            dialog.setContentView(R.layout.dialog_label);
            dialog.show();

            final Button negative = (Button) dialog.findViewById(R.id.btn_no_label);
            final Button positive = (Button) dialog.findViewById(R.id.btn_yes_label);

            /*/This is Database Spinner Retreival*/
            /* Spinner getting Data from dataBase*/

            negative.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    dialog.dismiss();

                }
            });

            positive.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    Log.i("brinjalResume", "Yes");

                    NotesDbHelperOld tn = new NotesDbHelperOld(getActivity());
                    tn.deleteTextNote(String.valueOf(parent.getItemAtPosition(position)));
                    labelsRetrieved = tn.retrieveLabel();
                    final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),
                            android.R.layout.simple_list_item_1, labelsRetrieved);
                    listView.setAdapter(arrayAdapter);
                    dialog.dismiss();
                }

            });

            return true;

        }
    });

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Toast.makeText(getActivity(),
                    "Inside in label" + ":" + String.valueOf(parent.getItemAtPosition(position)),
                    Toast.LENGTH_SHORT).show();
            Intent i = new Intent(getActivity(), LabelOpenActivity.class);
            i.putExtra("label", String.valueOf(parent.getItemAtPosition(position)));
            startActivity(i);

        }
    });

}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.widget.ListWidgetConfig.java

void setupConfig() {

    final WidgetPrefs widgetPrefs = new WidgetPrefs(this, appWidgetId);

    // final String[] sortOrderValues = getResources().getStringArray(
    // R.array.sorting_ordervalues_preference);
    final String[] sortTypeValues = getResources().getStringArray(R.array.sortingvalues_preference);
    final String[] themeValues = getResources().getStringArray(R.array.widget_themevalues_preference);

    if (themeValues == null) {
        Log.d(TAG, "themevalues null");
    } else {//from   www  .j  a  v a 2 s.co  m
        for (String s : themeValues) {
            Log.d(TAG, "themevalue: " + s);
        }
    }

    binding.widgetConfWrapper.sortingSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            widgetPrefs.putString(KEY_SORT_TYPE, sortTypeValues[pos]);
            // Need to recreate loader for this
            reloadTasks();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    binding.widgetConfWrapper.sortingSpinner.setSelection(getArrayPositionOf(sortTypeValues,
            widgetPrefs.getString(KEY_SORT_TYPE, getString(R.string.default_sorttype))));

    binding.widgetConfWrapper.themeSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            final String theme = parent.getItemAtPosition(pos).toString();
            final int mTheme;
            final int primaryTextColor;
            final int secondaryTextColor;
            if (theme.equals(getString(R.string.settings_summary_theme_light))) {
                mTheme = THEME_LIGHT;
                primaryTextColor = getResources().getColor(android.R.color.primary_text_light);
                secondaryTextColor = getResources().getColor(android.R.color.secondary_text_light);
            } else {
                mTheme = THEME_DARK;
                primaryTextColor = getResources().getColor(android.R.color.primary_text_dark);
                secondaryTextColor = getResources().getColor(android.R.color.secondary_text_dark);
            }
            widgetPrefs.putInt(KEY_THEME, mTheme);
            widgetPrefs.putInt(KEY_TEXTPRIMARY, primaryTextColor);
            widgetPrefs.putInt(KEY_TEXTSECONDARY, secondaryTextColor);
            updateTheme(mTheme, widgetPrefs);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    final String currentThemeString;
    if (widgetPrefs.getInt(KEY_THEME, DEFAULT_THEME) == THEME_LIGHT) {
        currentThemeString = getString(R.string.settings_summary_theme_light);
    } else {
        currentThemeString = getString(R.string.settings_summary_theme_dark);
    }
    binding.widgetConfWrapper.themeSpinner.setSelection(
            getSpinnerPositionOf(binding.widgetConfWrapper.themeSpinner.getAdapter(), currentThemeString));

    binding.widgetConfWrapper.itemRowsSeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // Plus one since seekbars start at zero
            widgetPrefs.putInt(KEY_TITLEROWS, progress + 1);
            // Only need to reload existing loader
            if (mNotesAdapter != null) {
                mNotesAdapter.notifyDataSetChanged();
            }
        }
    });
    binding.widgetConfWrapper.itemRowsSeekBar.setProgress(widgetPrefs.getInt(KEY_TITLEROWS, DEFAULT_ROWS) - 1);

    binding.widgetConfWrapper.transparencySeekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // final int color =
            // getHomescreenBackgroundColor(progress, 0xffffff);
            final int color = getHomescreenBackgroundColor(progress,
                    widgetPrefs.getInt(KEY_SHADE_COLOR, DEFAULT_SHADE));

            widgetPrefs.putInt(KEY_SHADE_COLOR, color);
            updateBG(color);
        }
    });
    // Set current item
    int opacity = widgetPrefs.getInt(KEY_SHADE_COLOR, DEFAULT_SHADE);
    // Isolate the alpha
    opacity = opacity >> 24;
    opacity &= 0xff;
    // Get percentage
    opacity = (100 * opacity) / 0xff;
    binding.widgetConfWrapper.transparencySeekBar.setProgress(opacity);

    binding.widgetConfWrapper.listSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapter, View arg1, int pos, long id) {
            widgetPrefs.putLong(KEY_LIST, id);
            try {
                widgetPrefs.putString(KEY_LIST_TITLE, ((Cursor) adapter.getItemAtPosition(pos)).getString(1));
            } catch (ClassCastException e) {
                // Its the all lists item
                widgetPrefs.putString(KEY_LIST_TITLE, ((String) adapter.getItemAtPosition(pos)));
            }

            // Need to reload tasks
            reloadTasks();
            // And set title
            binding.widgetPreviewWrapper.titleButton.setText(widgetPrefs.getString(KEY_LIST_TITLE, ""));
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
    mListAdapter = new ExtrasCursorAdapter(this, android.R.layout.simple_spinner_dropdown_item, null,
            new String[] { TaskList.Columns.TITLE }, new int[] { android.R.id.text1 },
            new int[] { ALL_LISTS_ID }, new int[] { R.string.show_from_all_lists },
            android.R.layout.simple_spinner_dropdown_item);

    // new SimpleCursorAdapter(this,
    // android.R.layout.simple_spinner_dropdown_item, null,
    // new String[] { TaskList.Columns.TITLE },
    // new int[] { android.R.id.text1 }, 0);
    binding.widgetConfWrapper.listSpinner.setAdapter(mListAdapter);

    binding.widgetConfWrapper.transparentHeaderCheckBox
            .setOnCheckedChangeListener(new OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    binding.widgetPreviewWrapper.widgetHeader
                            .setVisibility(isChecked ? View.GONE : View.VISIBLE);
                    widgetPrefs.putBoolean(KEY_HIDDENHEADER, isChecked);
                }
            });
    binding.widgetConfWrapper.transparentHeaderCheckBox
            .setChecked(widgetPrefs.getBoolean(KEY_HIDDENHEADER, false));

    binding.widgetConfWrapper.hideCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            widgetPrefs.putBoolean(KEY_HIDDENCHECKBOX, isChecked);
            if (mNotesAdapter != null)
                mNotesAdapter.notifyDataSetChanged();
        }
    });
    binding.widgetConfWrapper.hideCheckBox.setChecked(widgetPrefs.getBoolean(KEY_HIDDENCHECKBOX, false));

    binding.widgetConfWrapper.hideDateCheckBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            widgetPrefs.putBoolean(KEY_HIDDENDATE, isChecked);
            if (mNotesAdapter != null)
                mNotesAdapter.notifyDataSetChanged();
        }
    });
    binding.widgetConfWrapper.hideDateCheckBox.setChecked(widgetPrefs.getBoolean(KEY_HIDDENDATE, false));
}

From source file:com.juick.android.ThreadFragment.java

private void initAdapter() {
    final FragmentActivity activity = getActivity();
    listAdapter = new JuickMessagesAdapter(activity, this, JuickMessagesAdapter.TYPE_THREAD,
            JuickMessagesAdapter.SUBTYPE_OTHER);
    if (implicitlyCreated || restoreData != null) {
        getView().findViewById(android.R.id.empty).setVisibility(View.GONE);
    }//  w w  w  . java  2s  .  c  om
    if (implicitlyCreated) {
        return;
    }
    final ListView listView = getListView();
    listView.setOnItemClickListener(this);
    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position,
                final long id) {
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    if (activity.isFinishing()) {
                        System.out.println("OK");
                        return;
                    }
                    Object itemAtPosition = parent.getItemAtPosition(position);
                    if (itemAtPosition instanceof JuickMessage && parentMessagesSource != null) {
                        final JuickMessage msg = (JuickMessage) itemAtPosition;
                        if (msg.getMID() != null) {
                            doOnClickActualTime = System.currentTimeMillis();
                            doOnClick = new Runnable() {
                                @Override
                                public void run() {
                                    MessageMenu messageMenu = MainActivity.getMicroBlog(msg).getMessageMenu(
                                            activity, parentMessagesSource, listView, listAdapter);
                                    if (messageMenu != null) {
                                        messageMenu.onItemLongClick(parent, view, position, id);
                                    }
                                }
                            };
                            doOnClick.run();
                            doOnClick = null;

                        }

                    }
                }
            }, 100);
            return false;
        }
    });
    notification = new ThreadMessagesLoadNotification(activity, handler);
    navMenu.setVisibility(View.GONE);
    Thread thr = new Thread(new Runnable() {

        public void run() {
            final Utils.Function<Void, MessagesFragment.RetainedData> then = new Utils.Function<Void, MessagesFragment.RetainedData>() {
                @Override
                public Void apply(MessagesFragment.RetainedData retainedData) {
                    onObtainAllThread(retainedData, false);
                    return null;
                }
            };
            if (restoreData == null) {
                if (parentMessagesSource != null) {
                    if (prefetched != null) {
                        ArrayList<JuickMessage> messages = new ArrayList<JuickMessage>();
                        messages.add(prefetched.contextPost);
                        if (prefetched.contextReply != null) {
                            messages.add(prefetched.contextReply);
                        }
                        messages.add(prefetched);
                        prefetched.contextPost = null; // don't confuse later
                        prefetched.contextReply = null;
                        prefetched = null; // to enable proper reload
                        then.apply(new MessagesFragment.RetainedData(messages, null));
                    } else {
                        parentMessagesSource.getChildren(mid, notification,
                                new Utils.Function<Void, ArrayList<JuickMessage>>() {
                                    @Override
                                    public Void apply(ArrayList<JuickMessage> messages) {
                                        if (messages != null && messages.size() > 0
                                                && originalMessage != null) {
                                            if (messages.get(0).getRID() != 0) {
                                                messages.add(0, originalMessage);
                                            }
                                        }
                                        preprocessMessages(messages);
                                        then.apply(new MessagesFragment.RetainedData(messages, null));
                                        return null;
                                    }
                                });
                    }
                }
            } else {
                then.apply((MessagesFragment.RetainedData) restoreData);
                restoreData = null;
            }

        }
    }, "Init adapter, mid=" + mid);
    thr.start();
}

From source file:com.housekeeper.ar.healthhousekeeper.personalinfo.ModifyInfoActivity.java

private void initData() {
    try {/*  ww w. j  a v a 2s  .com*/
        usernameET.setText(joDoc.getString("userId"));
        //psdET.setText(joDoc.getString(""));
        nameET.setText(joDoc.getString("name"));
        idET.setText(joDoc.getString("identity"));

        telET.setText(joDoc.getString("phone"));
        mailET.setText(joDoc.getString("email"));
        //TODO ?
        //            workIdEditText.setText(joDoc.getString("workID"));

        sexStr = joDoc.getString("sex");
        birthdayStr = joDoc.getString("birthday");
        yearStr = birthdayStr.substring(0, 4);
        monthStr = birthdayStr.substring(5, 7);
        dayStr = birthdayStr.substring(8);
        Log.i(TAG, "yearString " + yearStr + " monthString " + monthStr + " dayString " + dayStr);

    } catch (JSONException e) {
        e.printStackTrace();
    }

    final List<String> yearList = getYearData();
    final List<String> monthList = getMonthData();
    final List<String> dayList = getDayData();
    final List<String> sexList = getSexData();

    ArrayAdapter<String> yearAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
            yearList) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(yearList.get(position));

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    ArrayAdapter<String> monthAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
            getMonthData()) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(monthList.get(position));

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    ArrayAdapter<String> dayAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
            getDayData()) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(dayList.get(position));

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    year.setAdapter(yearAdapter);
    //      year.setSelection(default_year_pos, true);
    month.setAdapter(monthAdapter);
    //      month.setSelection(default_month_pos, true);
    day.setAdapter(dayAdapter);
    //      day.setSelection(default_day_pos, true);

    ArrayAdapter<String> sexAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
            getSexData()) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(sexList.get(position));

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    sex.setAdapter(sexAdapter);
    //        sex.setSelection(default_sex_pos, true);

    //      ArrayAdapter<String> proAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item,namePros){
    //         @Override
    //         public View getDropDownView(int position, View convertView, ViewGroup parent) {
    //            LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    //            View view = inflater.inflate(R.layout.spinner_item_layout,
    //                  null);
    //            TextView label = (TextView) view
    //                  .findViewById(R.id.spinner_item_label);
    //
    //            label.setText(namePros[position]);
    //
    //
    //            return view;
    //            //return super.getDropDownView(position, convertView, parent);
    //         }
    //      };
    //      //?
    //
    //      proAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
    ////      proAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //      pro.setAdapter(proAdapter);
    //      pro.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    //
    //            @Override
    //            public void onItemSelected(AdapterView<?> parent, View view,
    //                                       int position, long id) {
    //                // TODO Auto-generated method stub
    //                proStr = parent.getItemAtPosition(position).toString();
    //                Log.v(TAG, "selcet proStr:" + proStr);
    //                if (proStr.equals(namePros[position])) {
    //                    idJobTitlesInt = idJobTitles[position];
    //                }
    //            }
    //
    //            @Override
    //            public void onNothingSelected(AdapterView<?> arg0) {
    //                // TODO Auto-generated method stub
    //
    //            }
    //
    //        });
    //        try {
    //            pro.setSelection(joDoc.getInt("jobTitleId")-1,true);
    //        } catch (JSONException e) {
    //            e.printStackTrace();
    //        }

    ArrayAdapter<String> shengAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, nameProvinces) {
        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = inflater.inflate(R.layout.spinner_item_layout, null);
            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

            label.setText(nameProvinces[position]);

            return view;
            //return super.getDropDownView(position, convertView, parent);
        }
    };
    //?

    shengAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
    sheng.setAdapter(shengAdapter);
    sheng.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> shengparent, View shengview, int shengposition,
                long shengid) {
            // TODO Auto-generated method stub
            myApp.setShengposition(shengposition);
            shengStr = shengparent.getItemAtPosition(shengposition).toString();
            Log.v(TAG, "shengStr:" + shengStr);
            if (shengStr.equals(nameProvinces[shengposition])) {
                Log.v(TAG, "position:" + shengposition);
                for (int i = 0; i < joProvinces.length; i++) {
                    try {

                        if (shengStr.equals(joProvinces[i].getString("name"))) {
                            jaCities = joProvinces[i].getJSONArray("cities");
                            joCities = new JSONObject[jaCities.length()];
                            nameCities = new String[joCities.length];

                            for (int j = 0; j < jaCities.length(); j++) {
                                joCities[j] = jaCities.getJSONObject(j);
                                nameCities[j] = joCities[j].getString("name");
                            }
                        }
                    } catch (JSONException e) {
                        // TODO Auto-generated catch block

                        e.printStackTrace();
                    }
                }
            }
            sheng.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View view, MotionEvent motionEvent) {

                    Log.i(TAG, "year touch ");
                    closeSoftKeyboard();
                    return false;
                }
            });
            shiAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item, nameCities) {
                @Override
                public View getDropDownView(int position, View convertView, ViewGroup parent) {
                    LayoutInflater inflater = (LayoutInflater) getContext()
                            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    View view = inflater.inflate(R.layout.spinner_item_layout, null);
                    TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

                    label.setText(nameCities[position]);

                    return view;
                    //return super.getDropDownView(position, convertView, parent);
                }
            };

            //?
            shiAdapter.setDropDownViewResource(R.layout.spinner_item_layout);

            //            shiAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            shi.setAdapter(shiAdapter);

            shi.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> shiparent, View shiview, int shiposition,
                        long shiid) {
                    // TODO Auto-generated method stub
                    shiStr = shiparent.getItemAtPosition(shiposition).toString();
                    Log.v(TAG, "shiStr:" + shiStr);
                    if (shiStr.equals(nameCities[shiposition])) {
                        for (int i = 0; i < joCities.length; i++) {
                            try {
                                if (shiStr.equals(joCities[i].getString("name"))) {
                                    jaHospitals = joCities[i].getJSONArray("hospitals");
                                    joHospitals = new JSONObject[jaHospitals.length()];
                                    nameHospitals = new String[joHospitals.length];
                                    for (int j = 0; j < jaHospitals.length(); j++) {
                                        joHospitals[j] = jaHospitals.getJSONObject(j);
                                        nameHospitals[j] = joHospitals[j].getString("name");
                                    }

                                }
                            } catch (JSONException e) {
                                // TODO Auto-generated catch block

                                e.printStackTrace();
                            }
                        }
                    }
                    shi.setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public boolean onTouch(View view, MotionEvent motionEvent) {

                            Log.i(TAG, "year touch ");
                            closeSoftKeyboard();
                            return false;
                        }
                    });
                    hospitalAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, R.layout.spinner_item,
                            nameHospitals) {
                        @Override
                        public View getDropDownView(int position, View convertView, ViewGroup parent) {
                            LayoutInflater inflater = (LayoutInflater) getContext()
                                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            View view = inflater.inflate(R.layout.spinner_item_layout, null);
                            TextView label = (TextView) view.findViewById(R.id.spinner_item_label);

                            label.setText(nameHospitals[position]);

                            return view;
                            //return super.getDropDownView(position, convertView, parent);
                        }
                    };

                    //?
                    hospitalAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
                    yy.setAdapter(hospitalAdapter);

                    yy.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                        @Override
                        public void onItemSelected(AdapterView<?> yyparent, View yyview, int yyposition,
                                long yyid) {
                            // TODO Auto-generated method stub
                            yyStr = yyparent.getItemAtPosition(yyposition).toString();
                            if (yyStr.equals(nameHospitals[yyposition])) {
                                for (int i = 0; i < joHospitals.length; i++) {
                                    try {
                                        if (yyStr.equals(joHospitals[i].getString("name"))) {
                                            jaDepartments = joHospitals[i].getJSONArray("departments");
                                            joDepartments = new JSONObject[jaDepartments.length()];
                                            nameDepartments = new String[joDepartments.length];
                                            idDepartments = new int[joDepartments.length];
                                            for (int j = 0; j < jaDepartments.length(); j++) {
                                                joDepartments[j] = jaDepartments.getJSONObject(j);
                                                nameDepartments[j] = joDepartments[j].getString("name");
                                                idDepartments[j] = joDepartments[j].getInt("id");

                                            }

                                        }
                                    } catch (JSONException e) {
                                        // TODO Auto-generated catch block

                                        e.printStackTrace();
                                    }
                                }
                            }
                            yy.setOnTouchListener(new View.OnTouchListener() {
                                @Override
                                public boolean onTouch(View view, MotionEvent motionEvent) {

                                    Log.i(TAG, "year touch ");
                                    closeSoftKeyboard();
                                    return false;
                                }
                            });
                            //                                departmentAdapter = new ArrayAdapter<String>(ModifyInfoActivity.this, android.R.layout.simple_spinner_item, nameDepartments) {
                            //                                    @Override
                            //                                    public View getDropDownView(int position, View convertView, ViewGroup parent) {
                            //                                        LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                            //                                        View view = inflater.inflate(R.layout.spinner_item_layout,
                            //                                                null);
                            //                                        TextView label = (TextView) view
                            //                                                .findViewById(R.id.spinner_item_label);
                            //
                            //                                        label.setText(nameDepartments[position]);
                            //
                            //
                            //                                        return view;
                            //                                        //return super.getDropDownView(position, convertView, parent);
                            //                                    }
                            //                                };
                            //
                            //                                ?
                            //                                departmentAdapter.setDropDownViewResource(R.layout.spinner_item_layout);
                            //                                ks.setAdapter(departmentAdapter);
                            //                                try {
                            //                                    ks.setSelection(joDoc.getInt("departmentId") - 1, true);
                            //                                } catch (JSONException e) {
                            //                                    e.printStackTrace();
                            //                                }
                            //                                ks.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                            //
                            //                                    @Override
                            //                                    public void onItemSelected(
                            //                                            AdapterView<?> ksparent, View ksview,
                            //                                            int ksposition, long ksid) {
                            //                                        // TODO Auto-generated method stub
                            //                                        ksStr = ksparent.getItemAtPosition(ksposition).toString();
                            //                                        if (ksStr.equals(nameDepartments[ksposition])) {
                            //                                            try {
                            //                                                idDepartmentInt = idDepartments[ksposition];
                            //                                                joDepartmentType = joDepartments[ksposition].getJSONObject("departmentType");
                            //                                                departmentTypeTv.setText(joDepartmentType.getString("name"));
                            //                                            } catch (JSONException e) {
                            //                                                // TODO Auto-generated catch block
                            //
                            //                                                e.printStackTrace();
                            //                                            }
                            //                                        }
                            //                                    }
                            //
                            //
                            //                                    @Override
                            //                                    public void onNothingSelected(
                            //                                            AdapterView<?> arg0) {
                            //                                        // TODO Auto-generated method stub
                            //
                            //                                    }
                            //                                });
                        }

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

                        }
                    });
                    //                        ks.setOnTouchListener(new View.OnTouchListener() {
                    //                            @Override
                    //                            public boolean onTouch(View view, MotionEvent motionEvent) {
                    //
                    //                                Log.i(TAG, "year touch ");
                    //                                closeSoftKeyboard();
                    //                                return false;
                    //                            }
                    //                        });
                }

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

                }
            });

        }

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

        }
    });
    year.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            yearStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });
    month.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            monthStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });
    day.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            dayStr = parent.getItemAtPosition(position).toString();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });
    sex.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            sexStr = parent.getItemAtPosition(position).toString();
        }

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

    for (int i = 0; i < sexList.size(); i++) {
        if (sexList.get(i).equals(sexStr)) {
            sex.setSelection(i, true);
            break;
        }
    }
    for (int i = 0; i < yearList.size(); i++) {
        if (yearList.get(i).equals(yearStr)) {
            year.setSelection(i, true);
            break;
        }
    }
    for (int i = 0; i < monthList.size(); i++) {
        if (monthList.get(i).equals(monthStr)) {
            month.setSelection(i, true);
            break;
        }
    }
    for (int i = 0; i < dayList.size(); i++) {
        if (dayList.get(i).equals(dayStr)) {
            day.setSelection(i, true);
            break;
        }
    }
    photoBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            picKind = 0;
            //                startActivityForResult(new Intent(ModifyInfoActivity.this, SelectPictureActivity.class), REQUEST_PICK);

            Intent intent = new Intent(ModifyInfoActivity.this, SelectPictureActivity.class);
            intent.putExtra("from", "modify");
            startActivityForResult(intent, REQUEST_PICK);
            //RegisterActivity.this.finish();
        }
    });

    signBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub
            picKind = 1;
            //                startActivityForResult(new Intent(ModifyInfoActivity.this, SelectPictureActivity.class), REQUEST_PICK);
            Intent intent = new Intent(ModifyInfoActivity.this, SelectPictureActivity.class);
            intent.putExtra("from", "modify");
            startActivityForResult(intent, REQUEST_PICK);
        }
    });

    regBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            modify();

        }
    });

}