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.fsck.k9.activity.Accounts.java

public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    BaseAccount account = (BaseAccount) parent.getItemAtPosition(position);
    onOpenAccount(account);/*from   w ww . j a  v  a  2  s .c om*/
}

From source file:com.landenlabs.all_devtool.PackageFragment.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    if (m_menu == null)
        return;/*from   w w w . ja v a2 s  .c o  m*/
    String itemStr = parent.getItemAtPosition(pos).toString();
    if (parent == m_loadSpinner) {
        m_show = pos;
        int menu_id = R.id.package_user;
        switch (pos) {
        case 0:
            menu_id = R.id.package_user;
            break;
        case 1:
            menu_id = R.id.package_system;
            break;
        case 2:
            menu_id = R.id.package_pref;
            break;
        case 3:
            menu_id = R.id.package_cache;
            break;
        case 4:
            menu_id = R.id.package_lib;
            break;
        }
        m_menu.findItem(menu_id).setChecked(true);
        updateList();
    } else if (parent == m_sortSpinner) {
        int menuId = -1;
        switch (pos) {
        case 0: // app
            menuId = R.id.package_sort_by_appname;
            break;
        case 1: // pkg
            menuId = R.id.package_sort_by_pkgname;
            break;
        case 2: // size
            menuId = R.id.package_sort_by_size;
            break;
        case 3: // update date;
            menuId = R.id.package_sort_by_update_date;
            break;
        case 4: // install date;
            menuId = R.id.package_sort_by_install_date;
            break;
        }

        if (id != -1) {
            m_menu.findItem(menuId).setChecked(true);
            m_sortBy = menuId;
            Message msgObj = m_handler.obtainMessage(MSG_SORT_LIST);
            m_handler.sendMessage(msgObj);
        }
    }
}

From source file:de.uni_koblenz_landau.apow.ObsDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.obs_detail_fragment, container, false);

    // Create UI references.
    mDeleteDialog = (DeleteDialogFragment) getFragmentManager().findFragmentByTag(DELETE_DIALOG_ID);
    if (mDeleteDialog != null) {
        mDeleteDialog.setListener(this);
    }/*from  w  ww  .  ja  va2  s  . co  m*/
    mClassLayout = (LinearLayout) view.findViewById(R.id.obs_detail_class);
    mClassSpinner = (Spinner) view.findViewById(R.id.obs_detail_class_spinner);
    mClassSpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {

            mQuestionLayout.setVisibility(View.GONE);
            mTestLayout.setVisibility(View.GONE);
            mFindingLayout.setVisibility(View.GONE);
            mSymptomLayout.setVisibility(View.GONE);

            switch (pos) {
            case Constants.CLASS_QUESTION:
                mQuestionLayout.setVisibility(View.VISIBLE);
                break;
            case Constants.CLASS_TEST:
                mTestLayout.setVisibility(View.VISIBLE);
                break;
            case Constants.CLASS_FINDING:
                mFindingLayout.setVisibility(View.VISIBLE);
                break;
            case Constants.CLASS_SYMPTOM:
                mSymptomLayout.setVisibility(View.VISIBLE);
                break;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mQuestionLayout = (LinearLayout) view.findViewById(R.id.obs_detail_question);
    mQuestionTextView = (EditText) view.findViewById(R.id.obs_detail_question_text);
    mTestLayout = (LinearLayout) view.findViewById(R.id.obs_detail_test);
    mTestConceptView = (Spinner) view.findViewById(R.id.obs_detail_test_concept);
    mTestConceptView.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
            ListViewItem item = (ListViewItem) parent.getItemAtPosition(pos);
            mTestUnitView.setText(item.getField2());
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    mTestUnitView = (TextView) view.findViewById(R.id.obs_detail_test_unit);
    mTestValueView = (EditText) view.findViewById(R.id.obs_detail_test_value);
    mFindingLayout = (LinearLayout) view.findViewById(R.id.obs_detail_finding);
    mFindingValueCodedView = (AutoCompleteTextView) view.findViewById(R.id.obs_detail_finding_value_coded);
    mFindingValueCodedView.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
        }

        @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 (!findingCodeBlock) {
                findingCode = -1;
            }
            findingCodeBlock = false;
            searchFindings(s.toString().trim());
        }
    });

    mFindingValueCodedView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
            findingCode = (int) id;
        }
    });
    mFindingCertaintyView = (CheckBox) view.findViewById(R.id.obs_detail_finding_certainty);
    mFindingSeverityCodedView = (CheckBox) view.findViewById(R.id.obs_detail_finding_severity_coded);
    mSymptomLayout = (LinearLayout) view.findViewById(R.id.obs_detail_symptom);
    mSymptomValueView = (AutoCompleteTextView) view.findViewById(R.id.obs_detail_symptom_value);
    mSymptomValueView.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
        }

        @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 (!symptomCodeBlock) {
                symptomCode = -1;
            }
            symptomCodeBlock = false;
            searchSymptoms(s.toString().trim());
        }
    });
    mSymptomValueView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> listView, View view, int position, long id) {
            symptomCode = (int) id;
        }
    });

    // Restore UI from saved instance or load data.
    if (savedInstanceState != null) {
        findingCode = savedInstanceState.getInt(ARG_FINDING_CODE);
        symptomCode = savedInstanceState.getInt(ARG_SYMPTOM_CODE);

        mObs = (Obs) savedInstanceState.getSerializable(ARG_OBS);
        if (mObs != null) {
            mTestConcepts = savedInstanceState.getParcelableArrayList(ARG_TEST_CONCEPTS);

            ArrayAdapter<ListViewItem> adapter = new ArrayAdapter<>(getActivity(),
                    android.R.layout.simple_spinner_item, mTestConcepts);
            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            mTestConceptView.setAdapter(adapter);
            restoreView();
        }
    } else {
        findingCode = -1;
        symptomCode = -1;
        loadObs();
    }
    return view;
}

