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:org.alfresco.mobile.android.application.fragments.config.ConfigMenuEditorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    setRootView(inflater.inflate(R.layout.fr_config_menu_editor, container, false));

    account = null;/*from   w w  w .j a  va  2s .  c  om*/
    if (getArguments() != null) {
        accountId = BundleUtils.getLong(getArguments(), ARGUMENT_ACCOUNT_ID);
        if (accountId != null) {
            account = AlfrescoAccountManager.getInstance(getActivity()).retrieveAccount(accountId);
        } else {
            account = getAccount();
            accountId = account.getId();
        }
    }

    listView = (DynamicListView) viewById(R.id.listview);
    configManager = ConfigManager.getInstance(getActivity());
    customConfiguration = ConfigManager.getInstance(getActivity()).getCustomConfig(accountId);

    if (adapter == null) {
        if (customConfiguration != null) {
            updateMenu();
        } else {
            defaultMenuItems = DevConfigModelHelper.createDefaultMenu(getActivity());
        }
        if (defaultMenuItems != null) {
            menuConfigItems = new ArrayList<>(defaultMenuItems.values());
        } else {
            menuConfigItems = new ArrayList<>(0);
        }
    }

    // List Items
    adapter = new ConfigMenuItemAdapter(this, R.layout.row_two_lines, menuConfigItems);
    listView.setItemList(menuConfigItems != null ? menuConfigItems : new ArrayList<ViewConfig>(0));
    listView.setAdapter(adapter);
    listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CreateConfigMenuItemFragment.with(getActivity())
                    .viewConfig((ViewConfigImpl) parent.getItemAtPosition(position)).display();
        }
    });

    // Add Items
    FloatingActionButton button = (FloatingActionButton) viewById(R.id.fab_create_view);
    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CreateConfigMenuItemFragment.with(getActivity()).display();
        }
    });

    FloatingActionButton button2 = (FloatingActionButton) viewById(R.id.fab_create_viewgroup);
    button2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            CreateConfigMenuItemFragment.with(getActivity()).display();
        }
    });

    return getRootView();
}

From source file:org.xbmc.kore.ui.NavigationDrawerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//w  w w. java  2  s.co m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DrawerItem item = (DrawerItem) parent.getItemAtPosition(position);
            selectItem(item, position);
        }
    });

    Resources.Theme theme = getActivity().getTheme();
    TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] { R.attr.iconHosts, R.attr.iconRemote,
            R.attr.iconMovies, R.attr.iconTvShows, R.attr.iconMusic, R.attr.iconPVR, R.attr.iconFiles,
            R.attr.iconAddons, R.attr.iconSettings, });

    HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
    String hostName = (hostInfo != null) ? hostInfo.getName() : getString(R.string.xbmc_media_center);
    int hostId = (hostInfo != null) ? hostInfo.getId() : 0;

    Set<String> shownItems = PreferenceManager.getDefaultSharedPreferences(getActivity()).getStringSet(
            Settings.getNavDrawerItemsPrefKey(hostId),
            new HashSet<>(Arrays.asList(getResources().getStringArray(R.array.entry_values_nav_drawer_items))));

    ArrayList<DrawerItem> items = new ArrayList<>(15);
    items.add(new DrawerItem(DrawerItem.TYPE_HOST, ACTIVITY_HOSTS, hostName,
            styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_HOSTS), 0)));
    items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_REMOTE, getString(R.string.remote),
            styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_REMOTE), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_MOVIES)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_MOVIES, getString(R.string.movies),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_MOVIES), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_TVSHOWS)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_TVSHOWS, getString(R.string.tv_shows),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_TVSHOWS), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_MUSIC)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_MUSIC, getString(R.string.music),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_MUSIC), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_PVR)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_PVR, getString(R.string.pvr),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_PVR), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_FILES)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_FILES, getString(R.string.files),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_FILES), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_ADDONS)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_ADDONS, getString(R.string.addons),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_ADDONS), 0)));
    items.add(new DrawerItem()); // Divider
    items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_SETTINGS, getString(R.string.settings),
            styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_SETTINGS), 0)));

    styledAttributes.recycle();
    mDrawerListView.setAdapter(new DrawerItemAdapter(getActivity(), R.layout.list_item_navigation_drawer,
            items.toArray(new DrawerItem[items.size()])));

    return mDrawerListView;
}