From source file:com.abeo.tia.noordin.AddCaseStep2of4.java

public void addCaseListOfItems() {

    RequestParams params = null;//from w  ww. j  a  v a2  s  .  c om
    params = new RequestParams();

    RestService.post(METHOD_ADDCASE_ITEMLIST, params, new BaseJsonHttpResponseHandler<String>() {

        @Override
        public void onFailure(int arg0, Header[] arg1, Throwable arg2, String arg3, String arg4) {
            // TODO Auto-generated method stub
            System.out.println(arg3);

        }

        @Override
        public void onSuccess(int arg0, Header[] arg1, String arg2, String arg3) {
            // TODO Auto-generated method stub
            System.out.println("Add Case List Item Success Details ");
            System.out.println(arg2);

            try {

                arrayResponse = new JSONArray(arg2);
                // Create new list
                jsonItemList = new ArrayList<HashMap<String, String>>();

                for (int i = 0; i < arrayResponse.length(); i++) {

                    jsonResponse = arrayResponse.getJSONObject(i);

                    itemCode = jsonResponse.getString("ItemCode").toString();
                    itemName = jsonResponse.getString("ItemName").toString();

                    // SEND JSON DATA INTO SPINNER TITLE LIST
                    HashMap<String, String> addCaseItemList = new HashMap<String, String>();

                    // Send JSON Data to list activity
                    System.out.println("SEND ADD CASE ITEM LIST");
                    addCaseItemList.put("ItemCode_T", itemCode);
                    System.out.println(itemCode);
                    addCaseItemList.put("ItemName_T", itemName);
                    System.out.println(itemName);
                    System.out.println(" END ADD CASE ITEM LIST");

                    jsonItemList.add(addCaseItemList);
                    System.out.println("JSON ADD CASE ITEM LIST");
                    System.out.println(jsonItemList);
                }

            } catch (JSONException e) { // TODO Auto-generated
                // catch
                // block
                e.printStackTrace();
            }
            //Toast.makeText(AddCaseStep2of4.this, "AddCase Item Found", Toast.LENGTH_SHORT).show();
            dialog.dismiss();
            // Simple Adapter for List
            SimpleAdapter simpleAdapter = new SimpleAdapter(AddCaseStep2of4.this, jsonItemList,
                    R.layout.listview_column_addcase_itemlist, new String[] { "ItemCode_T", "ItemName_T" },
                    new int[] { R.id.listAddCaseHeader_ItemCodeText, R.id.listAddCaseHeader_ItemNameText });

            listViewItem.setAdapter(simpleAdapter);

            listViewItem.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                View ls = null;

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

                    if (get() != view && get() != null) {
                        get().setActivated(false);
                    }
                    //Toast.makeText(AddCaseStep2of4.this, "You Clicked at " + jsonItemList.get(position),
                    //   Toast.LENGTH_SHORT).show();
                    System.out.println(position);

                    //int mSelectedItem = position;      

                    view.setActivated(true);

                    // Get list of Item data
                    TextView c = (TextView) view.findViewById(R.id.listAddCaseHeader_ItemCodeText);
                    itemCode = c.getText().toString();
                    System.out.println(itemCode);

                    TextView D = (TextView) view.findViewById(R.id.listAddCaseHeader_ItemNameText);
                    itemName = D.getText().toString();

                    String data = (String) parent.getItemAtPosition(position).toString();
                    System.out.println(data);
                    set(view);

                    //store itemname and code in session
                    SharedPreferences prefLogin = getSharedPreferences("ItemData", Context.MODE_PRIVATE);

                    // We need an editor object to make changes
                    SharedPreferences.Editor edit = prefLogin.edit();

                    // Set/Store data
                    edit.putString("ItemCode", itemCode);
                    edit.putString("ItemName", itemName);
                    // Commit the changes
                    edit.commit();

                }

                private void set(View view) {
                    ls = view;
                }

                private View get() {
                    return ls;
                }
            });

            spinnerpropertyPROJECT.setSelection(2);
        }

        @Override
        protected String parseResponse(String arg0, boolean arg1) throws Throwable {

            // Get Json response
            arrayResponse = new JSONArray(arg0);
            jsonResponse = arrayResponse.getJSONObject(0);

            System.out.println("Add Case List Itemparse ParseResponse");
            System.out.println(arg0);
            return null;
        }
    });

}

From source file:com.irccloud.android.fragment.MessageViewFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.messageview, container, false);
    statusView = (TextView) v.findViewById(R.id.statusView);
    statusView.setOnClickListener(new OnClickListener() {

        @Override//from   w  ww.jav  a2 s .  c om
        public void onClick(View v) {
            if (buffer != null && conn != null && server != null && server.status != null
                    && server.status.equalsIgnoreCase("disconnected")) {
                conn.reconnect(buffer.cid);
            }
        }

    });

    awayView = v.findViewById(R.id.away);
    awayView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            conn.back(buffer.cid);
        }

    });
    awayTxt = (TextView) v.findViewById(R.id.awayTxt);
    unreadBottomView = v.findViewById(R.id.unreadBottom);
    unreadBottomView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            getListView().setSelection(adapter.getCount() - 1);
        }

    });
    unreadBottomLabel = (TextView) v.findViewById(R.id.unread);
    highlightsBottomLabel = (TextView) v.findViewById(R.id.highlightsBottom);

    unreadTopView = v.findViewById(R.id.unreadTop);
    unreadTopView.setVisibility(View.GONE);
    unreadTopView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (adapter.getLastSeenEIDPosition() > 0) {
                if (heartbeatTask != null)
                    heartbeatTask.cancel(true);
                heartbeatTask = new HeartbeatTask();
                heartbeatTask.execute((Void) null);
                hideView(unreadTopView);
            }
            getListView().setSelection(adapter.getLastSeenEIDPosition());
        }

    });
    unreadTopLabel = (TextView) v.findViewById(R.id.unreadTopText);
    highlightsTopLabel = (TextView) v.findViewById(R.id.highlightsTop);
    Button b = (Button) v.findViewById(R.id.markAsRead);
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            hideView(unreadTopView);
            if (heartbeatTask != null)
                heartbeatTask.cancel(true);
            heartbeatTask = new HeartbeatTask();
            heartbeatTask.execute((Void) null);
        }
    });
    globalMsgView = v.findViewById(R.id.globalMessageView);
    globalMsg = (TextView) v.findViewById(R.id.globalMessageTxt);
    b = (Button) v.findViewById(R.id.dismissGlobalMessage);
    b.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (conn != null)
                conn.globalMsg = null;
            update_global_msg();
        }
    });
    ((ListView) v.findViewById(android.R.id.list)).setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> list, View v, int pos, long id) {
            try {
                longPressOverride = mListener
                        .onMessageLongClicked((EventsDataSource.Event) list.getItemAtPosition(pos));
                return longPressOverride;
            } catch (Exception e) {
            }
            return false;
        }
    });
    spinner = (ProgressBar) v.findViewById(R.id.spinner);
    suggestionsContainer = v.findViewById(R.id.suggestionsContainer);
    suggestions = (GridView) v.findViewById(R.id.suggestions);
    headerViewContainer = getLayoutInflater(null).inflate(R.layout.messageview_header, null);
    headerView = headerViewContainer.findViewById(R.id.progress);
    backlogFailed = (TextView) headerViewContainer.findViewById(R.id.backlogFailed);
    loadBacklogButton = (Button) headerViewContainer.findViewById(R.id.loadBacklogButton);
    loadBacklogButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (conn != null && buffer != null) {
                backlogFailed.setVisibility(View.GONE);
                loadBacklogButton.setVisibility(View.GONE);
                headerView.setVisibility(View.VISIBLE);
                conn.request_backlog(buffer.cid, buffer.bid, earliest_eid);
            }
        }
    });
    ((ListView) v.findViewById(android.R.id.list)).addHeaderView(headerViewContainer);
    return v;
}

From source file:org.de.jmg.learn.SettingsActivity.java