From source file:liqui.droid.activity.LiquiDroid.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    Cursor c = (Cursor) parent.getItemAtPosition(pos);

    String name = c.getString(c.getColumnIndex(DBSystem.Instance.COLUMN_NAME));
    String url = c.getString(c.getColumnIndex(DBSystem.Instance.COLUMN_URL));
    String key = c.getString(c.getColumnIndex(DBSystem.Instance.COLUMN_API_KEY));

    setSettingStringValue("SpinnerLogin", String.valueOf(mSpinnerLQFBs.getSelectedItemPosition()));

    mApiName = name;//from   ww  w  .  java2s  .  co m
    mApiUrl = url;

    mEditTextApiKey.setText(key);

    fillData();

    setActionBarTitle();
}

From source file:com.beesham.popularmovies.DiscoveryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_discovery, container, false);

    mMoviesGridView = (GridView) rootView.findViewById(R.id.movies_gridview);
    mImageAdapter = new ImageAdapter(getContext());

    mMoviesGridView.setEmptyView(rootView.findViewById(R.id.empty_view));

    mMoviesGridView.setAdapter(mImageAdapter);
    mMoviesGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from   w  w w  .j  a  va  2 s  . c  om*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
            String sort_by = prefs.getString(getContext().getString(R.string.pref_sort_key),
                    getContext().getString(R.string.pref_sort_default));

            Cursor c = (Cursor) adapterView.getItemAtPosition(position);

            if (sort_by.equals(getString(R.string.pref_sort_favorite))) {
                if (c != null) {
                    ((DetailsFragment.Callback) getActivity())
                            .onItemSelected(
                                    MoviesContract.MoviesFavoriteEntry.CONTENT_URI.buildUpon()
                                            .appendPath(c.getString(
                                                    c.getColumnIndex(MoviesFavoriteEntry.COLUMN_MOVIE_TITLE)))
                                            .build());
                }
            } else {
                if (c != null) {
                    ((DetailsFragment.Callback) getActivity()).onItemSelected(MoviesEntry.CONTENT_URI
                            .buildUpon()
                            .appendPath(c.getString(c.getColumnIndex(MoviesEntry.COLUMN_MOVIE_TITLE))).build());
                }
            }
            mPosition = position;
        }
    });

    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    return rootView;
}

From source file:com.xengar.android.englishverbs.ui.EditorActivity.java

/**
 * Setup the dropdown spinner that allows the user to select the gender of the verb.
 *///  w  ww.  j  a v  a2  s  .  c o  m
private void setupSpinner() {
    // Create adapter for spinner. The list options are from the String array it will use
    // the spinner will use the default layout
    ArrayAdapter genderSpinnerAdapter = ArrayAdapter.createFromResource(this, R.array.array_gender_options,
            android.R.layout.simple_spinner_item);

    // Specify dropdown layout style - simple list view with 1 item per line
    genderSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);

    // Apply the adapter to the spinner
    mRegularSpinner.setAdapter(genderSpinnerAdapter);

    // Set the integer mSelected to the constant values
    mRegularSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String selection = (String) parent.getItemAtPosition(position);
            if (!TextUtils.isEmpty(selection)) {
                if (selection.equals(getString(R.string.type_regular))) {
                    mRegular = VerbEntry.REGULAR;
                } else {
                    mRegular = VerbEntry.IRREGULAR;
                }
            }
        }

        // Because AdapterView is an abstract class, onNothingSelected must be defined
        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            mRegular = VerbEntry.REGULAR;
        }
    });
}

From source file:com.cssweb.android.base.BaseActivity.java

private void setAdapter(ListView localListView, boolean flag) {
    int len = initBitmap();
    adapter = new MenuAdapter(this, len);
    localListView.setAdapter(adapter);/* w w w.j  a  v  a  2  s  . c  o  m*/

    localListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String menuName = (String) (parent.getItemAtPosition(position));
            MenuUtils.toMenu(BaseActivity.this, menuName);
            openMenu();
        }
    });
}

From source file:com.cssweb.android.base.BaseActivity.java

private void setAdapter(ListView localListView) {
    int len = getCustMenus().length;
    if (Config.mapBitmap != null && Config.mapBitmap.size() > 0) {
    } else {//  ww  w .  j  a v a  2s .  c o  m
        initBitmap();
    }
    adapter = new MenuAdapter(this, len);
    localListView.setAdapter(adapter);

    localListView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String menuName = (String) (parent.getItemAtPosition(position));
            MenuUtils.toMenu(BaseActivity.this, menuName);
            openMenu();
        }
    });
}