private void initSpinners(boolean blnRestart) {
    libLearn.gStatus = "initSpinners";
    try {//  w  w  w. jav  a  2 s  .c om
        spnAbfragebereich = (Spinner) findViewById(R.id.spnAbfragebereich);
        spnASCII = (Spinner) findViewById(R.id.spnASCII);
        spnStep = (Spinner) findViewById(R.id.spnStep);
        spnDisplayDurationWord = (Spinner) findViewById(R.id.spnAnzeigedauerWord);
        spnDisplayDurationBed = (Spinner) findViewById(R.id.spnAnzeigedauerBed);
        spnPaukRepetitions = (Spinner) findViewById(R.id.spnRepetitions);
        spnProbabilityFactor = (Spinner) findViewById(R.id.spnProbabilityFactor);
        spnRestartInterval = (Spinner) findViewById(R.id.spnRestartInterval);
        spnLanguages = (Spinner) findViewById(R.id.spnLanguages);
        spnColors = (org.de.jmg.lib.NoClickSpinner) findViewById(R.id.spnColors);
        spnSounds = (org.de.jmg.lib.NoClickSpinner) findViewById(R.id.spnSounds);
        spnLangWord = (Spinner) findViewById(R.id.spnLangWord);
        spnLangMeaning = (Spinner) findViewById(R.id.spnLangMeaning);
        if (!blnRestart)
            langinitialized = 0;
        else
            langinitialized = 0;
        if (spnAbfragebereich.getAdapter() != null && spnAbfragebereich.getAdapter().getCount() > 0)
            return;
        if (Colors == null || Colors != null) {
            Colors = new ColorsArrayAdapter(_main, R.layout.spinnerrow);
            Colors.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

            Sounds = new SoundsArrayAdapter(_main, R.layout.soundsspinnerrow);
            Sounds.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        }

        spnASCII.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        spnStep.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        spnDisplayDurationBed.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        spnDisplayDurationWord.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        spnAbfragebereich.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        spnPaukRepetitions.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        spnProbabilityFactor.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        spnRestartInterval.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        spnLanguages.getBackground().setColorFilter(Color.BLACK, PorterDuff.Mode.SRC_ATOP);
        //spnColors.getBackground().setColorFilter(Color.BLACK,   PorterDuff.Mode.SRC_ATOP);
        //spnSounds.getBackground().setColorFilter(Color.BLACK,   PorterDuff.Mode.SRC_ATOP);

        // Create an ArrayAdapter using the string array and a default
        // spinner layout
        ScaledArrayAdapter<CharSequence> adapter = ScaledArrayAdapter.createFromResource(_main,
                R.array.spnAbfragebereichEntries, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        if (lib.NookSimpleTouch() && mScale == 1)
            adapter.Scale = 1.8f;
        // Apply the adapter to the spinner
        spnAbfragebereich.setAdapter(adapter);
        spnAbfragebereich.setSelection(getIntent().getShortExtra("Abfragebereich", (short) -1) + 1);

        spnAbfragebereich.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                intent.putExtra("Abfragebereich", (short) (position - 1));
                intent.putExtra("OK", "OK");
            }

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

            }

        });
        ScaledArrayAdapter<CharSequence> adapterStep = ScaledArrayAdapter.createFromResource(_main,
                R.array.spnStepEntries, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapterStep.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterStep.Scale = 1.8f;
        spnStep.setAdapter(adapterStep);
        spnStep.setSelection(adapterStep.getPosition("" + getIntent().getShortExtra("Step", (short) 5)));
        spnStep.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                intent.putExtra("Step",
                        (short) (Integer.parseInt((String) parent.getItemAtPosition(position))));
                intent.putExtra("OK", "OK");
            }

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

            }

        });

        ScaledArrayAdapter<String> adapterASCII = new ScaledArrayAdapter<String>(_main,
                android.R.layout.simple_spinner_item);
        // adapterASCII.addAll(Charset.availableCharsets().values());
        ArrayList<String> charsets = new ArrayList<String>();
        for (Charset c : Charset.availableCharsets().values()) {
            charsets.add(c.name());
        }
        adapterASCII.addAll(charsets);
        // Specify the layout to use when the list of choices appears
        adapterASCII.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        // Apply the adapter to the spinner
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterASCII.Scale = 1.8f;
        spnASCII.setAdapter(adapterASCII);
        String CharsetASCII = getIntent().getStringExtra("CharsetASCII");
        if (!libString.IsNullOrEmpty(CharsetASCII)) {
            int i = 0;
            for (Charset c : Charset.availableCharsets().values()) {
                if (c.name().equalsIgnoreCase(CharsetASCII)) {
                    break;
                }
                i++;
            }
            if (i < adapterASCII.getCount()) {
                spnASCII.setSelection(i);
            }

        }
        spnASCII.setOnItemSelectedListener(new OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                intent.putExtra("CharsetASCII", ((String) (parent.getSelectedItem())));
                intent.putExtra("OK", "OK");
            }

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

            }

        });

        final ScaledArrayAdapter<CharSequence> adapterDDWord = ScaledArrayAdapter.createFromResource(_main,
                R.array.spnDurations, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapterDDWord.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterDDWord.Scale = 1.8f;
        // Apply the adapter to the spinner
        spnDisplayDurationWord.setAdapter(adapterDDWord);
        String strDD = "" + getIntent().getFloatExtra("DisplayDurationWord", 1.5f);
        strDD = strDD.replace(".0", "");
        int Pos = adapterDDWord.getPosition(strDD);
        spnDisplayDurationWord.setSelection(Pos);
        spnDisplayDurationWord.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                intent.putExtra("DisplayDurationWord",
                        (Float.parseFloat((String) parent.getItemAtPosition(position))));
                intent.putExtra("OK", "OK");
            }

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

            }

        });

        ScaledArrayAdapter<CharSequence> adapterDDBed = ScaledArrayAdapter.createFromResource(_main,
                R.array.spnDurations, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapterDDBed.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterDDBed.Scale = 1.8f;
        // Apply the adapter to the spinner
        spnDisplayDurationBed.setAdapter(adapterDDBed);
        strDD = "" + getIntent().getFloatExtra("DisplayDurationBed", 2.5f);
        strDD = strDD.replace(".0", "");
        Pos = adapterDDBed.getPosition(strDD);
        spnDisplayDurationBed.setSelection(Pos);
        spnDisplayDurationBed.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                intent.putExtra("DisplayDurationBed",
                        (Float.parseFloat((String) parent.getItemAtPosition(position))));
                intent.putExtra("OK", "OK");
            }

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

            }

        });

        ScaledArrayAdapter<CharSequence> adapterPaukRepetitions = ScaledArrayAdapter.createFromResource(_main,
                R.array.spnRepetitions, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapterPaukRepetitions.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterPaukRepetitions.Scale = 1.8f;
        spnPaukRepetitions.setAdapter(adapterPaukRepetitions);
        Pos = getIntent().getIntExtra("PaukRepetitions", 3) - 1;
        spnPaukRepetitions.setSelection(Pos);
        spnPaukRepetitions.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                intent.putExtra("PaukRepetitions",
                        (Integer.parseInt((String) parent.getItemAtPosition(position))));
                intent.putExtra("OK", "OK");
            }

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

            }

        });

        ScaledArrayAdapter<CharSequence> adapterProbabilityFactor = ScaledArrayAdapter.createFromResource(_main,
                R.array.spnProbabilityFactors, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapterProbabilityFactor.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterProbabilityFactor.Scale = 1.8f;
        spnProbabilityFactor.setAdapter(adapterProbabilityFactor);
        float ProbabilityFactor = getIntent().getFloatExtra("ProbabilityFactor", -1f);
        if (ProbabilityFactor == -1) {
            strDD = _main.getString((R.string.auto));
        } else {
            strDD = "" + ProbabilityFactor;
            strDD = strDD.replace(".0", "");
        }

        ArrayAdapter<CharSequence> a1 = adapterProbabilityFactor;
        if (a1 != null) {
            try {
                libLearn.gStatus = "get Spinneradapter ProbabilityFactor";
                Pos = (a1.getPosition(strDD));
                spnProbabilityFactor.setSelection(Pos);
            } catch (Exception ex) {
                lib.ShowException(_main, ex);
            }

        }

        spnProbabilityFactor.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                String strDD = (String) parent.getItemAtPosition(position);
                if (strDD.equalsIgnoreCase(_main.getString(R.string.auto)))
                    strDD = "-1";
                intent.putExtra("ProbabilityFactor", (Float.parseFloat(strDD)));
                intent.putExtra("OK", "OK");
            }

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

            }

        });

        ScaledArrayAdapter<CharSequence> adapterRestartInterval = ScaledArrayAdapter.createFromResource(_main,
                R.array.spnRestartInterval, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapterRestartInterval.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterRestartInterval.Scale = 1.8f;
        spnRestartInterval.setAdapter(adapterRestartInterval);
        int RestartInterval = getIntent().getIntExtra("RestartInterval", -1);
        if (RestartInterval == -1) {
            strDD = _main.getString(R.string.off);
        } else {
            strDD = "" + RestartInterval;
        }

        a1 = adapterRestartInterval;
        if (a1 != null) {
            try {
                libLearn.gStatus = "get Spinneradapter ProbabilityFactor";
                Pos = (a1.getPosition(strDD));
                spnRestartInterval.setSelection(Pos);
            } catch (Exception ex) {
                lib.ShowException(_main, ex);
            }

        }

        spnRestartInterval.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                String strDD = (String) parent.getItemAtPosition(position);
                if (strDD.equalsIgnoreCase(_main.getString(R.string.off)))
                    strDD = "-1";
                intent.putExtra("RestartInterval", (Integer.parseInt(strDD)));
                intent.putExtra("OK", "OK");
            }

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

            }

        });

        ScaledArrayAdapter<CharSequence> adapterLanguages = ScaledArrayAdapter.createFromResource(_main,
                R.array.spnLanguages, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapterLanguages.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterLanguages.Scale = 1.8f;
        spnLanguages.setAdapter(adapterLanguages);
        int Language = getIntent().getIntExtra("Language",
                org.de.jmg.learn.vok.Vokabel.EnumSprachen.undefiniert.ordinal());
        spnLanguages.setSelection(Language);
        spnLanguages.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                intent.putExtra("Language", position);
                intent.putExtra("OK", "OK");
            }

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

            }

        });

        adapterLangWord = new ScaledArrayAdapter<>(_main, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapterLangWord.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterLangWord.Scale = 1.8f;

        adapterLangWord.add(new DisplayLocale(new Locale("", "")));
        adapterLangWord.add(new DisplayLocale(new Locale("_off")));
        for (Locale l : Locale.getAvailableLocales()) {
            DisplayLocale dl = new DisplayLocale(l);
            adapterLangWord.add(dl);
        }
        sortLangWord();

        spnLangWord.setAdapter(adapterLangWord);
        /*
        if (selectedLocale != null)
        {
           int pos = adapterLangWord.getPosition(selectedLocale);
           spnLangWord.setSelection (-1);
           spnLangWord.setSelection(pos);
        }*/
        spnLangWord.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (position <= 0 || langinitialized == 0) {
                    langinitialized += 1;
                    return;
                }
                Locale l = adapterLangWord.getItem(position).locale;
                int res = 0;
                if (_main.tts.isLanguageAvailable(Locale.US) >= 0) {
                    res = _main.tts.setLanguage(l);
                }
                if (!chkTextToSpeech.isChecked() || res >= 0 || l.toString().equalsIgnoreCase("_off")
                        || !_main.blnTextToSpeech
                        || lib.ShowMessageYesNo(_main,
                                String.format(_main.getString(R.string.msgLanguageNotavailable),
                                        l.getDisplayLanguage() + " " + l.getDisplayCountry()),
                                "") == yesnoundefined.yes) {
                    intent.putExtra("langword", lib.toLanguageTag(l));
                    intent.putExtra("OK", "OK");
                }
            }

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

            }

        });

        adapterLangMeaning = new ScaledArrayAdapter<>(_main, android.R.layout.simple_spinner_item);
        // Specify the layout to use when the list of choices appears
        adapterLangMeaning.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        if (lib.NookSimpleTouch() && mScale == 1)
            adapterLangMeaning.Scale = 1.8f;
        adapterLangMeaning.add(new DisplayLocale(new Locale("", "")));
        adapterLangMeaning.add(new DisplayLocale(new Locale("_off")));
        for (Locale l : Locale.getAvailableLocales()) {
            DisplayLocale dl = new DisplayLocale((l));
            adapterLangMeaning.add(dl);
        }
        sortLangMeaning();

        spnLangMeaning.setAdapter(adapterLangMeaning);
        /*
        if (selectedLocale != null)
        {
           int pos = adapterLangMeaning.getPosition(selectedLocale);
           spnLangMeaning.setSelection(-1);
           spnLangMeaning.setSelection(pos);
        }
        */
        spnLangMeaning.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (position <= 0 || langinitialized < 2) {
                    langinitialized += 1;
                    return;
                }
                Locale l = adapterLangMeaning.getItem(position).locale;
                int res = 0;
                if (_main.tts.isLanguageAvailable(Locale.US) >= 0) {
                    res = _main.tts.setLanguage(l);
                }
                if (!chkTextToSpeech.isChecked() || res >= 0 || l.toString().equalsIgnoreCase("_off")
                        || !_main.blnTextToSpeech
                        || lib.ShowMessageYesNo(_main,
                                String.format(_main.getString(R.string.msgLanguageNotavailable),
                                        l.getDisplayLanguage() + " " + l.getDisplayCountry()),
                                "") == yesnoundefined.yes) {
                    intent.putExtra("langmeaning", lib.toLanguageTag(l));
                    intent.putExtra("OK", "OK");
                }
            }

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

            }

        });

        if (lib.NookSimpleTouch() && mScale == 1)
            Colors.Scale = 1.8f;
        spnColors.setAdapter(Colors);
        spnColors.setOnLongClickListener(new android.widget.AdapterView.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {

                spnColors.blnDontCallOnClick = true;
                ShowColorDialog();
                return false;
            }
        });
        spnColors.setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

                spnColors.blnDontCallOnClick = true;
                ShowColorDialog();
                return false;
            }
        });

        if (lib.NookSimpleTouch() && mScale == 1)
            Sounds.Scale = 1.8f;
        spnSounds.setAdapter(Sounds);
        spnSounds.setOnLongClickListener(new android.widget.AdapterView.OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {

                spnSounds.blnDontCallOnClick = true;
                ShowSoundsDialog();
                return false;
            }
        });
        spnSounds.setOnItemLongClickListener(new android.widget.AdapterView.OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

                spnSounds.blnDontCallOnClick = true;
                ShowSoundsDialog();
                return false;
            }
        });

        spnSounds.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

                SoundSetting item = (SoundSetting) parent.getItemAtPosition(position);
                File F = new File(item.SoundPath);
                try {
                    if (F.exists())
                        lib.playSound(F);
                    else
                        lib.playSound(_main.getAssets(), item.SoundPath);
                } catch (Exception e) {

                    e.printStackTrace();
                }
            }

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

            }

        });

    } catch (Exception ex) {
        lib.ShowException(_main, ex);
    }
}

From source file:com.ifoer.expeditionphone.MainActivity.java

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    BaseDiagAdapter baseDiagAdapter = (BaseDiagAdapter) arg0.getAdapter();
    baseDiagAdapter.setSelectItem(arg2);
    baseDiagAdapter.notifyDataSetChanged();
    DataCleanManager.cleanLibs(contexts);
    this.cc = MySharedPreferences.getStringValue(contexts, MySharedPreferences.CCKey);
    if (this.cc != null) {
        if (!this.cc.equals(XmlPullParser.NO_NAMESPACE)) {
            String type = MySharedPreferences.getStringValue(this, "getSerialNo");
            if (type == null || type.equals(Contact.RELATION_FRIEND)) {
                if (Common.isNetworkAvailable(this)) {
                    new PortNumAsy(REQUEST_CONNECT_DEVICE).execute(new String[0]);
                } else {
                    Toast.makeText(this, C0136R.string.network_exception, 0).show();
                }//  w ww  . j a  v  a2 s  .c o m
            }
        }
    }
    if (Environment.getExternalStorageState().equals("mounted")) {
        HashMap<String, Object> map = (HashMap) arg0.getItemAtPosition(arg2);
        String softPackageId = map.get("softPackageId").toString();
        String softId = map.get("softId").toString();
        String icon = map.get("icon").toString();
        MySharedPreferences.setString(contexts, MySharedPreferences.savesoftPackageId, softPackageId);
        String serialNo1 = MySharedPreferences.getStringValue(contexts, MySharedPreferences.serialNoKey);
        MySharedPreferences.setString(contexts, MySharedPreferences.generateOperatingRecord,
                Contact.RELATION_ASK);
        if (serialNo1 != null) {
            if (!XmlPullParser.NO_NAMESPACE.equals(serialNo1)) {
                if (country == null || country.length() <= 0) {
                    country = Locale.getDefault().getCountry();
                }
                country = Locale.getDefault().getCountry();
                if (!DBDao.getInstance(this).isDownload(softPackageId, serialNo1, AndroidToLan.toLan(country),
                        database)) {
                    this.cc = MySharedPreferences.getStringValue(contexts, MySharedPreferences.CCKey);
                    if (this.cc != null) {
                        if (!this.cc.equals(XmlPullParser.NO_NAMESPACE)) {
                            String serialNo = MySharedPreferences.getStringValue(contexts,
                                    MySharedPreferences.serialNoKey);
                            if (serialNo != null) {
                                if (!XmlPullParser.NO_NAMESPACE.equals(serialNo)) {
                                    String softName = ((TextView) arg1.findViewById(C0136R.id.car_name))
                                            .getText().toString();
                                    if (Common.isNetworkAvailable(this)) {
                                        SoftIdListTask softListTask = new SoftIdListTask();
                                        String[] strArr = new String[MESSAGE_DEVICE_NAME];
                                        strArr[0] = softId;
                                        strArr[REQUEST_CONNECT_DEVICE] = softPackageId;
                                        strArr[REQUEST_ENABLE_BT] = softName;
                                        strArr[REQUEST_CIRCLE_ADD_IMAGE] = icon;
                                        softListTask.execute(strArr);
                                        return;
                                    }
                                    Toast.makeText(this, C0136R.string.network_exception, 0).show();
                                    return;
                                }
                            }
                            Toast.makeText(this, C0136R.string.port_input, 0).show();
                            return;
                        }
                    }
                    SimpleDialog.ToastToLogin(this);
                    return;
                } else if (serialPort != null) {
                    openConnect(serialNo1, softPackageId);
                    return;
                } else {
                    return;
                }
            }
        }
        startActivity(new Intent(this, SerialNumberActivity.class));
        overridePendingTransition(0, 0);
        return;
    }
    Toast.makeText(this, getResources().getString(C0136R.string.sdcard), 0).show();
}