From source file:org.solovyev.android.calculator.history.AbstractCalculatorHistoryFragment.java

@Override
public void onViewCreated(View root, Bundle savedInstanceState) {
    super.onViewCreated(root, savedInstanceState);

    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
    final Boolean showDatetime = CalculatorPreferences.History.showDatetime.getPreference(preferences);

    fragmentHelper.onViewCreated(this, root);

    adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(),
            org.solovyev.android.calculator.R.id.history_item, new ArrayList<CalculatorHistoryState>(),
            showDatetime);/*  w w w.j  a v a 2s.c om*/
    setListAdapter(adapter);

    final ListView lv = getListView();
    lv.setTextFilterEnabled(true);

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

            useHistoryItem((CalculatorHistoryState) parent.getItemAtPosition(position));
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, final int position, long id) {
            final CalculatorHistoryState historyState = (CalculatorHistoryState) parent
                    .getItemAtPosition(position);

            final FragmentActivity activity = getActivity();

            final HistoryItemMenuData data = new HistoryItemMenuData(historyState, adapter);

            final List<HistoryItemMenuItem> menuItems = Collections.asList(HistoryItemMenuItem.values());

            if (historyState.isSaved()) {
                menuItems.remove(HistoryItemMenuItem.save);
            } else {
                if (isAlreadySaved(historyState)) {
                    menuItems.remove(HistoryItemMenuItem.save);
                }
                menuItems.remove(HistoryItemMenuItem.remove);
                menuItems.remove(HistoryItemMenuItem.edit);
            }

            if (historyState.getDisplayState().isValid()
                    && Strings.isEmpty(historyState.getDisplayState().getEditorState().getText())) {
                menuItems.remove(HistoryItemMenuItem.copy_result);
            }

            final ContextMenuBuilder<HistoryItemMenuItem, HistoryItemMenuData> menuBuilder = ContextMenuBuilder
                    .newInstance(activity, "history-menu", ListContextMenu.newInstance(menuItems));
            menuBuilder.build(data).show();

            return true;
        }
    });
}

From source file:org.xbmc.kore.ui.generic.NavigationDrawerFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mDrawerListView = (ListView) inflater.inflate(R.layout.fragment_navigation_drawer, container, false);
    mDrawerListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//w  w  w .  j  a  va 2s. c o  m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DrawerItem item = (DrawerItem) parent.getItemAtPosition(position);
            selectItem(item, position);
        }
    });

    Resources.Theme theme = getActivity().getTheme();
    TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] { R.attr.iconHosts, R.attr.iconRemote,
            R.attr.iconMovies, R.attr.iconTvShows, R.attr.iconMusic, R.attr.iconPVR, R.attr.iconFiles,
            R.attr.iconAddons, R.attr.iconSettings, R.attr.iconFavourites });

    HostInfo hostInfo = HostManager.getInstance(getActivity()).getHostInfo();
    String hostName = (hostInfo != null) ? hostInfo.getName() : getString(R.string.xbmc_media_center);
    int hostId = (hostInfo != null) ? hostInfo.getId() : 0;

    Set<String> shownItems = PreferenceManager.getDefaultSharedPreferences(getActivity()).getStringSet(
            Settings.getNavDrawerItemsPrefKey(hostId),
            new HashSet<>(Arrays.asList(getResources().getStringArray(R.array.entry_values_nav_drawer_items))));

    ArrayList<DrawerItem> items = new ArrayList<>(15);
    items.add(new DrawerItem(DrawerItem.TYPE_HOST, ACTIVITY_HOSTS, hostName,
            styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_HOSTS), 0)));
    items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_REMOTE, getString(R.string.remote),
            styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_REMOTE), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_MOVIES)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_MOVIES, getString(R.string.movies),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_MOVIES), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_TVSHOWS)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_TVSHOWS, getString(R.string.tv_shows),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_TVSHOWS), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_MUSIC)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_MUSIC, getString(R.string.music),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_MUSIC), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_PVR)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_PVR, getString(R.string.pvr),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_PVR), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_FAVOURITES)))
        items.add(
                new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_FAVOURITES, getString(R.string.favourites),
                        styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_FAVOURITES), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_FILES)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_FILES, getString(R.string.files),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_FILES), 0)));
    if (shownItems.contains(String.valueOf(ACTIVITY_ADDONS)))
        items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_ADDONS, getString(R.string.addons),
                styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_ADDONS), 0)));
    items.add(new DrawerItem()); // Divider
    items.add(new DrawerItem(DrawerItem.TYPE_NORMAL_ITEM, ACTIVITY_SETTINGS, getString(R.string.settings),
            styledAttributes.getResourceId(styledAttributes.getIndex(ACTIVITY_SETTINGS), 0)));

    styledAttributes.recycle();
    mDrawerListView.setAdapter(new DrawerItemAdapter(getActivity(), R.layout.list_item_navigation_drawer,
            items.toArray(new DrawerItem[items.size()])));

    return mDrawerListView;
}