From source file:org.openintents.shopping.ui.ShoppingActivity.java

/**
 * Hook up buttons, lists, and edittext with functionality.
 *//*from w w  w  .j  a v a2s. c  o  m*/
private void createView() {

    // Temp-create either Spinner or List based upon the Display
    createList();

    mAddPanel = findViewById(R.id.add_panel);
    mEditText = (AutoCompleteTextView) findViewById(R.id.autocomplete_add_item);

    fillAutoCompleteTextViewAdapter(mEditText);
    mEditText.setThreshold(1);
    mEditText.setOnKeyListener(new OnKeyListener() {

        private int mLastKeyAction = KeyEvent.ACTION_UP;

        public boolean onKey(View v, int keyCode, KeyEvent key) {
            // Shortcut: Instead of pressing the button,
            // one can also press the "Enter" key.
            if (debug) {
                Log.i(TAG, "Key action: " + key.getAction());
            }
            if (debug) {
                Log.i(TAG, "Key code: " + keyCode);
            }
            if (keyCode == KeyEvent.KEYCODE_ENTER) {

                if (mEditText.isPopupShowing()) {
                    mEditText.performCompletion();
                }

                // long key press might cause call of duplicate onKey events
                // with ACTION_DOWN
                // this would result in inserting an item and showing the
                // pick list

                if (key.getAction() == KeyEvent.ACTION_DOWN && mLastKeyAction == KeyEvent.ACTION_UP) {
                    insertNewItem();
                }

                mLastKeyAction = key.getAction();
                return true;
            }
            return false;
        }
    });
    mEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            if (mItemsView.mMode == MODE_ADD_ITEMS) {
                // small optimization: Only care about updating
                // the button label on each key pressed if we
                // are in "add items" mode.
                updateButton();
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

    });

    mButton = (Button) findViewById(R.id.button_add_item);
    mButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            insertNewItem();
        }
    });
    mButton.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (PreferenceActivity.getAddForBarcode(getApplicationContext()) == false) {
                if (debug) {
                    Log.v(TAG, "barcode scanner on add button long click disabled");
                }
                return false;
            }

            Intent intent = new Intent();
            intent.setData(mListUri);
            intent.setClassName("org.openintents.barcodescanner",
                    "org.openintents.barcodescanner.BarcodeScanner");
            intent.setAction(Intent.ACTION_GET_CONTENT);
            intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
            try {
                startActivityForResult(intent, REQUEST_CODE_CATEGORY_ALTERNATIVE);
            } catch (ActivityNotFoundException e) {
                if (debug) {
                    Log.v(TAG, "barcode scanner not found");
                }
                showDialog(DIALOG_GET_FROM_MARKET);
                return false;
            }

            // Instead of calling the class of barcode
            // scanner directly, a more generic approach would
            // be to use a general activity picker.
            //
            // TODO: Implement onActivityResult.
            // Problem: User has to pick activity every time.
            // Choice should be storeable in Stettings.
            // Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
            // intent.setData(mListUri);
            // intent.addCategory(Intent.CATEGORY_ALTERNATIVE);
            //
            // Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
            // pickIntent.putExtra(Intent.EXTRA_INTENT, intent);
            // pickIntent.putExtra(Intent.EXTRA_TITLE,
            // getText(R.string.title_select_item_from));
            // try {
            // startActivityForResult(pickIntent,
            // REQUEST_CODE_CATEGORY_ALTERNATIVE);
            // } catch (ActivityNotFoundException e) {
            // Log.v(TAG, "barcode scanner not found");
            // return false;
            // }
            return true;
        }
    });

    mLayoutParamsItems = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);

    mToastBar = (ActionableToastBar) findViewById(R.id.toast_bar);

    mItemsView = (ShoppingItemsView) findViewById(R.id.list_items);
    mItemsView.setThemedBackground(findViewById(R.id.background));
    mItemsView.setCustomClickListener(this);
    mItemsView.setToastBar(mToastBar);
    mItemsView.initTotals();

    mItemsView.setItemsCanFocus(true);
    mItemsView.setDragListener(new DragListener() {

        @Override
        public void drag(int from, int to) {
            if (debug) {
                Log.v("DRAG", "" + from + "/" + to);
            }

        }
    });
    mItemsView.setDropListener(new DropListener() {

        @Override
        public void drop(int from, int to) {
            if (debug) {
                Log.v("DRAG", "" + from + "/" + to);
            }

        }
    });

    mItemsView.setOnItemClickListener(new OnItemClickListener() {

        public void onItemClick(AdapterView parent, View v, int pos, long id) {
            Cursor c = (Cursor) parent.getItemAtPosition(pos);
            onCustomClick(c, pos, EditItemDialog.FieldType.ITEMNAME, v);
            // DO NOT CLOSE THIS CURSOR - IT IS A MANAGED ONE.
            // ---- c.close();
        }

    });

    mItemsView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {

        public void onCreateContextMenu(ContextMenu contextmenu, View view, ContextMenuInfo info) {
            contextmenu.add(0, MENU_EDIT_ITEM, 0, R.string.menu_edit_item).setShortcut('1', 'e');
            contextmenu.add(0, MENU_MARK_ITEM, 0, R.string.menu_mark_item).setShortcut('2', 'm');
            contextmenu.add(0, MENU_ITEM_STORES, 0, R.string.menu_item_stores).setShortcut('3', 's');
            contextmenu.add(0, MENU_REMOVE_ITEM_FROM_LIST, 0, R.string.menu_remove_item).setShortcut('4', 'r');
            contextmenu.add(0, MENU_COPY_ITEM, 0, R.string.menu_copy_item).setShortcut('5', 'c');
            contextmenu.add(0, MENU_DELETE_ITEM, 0, R.string.menu_delete_item).setShortcut('6', 'd');
            contextmenu.add(0, MENU_MOVE_ITEM, 0, R.string.menu_move_item).setShortcut('7', 'l');
        }

    });
}

From source file:cm.aptoide.pt.MainActivity.java

private void loadUi() {
    setContentView(R.layout.activity_aptoide);
    TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.indicator);
    pager = (ViewPager) findViewById(R.id.viewpager);

    if (!ApplicationAptoide.MULTIPLESTORES) {
        depth = ListDepth.CATEGORY1;//from   www.j ava  2 s  .c  o m
        store_id = 1;
    }

    updateView.findViewById(R.id.update_button).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            updateAll();
        }
    });

    availableListView.setFastScrollEnabled(true);
    availableListView.addHeaderView(breadcrumbs, null, false);

    registerForContextMenu(updatesListView);
    updatesListView.setLongClickable(true);

    availableView.findViewById(R.id.refresh_view_layout).findViewById(R.id.refresh_view)
            .setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    refreshClick = true;
                    availableView.findViewById(R.id.refresh_view_layout).setVisibility(View.GONE);
                    refreshAvailableList(false);

                }
            });

    joinStores.setOnCheckedChangeListener(new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            joinStores_boolean = isChecked;
            // if (isChecked) {
            // addBreadCrumb("All Stores", depth);
            // } else {
            // breadcrumbs.removeAllViews();
            // }
            refreshAvailableList(true);
        }
    });

    bindService(serviceDownloadManagerIntent, serviceManagerConnection, BIND_AUTO_CREATE);

    pb.setText(R.string.add_store_button_below);

    addStoreButton.setOnClickListener(addStoreListener);

    if (!ApplicationAptoide.MULTIPLESTORES) {
        addStoreButton.setVisibility(View.GONE);
    }

    availableListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i;
            View v = availableListView.getChildAt(0);
            scrollMemory.put(depth, new ListViewPosition((v == null) ? 0 : v.getTop(),
                    availableListView.getFirstVisiblePosition()));
            switch (depth) {
            case STORES:
                depth = ListDepth.CATEGORY1;
                store_id = id;
                break;
            case CATEGORY1:
                String category = ((Cursor) parent.getItemAtPosition(position)).getString(1);
                if (category.equals("Top Apps")) {
                    depth = ListDepth.TOPAPPS;
                } else if (category.equals("Latest Apps")) {
                    depth = ListDepth.LATESTAPPS;
                } else if (id == LATEST_LIKES) {
                    depth = ListDepth.LATEST_LIKES;
                } else if (id == LATEST_COMMENTS) {
                    depth = ListDepth.LATEST_COMMENTS;
                } else if (id == -3) {
                    if (!Login.isLoggedIn(mContext)) {
                        Toast toast = Toast.makeText(mContext,
                                mContext.getString(R.string.you_need_to_login_toast), Toast.LENGTH_SHORT);
                        toast.show();
                        return;
                    } else {
                        depth = ListDepth.RECOMMENDED;
                    }
                } else if (id == -4) {
                    depth = ListDepth.ALLAPPLICATIONS;
                } else if (id == -10) {
                    Toast toast = Toast.makeText(mContext, mContext.getString(R.string.store_beginning_to_load),
                            Toast.LENGTH_SHORT);
                    toast.show();
                    return;
                } else {
                    depth = ListDepth.CATEGORY2;
                }
                category_id = id;
                break;
            case CATEGORY2:
                depth = ListDepth.APPLICATIONS;
                category2_id = id;
                break;
            case TOPAPPS:
                i = new Intent(MainActivity.this, ApkInfo.class);
                i.putExtra("_id", id);
                i.putExtra("top", true);
                i.putExtra("category", Category.TOP.ordinal());
                startActivity(i);
                return;
            case LATESTAPPS:
                i = new Intent(MainActivity.this, ApkInfo.class);
                i.putExtra("_id", id);
                i.putExtra("top", true);
                i.putExtra("category", Category.LATEST.ordinal());
                startActivity(i);
                return;
            case APPLICATIONS:
            case ALLAPPLICATIONS:
            case RECOMMENDED:
                i = new Intent(MainActivity.this, ApkInfo.class);
                i.putExtra("_id", id);
                i.putExtra("top", false);
                i.putExtra("category", Category.INFOXML.ordinal());
                startActivity(i);
                return;
            case LATEST_COMMENTS:
            case LATEST_LIKES:
                String apkid = ((Cursor) parent.getItemAtPosition(position)).getString(1);
                latestClick(apkid);
                return;
            default:
                return;
            }
            addBreadCrumb(((Cursor) parent.getItemAtPosition(position)).getString(1), depth);
            refreshAvailableList(true);
        }
    });
    installedView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long id) {
            Intent i = new Intent(MainActivity.this, ApkInfo.class);
            i.putExtra("_id", id);
            i.putExtra("installed", true);
            i.putExtra("category", Category.INFOXML.ordinal());
            startActivity(i);
        }
    });

    ImageView brandIv = (ImageView) findViewById(R.id.brand);

    if (ApplicationAptoide.APTOIDETHEME.equalsIgnoreCase("jblow")) {
        brandIv.setImageResource(R.drawable.brand_jblow);
    } else if (ApplicationAptoide.APTOIDETHEME.equalsIgnoreCase("magalhaes")) {
        brandIv.setImageResource(R.drawable.brand_magalhaes);
    } else if (ApplicationAptoide.APTOIDETHEME.equalsIgnoreCase("timwe")) {
        brandIv.setImageResource(R.drawable.brand_timwe);
    } else if (ApplicationAptoide.APTOIDETHEME.equalsIgnoreCase("digitallydifferent")) {
        brandIv.setImageResource(R.drawable.brand_digitallydifferent);
    } else if (ApplicationAptoide.APTOIDETHEME.equalsIgnoreCase("eocean")) {
        brandIv.setImageResource(R.drawable.brand_eocean);
    } else if (ApplicationAptoide.APTOIDETHEME.equalsIgnoreCase("educomp")) {
        brandIv.setImageResource(R.drawable.brand_educomp);
    } else if (ApplicationAptoide.APTOIDETHEME.equalsIgnoreCase("peoplenet")) {
        brandIv.setImageResource(R.drawable.brand_peoplenet);
    } else if (ApplicationAptoide.BRAND != null) {
        brandIv.setImageResource(getBrandDrawableResource());
    } else {
        brandIv.setImageResource(R.drawable.brand_aptoide);
    }

    findViewById(R.id.btsearch).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            onSearchRequested();

        }
    });
    updatesListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long id) {
            Intent i = new Intent(MainActivity.this, ApkInfo.class);
            i.putExtra("_id", id);
            i.putExtra("updates", true);
            i.putExtra("category", Category.INFOXML.ordinal());
            startActivity(i);
        }
    });
    // LoaderManager.enableDebugLogging(true);
    availableLoader = getSupportLoaderManager().initLoader(AVAILABLE_LOADER, null, this);

    ArrayList<View> views = new ArrayList<View>();
    views.add(featuredView);
    views.add(availableView);
    views.add(installedView);
    views.add(updateView);

    pager.setAdapter(new ViewPagerAdapter(mContext, views));
    indicator.setViewPager(pager);
    refreshAvailableList(true);

    if (!ApplicationAptoide.MULTIPLESTORES) {
        addBreadCrumb(getString(R.string.store), ListDepth.CATEGORY1);
    } else {
        addBreadCrumb(getString(R.string.stores), ListDepth.STORES);
    }

    if (!ApplicationAptoide.MATURECONTENTSWITCH) {
        featuredView.findViewById(R.id.toggleButton1).setVisibility(View.GONE);
        featuredView.findViewById(R.id.adultcontent_label).setVisibility(View.GONE);
    }

}