From source file:com.infigent.stocksense.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    startService(new Intent(this, BackGround.class));
    // setSlidingActionBarEnabled(true);
    Intent n = getIntent();//from   w  w w  .  j ava  2  s  . c om
    if (getIntent() != null) {
        Bundle bundle = n.getExtras();
        if (bundle != null) {
            Log.e("ARG", "EXIST");
            if (bundle.containsKey("eq")) {
                Log.e("EQ", "EXIST");
                if (bundle.getBoolean("eq")) {
                    Log.e("eq", "true");
                    Bundle data = new Bundle();
                    Fragment4 eq = new Fragment4();
                    mContent = eq;
                    data.putString("q", bundle.getString("q"));
                    data.putString("type", bundle.getString("type"));
                    data.putString("name", bundle.getString("name"));
                    data.putString("f", gId());
                    eq.setArguments(data);
                    switchContent(eq);
                }
            }
        }
    }

    if (savedInstanceState != null)
        mContent = getSupportFragmentManager().getFragment(savedInstanceState, "mContent");
    if (mContent == null)
        mContent = new Fragment1();

    ScrollView scrollView = new ScrollView(this);
    LinearLayout l = new LinearLayout(this);
    TextView one = new TextView(this);
    one.setText(getResources().getString(R.string.intro));
    one.setPadding(0, 0, 0, 20);
    TextView two = new TextView(this);
    two.setText("Limited License");
    two.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium);
    TextView three = new TextView(this);
    three.setText(getResources().getString(R.string.l1));
    TextView four = new TextView(this);
    four.setText(getResources().getString(R.string.l2));
    four.setPadding(0, 0, 0, 20);
    TextView five = new TextView(this);
    five.setText("Disclaimer");
    five.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium);
    TextView six = new TextView(this);
    six.setText(getResources().getString(R.string.disclaimer1));
    TextView seven = new TextView(this);
    seven.setText(getResources().getString(R.string.disclaimer2));
    TextView eight = new TextView(this);
    eight.setText(getResources().getString(R.string.disclaimer3));
    eight.setPadding(0, 0, 0, 20);
    TextView nine = new TextView(this);
    nine.setText("Liability For Our Services");
    nine.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium);
    TextView ten = new TextView(this);
    ten.setText(getResources().getString(R.string.liability1));
    TextView eleven = new TextView(this);
    eleven.setText(getResources().getString(R.string.liability2));
    eleven.setPadding(0, 0, 0, 20);
    TextView twelve = new TextView(this);
    twelve.setText("Maintenance And Support");
    twelve.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium);
    TextView thirteen = new TextView(this);
    thirteen.setText(getResources().getString(R.string.ms));
    thirteen.setPadding(0, 0, 0, 20);
    TextView fourteen = new TextView(this);
    fourteen.setText("Links To Third Party Website");
    fourteen.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_DeviceDefault_Medium);
    TextView fifteen = new TextView(this);
    fifteen.setText(getResources().getString(R.string.p3));
    l.addView(one);
    l.addView(two);
    l.addView(three);
    l.addView(four);
    l.addView(five);
    l.addView(six);
    l.addView(seven);
    l.addView(eight);
    l.addView(nine);
    l.addView(ten);
    l.addView(eleven);
    l.addView(twelve);
    l.addView(thirteen);
    l.addView(fourteen);
    l.addView(fifteen);
    one.setTextColor(getResources().getColor(R.color.White));
    two.setTextColor(getResources().getColor(R.color.White));
    three.setTextColor(getResources().getColor(R.color.White));
    four.setTextColor(getResources().getColor(R.color.White));
    five.setTextColor(getResources().getColor(R.color.White));
    six.setTextColor(getResources().getColor(R.color.White));
    seven.setTextColor(getResources().getColor(R.color.White));
    eight.setTextColor(getResources().getColor(R.color.White));
    nine.setTextColor(getResources().getColor(R.color.White));
    ten.setTextColor(getResources().getColor(R.color.White));
    eleven.setTextColor(getResources().getColor(R.color.White));
    twelve.setTextColor(getResources().getColor(R.color.White));
    thirteen.setTextColor(getResources().getColor(R.color.White));
    fourteen.setTextColor(getResources().getColor(R.color.White));
    fifteen.setTextColor(getResources().getColor(R.color.White));
    l.setOrientation(LinearLayout.VERTICAL);
    l.setBackgroundColor(getResources().getColor(R.color.bg));
    l.setPadding(10, 10, 10, 10);
    scrollView.addView(l);
    boolean firstboot = getSharedPreferences("BOOT_PREF", MODE_PRIVATE).getBoolean("firstboot", true);
    if (firstboot) {

        LayoutInflater inflater = getLayoutInflater();
        View vvv = inflater.inflate(R.layout.alerttitle, null);
        AlertDialog.Builder builder = new AlertDialog.Builder(this).setTitle("Terms of Service")
                .setView(scrollView).setCustomTitle(vvv)
                .setPositiveButton(android.R.string.ok, new Dialog.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        dialogInterface.dismiss();

                        getSharedPreferences("BOOT_PREF", MODE_PRIVATE).edit().putBoolean("firstboot", false)
                                .commit();
                    }
                }).setNegativeButton(android.R.string.cancel, new Dialog.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // Close the activity as they have declined the EULA
                        MainActivity.this.finish();
                    }

                }).setCancelable(false);
        builder.create().show();
    }
    ime = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    ActionBar actionBar = getSupportActionBar();
    getSupportActionBar().setCustomView(R.layout.search);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayShowHomeEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);
    sb = (ImageButton) actionBar.getCustomView().findViewById(R.id.sb);
    title = (TextView) actionBar.getCustomView().findViewById(R.id.title);
    sb.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            // only will trigger it if no physical keyboard is open
            search.setVisibility(View.VISIBLE);
            search.requestFocus();
            ime.showSoftInput(search, InputMethodManager.SHOW_IMPLICIT);
            search.setSelection(search.getText().length());
            sb.setVisibility(View.GONE);
            title.setVisibility(View.GONE);

        }
    });

    search = (AutoCompleteTextView) actionBar.getCustomView().findViewById(R.id.et);
    search.setThreshold(2);
    search.setAdapter(new SuggestionsAdapter(this, search.getText().toString()));
    search.setSelectAllOnFocus(true);
    search.clearFocus();

    search.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View arg1, int pos, long id) {
            String term = parent.getItemAtPosition(pos).toString();
            String[] lines = term.split("\\r?\\n");
            String name = lines[0];
            String code = lines[1].substring(lines[1].indexOf(":") + 1, lines[1].length()).trim();
            String type = lines[1].substring(0, lines[1].indexOf(":"));
            Log.d("DATA", name + " " + type + ":" + code);
            search.setText("");
            if (isNetworkAvailable()) {
                if (term.replace(" ", "") != null) {
                    Bundle data = new Bundle();
                    data.putString("q", code);
                    data.putString("type", type);
                    data.putString("name", name);
                    data.putString("f", gId());
                    Fragment4 eq = new Fragment4();
                    eq.setArguments(data);
                    Log.d("C", gId() + " frag");
                    mContent = eq;
                    getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, eq).commit();
                    getSlidingMenu().showContent();
                    search.setVisibility(View.GONE);
                    sb.setVisibility(View.VISIBLE);
                    title.setVisibility(View.VISIBLE);
                    ime.hideSoftInputFromWindow(search.getApplicationWindowToken(), 0);
                } else {
                    Toast.makeText(getApplicationContext(), "Enter a search term!", Toast.LENGTH_LONG).show();
                }
            } else
                Toast.makeText(getApplicationContext(), "Internet not available", Toast.LENGTH_LONG).show();
        }
    });

    search.setOnEditorActionListener(new OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

            return false;
        }
    });

    // set the Above View
    setContentView(R.layout.content_frame);
    getSupportFragmentManager().beginTransaction().replace(R.id.content_frame, mContent).commit();
    AdView mAdView;
    mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);
    // set the Behind View
    setBehindContentView(R.layout.menu_frame);
    getSupportFragmentManager().beginTransaction().replace(R.id.menu_frame, new SampleListFragment()).commit();
}