Example usage for android.support.v4.view ViewPager setCurrentItem

List of usage examples for android.support.v4.view ViewPager setCurrentItem

Introduction

In this page you can find the example usage for android.support.v4.view ViewPager setCurrentItem.

Prototype

public void setCurrentItem(int item) 

Source Link

Document

Set the currently selected page.

Usage

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

@SuppressLint("DefaultLocale")
@Override//from   w  w  w. ja  v  a2 s . co  m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    m_uncaughtExceptionHandler = new UncaughtExceptionHandler();
    boolean DEBUG = (getApplicationInfo().flags & 2) != 0;
    AppCrash.initalize(getApplication(), DEBUG);

    GlobalInfo.s_globalInfo.mainFragActivity = this;
    try {
        GlobalInfo.s_globalInfo.isDebug = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE));
        GlobalInfo.s_globalInfo.pkgName = getPackageName();
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        GlobalInfo.s_globalInfo.version = pInfo.versionName;
        // GlobalInfo.s_globalInfo.appName = pInfo.applicationInfo.name;
    } catch (Exception ex) {
        GlobalInfo.s_globalInfo.version = "1.3";
    }

    /*
    // See build.gradle to add
    // debugCompile "com.squareup.leakcanary:leakcanary-android:${leakCanaryVersion}"
    if (GlobalInfo.s_globalInfo.isDebug) {
    LeakCanary.install(this.getApplication());
    }
    */

    JodaTimeAndroid.init(this); // Load TimeZone database.
    GoogleAnalyticsHelper.init(this);
    // Obtain the FirebaseAnalytics instance.
    mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
    Utils.onActivityCreateSetTheme(this);

    setContentView(R.layout.main);
    setTitle(String.format("%s v%s API=%d", GlobalInfo.s_globalInfo.appName, GlobalInfo.s_globalInfo.version,
            Build.VERSION.SDK_INT));
    // setTitle(GlobalInfo.s_globalInfo.appName + " v" + BuildConfig.VERSION_NAME + " API" + Build.VERSION.SDK_INT +  (BuildConfig.DEBUG ? " Debug" : ""));

    // Initialization
    ViewPager viewPager = Ui.viewById(this, R.id.pager);
    GlobalInfo.s_globalInfo.tabAdapter = new TabPagerAdapter(getSupportFragmentManager(), viewPager,
            getActionBar());

    GlobalInfo.grabThemeSetings(this);

    GoogleAnalyticsHelper.event(this, this.getLocalClassName(), "create", "");

    Intent intent = this.getIntent();
    if (intent != null) {
        String startupFrag = intent.getStringExtra(GlobalInfo.STARTUP_FRAG);
        if (!TextUtils.isEmpty(startupFrag)) {
            m_startFrag = startupFrag;
        }
    }

    if (!TextUtils.isEmpty(m_startFrag)) {
        viewPager.setCurrentItem(GlobalInfo.s_globalInfo.tabAdapter.findFragPos(m_startFrag, 0));
    }
}

From source file:org.matrix.console.activity.ImageSliderActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {

    if (CommonActivityUtils.shouldRestartApp()) {
        CommonActivityUtils.restartApp(this);
    }/*from w w  w . j  ava 2  s  .  c  o  m*/

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_images_slider);

    ViewPager viewPager = (ViewPager) findViewById(R.id.view_pager);

    final Intent intent = getIntent();

    List<SlidableImageInfo> listImageMessages = (List<SlidableImageInfo>) intent
            .getSerializableExtra(KEY_INFO_LIST);
    int position = intent.getIntExtra(KEY_INFO_LIST_INDEX, 0);
    int maxImageWidth = intent.getIntExtra(KEY_THUMBNAIL_WIDTH, 0);
    int maxImageHeight = intent.getIntExtra(ImageSliderActivity.KEY_THUMBNAIL_HEIGHT, 0);

    MXSession session = getSession(intent);
    HomeserverConnectionConfig hsConfig = session != null ? session.getHomeserverConfig() : null;

    ImagesSliderAdapter adapter = new ImagesSliderAdapter(this, hsConfig, listImageMessages, maxImageWidth,
            maxImageHeight);
    viewPager.setAdapter(adapter);
    viewPager.setCurrentItem(position);
    viewPager.setPageTransformer(true, new DepthPageTransformer());
}

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

/**
 * Called when the activity is first created.
 * //from   w w w  .  j a v  a  2 s .c  om
 * @param savedInstanceState the saved instance state
 */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mBundle = getIntent().getExtras().getBundle(Constants.DATA_BUNDLE);
    mInitiativeId = String.valueOf(mBundle.getInt("_id"));

    setContentView(R.layout.act_ini);
    setUpActionBar();
    setBreadCrumbs();

    mContentUri = dbUri("content://liqui.droid.db/issues_pure");

    ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
    mAdapter = new InitiativePagerAdapter(this, mContentUri);
    vp.setAdapter(mAdapter);

    mInitiativeOnPageChangeListener = new InitiativeOnPageChangeListener();
    vp.setOnPageChangeListener(mInitiativeOnPageChangeListener);

    TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
    titleIndicator.setViewPager(vp);
    titleIndicator.setOnPageChangeListener(mInitiativeOnPageChangeListener);

    if (mInitiativeId != null && mInitiativeId.length() > 0) {
        int item = mAdapter.indexOf(Integer.parseInt(mInitiativeId));
        vp.setCurrentItem(item);
    }
}

From source file:com.bt.heliniumstudentapp.DayActivity.java

@SuppressWarnings("ConstantConditions")
@Override// ww w  .j av  a2  s  . c  o  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_day);

    final Toolbar toolbarTB = (Toolbar) findViewById(R.id.tb_toolbar_ad);
    setSupportActionBar(toolbarTB);
    toolbarTB.setBackgroundResource(MainActivity.primaryColor);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    toolbarTB.getNavigationIcon().setColorFilter(ContextCompat.getColor(this, MainActivity.primaryTextColor),
            PorterDuff.Mode.SRC_ATOP);

    getWindow().getDecorView().setBackgroundResource(MainActivity.themeColor);

    MainActivity.setStatusBar(this);

    ViewPager daysVP = (ViewPager) findViewById(R.id.vp_days_ad);

    Bundle bundle = getIntent().getExtras();
    schedule = (ScheduleFragment.week) bundle.getSerializable("schedule");
    lastPosition = (Integer) bundle.get("pos");

    daysVP.setAdapter(new DaysAdapter(this, getSupportFragmentManager()));
    daysVP.setOffscreenPageLimit(1);
    daysVP.setCurrentItem(lastPosition);

    compactView = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_customization_compact",
            false);

    MainActivity.setToolbarTitle(this, schedule.day_get(schedule.day_get_index(lastPosition) + 2).day,
            schedule.day_get(schedule.day_get_index(lastPosition) + 2).date);

    daysVP.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int position) {
            MainActivity.setToolbarTitle(DayActivity.this,
                    schedule.day_get(schedule.day_get_index(position) + 2).day,
                    schedule.day_get(schedule.day_get_index(position) + 2).date);

            hw_floating = (schedule.day_get(schedule.day_get_index(position) + 2).floatings_get() != 0);
            invalidateOptionsMenu();

            lastPosition = position;
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }
    });
}

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

/**
 * Called when the activity is first created.
 * /*  w w  w  . ja va2s.  co  m*/
 * @param bundle the saved instance state
 */
@Override
public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    setContentView(R.layout.act_member_details);
    setUpActionBar();
    setBreadCrumbs();

    CONTENT_URI = dbUri(DBProvider.MEMBER_CONTENT_URI);

    Bundle extras = getIntent().getExtras();

    // Check from the saved Instance
    mUri = (bundle == null) ? null : (Uri) bundle.getParcelable(DBProvider.MEMBER_CONTENT_ITEM_TYPE);

    // Or passed from the other activity
    if (extras != null) {
        mUri = extras.getParcelable(DBProvider.MEMBER_CONTENT_ITEM_TYPE);

        mSortOrder = extras.getString("sortOrder");
        mSortDir = extras.getString("sortDir");
        mFilter = extras.getString("filter");
    }

    mMemberDetailId = mUri.getLastPathSegment();

    ViewPager vp = (ViewPager) findViewById(R.id.viewpager);
    mAdapter = new MemberDetailsPagerAdapter(this, CONTENT_URI);
    vp.setAdapter(mAdapter);

    mDetailOnPageChangeListener = new DetailOnPageChangeListener();
    vp.setOnPageChangeListener(mDetailOnPageChangeListener);

    if (mMemberDetailId != null && mMemberDetailId.length() > 0) {
        int item = mAdapter.indexOf(Integer.parseInt(mMemberDetailId));
        vp.setCurrentItem(item);
    }

    Log.d("XXXXXX", "mMemberDetailId " + mMemberDetailId);
    Log.d("XXXXXX", "getMemberId() " + getMemberId());
}

From source file:com.google.devrel.vrviewapp.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w  ww. j a  va 2s.c  o  m*/

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    assert tabLayout != null;
    tabLayout.addTab(tabLayout.newTab().setText(R.string.welcome));
    tabLayout.addTab(tabLayout.newTab().setText(R.string.venue));
    tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

    final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
    final PagerAdapter adapter = new FragmentStatePagerAdapter(getSupportFragmentManager()) {

        @Override
        public Fragment getItem(int position) {
            switch (position) {
            case 0:
                return new WelcomeFragment();
            case 1:
                return new GorillaFragment();
            }
            return null;
        }

        @Override
        public int getCount() {
            return 2;
        }
    };
    assert viewPager != null;
    viewPager.setAdapter(adapter);
    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            viewPager.setCurrentItem(tab.getPosition());
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {

        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {

        }
    });
}

From source file:com.battlelancer.seriesguide.ui.AddActivity.java

private void setupViews() {
    AddPagerAdapter adapter = new AddPagerAdapter(getSupportFragmentManager(), this);

    ViewPager pager = (ViewPager) findViewById(R.id.pagerAddShows);
    pager.setAdapter(adapter);/*from   w ww  . j a v  a2 s  . c o  m*/

    SlidingTabLayout tabs = (SlidingTabLayout) findViewById(R.id.tabsAddShows);
    tabs.setCustomTabView(R.layout.tabstrip_item_allcaps, R.id.textViewTabStripItem);
    tabs.setSelectedIndicatorColors(
            getResources().getColor(Utils.resolveAttributeToResourceId(getTheme(), R.attr.colorAccent)));
    tabs.setBottomBorderColor(getResources()
            .getColor(Utils.resolveAttributeToResourceId(getTheme(), R.attr.sgColorTabStripUnderline)));
    tabs.setViewPager(pager);

    // set default tab
    if (getIntent() != null && getIntent().getExtras() != null) {
        int defaultTab = getIntent().getExtras().getInt(InitBundle.DEFAULT_TAB);
        if (defaultTab < adapter.getCount()) {
            pager.setCurrentItem(defaultTab);
        }
    }
}

From source file:com.tapchatapp.android.app.fragment.MainFragment.java

@Subscribe
public void onServiceStateChanged(ServiceStateChangedEvent event) {
    mTabsAdapter.notifyDataSetChanged();

    final TitlePageIndicator tabs = (TitlePageIndicator) getView().findViewById(R.id.pager_tabs);
    tabs.notifyDataSetChanged();/*from ww  w  .j a v  a  2  s.c  o m*/

    final ViewPager viewPager = (ViewPager) getView().findViewById(R.id.pager);

    View view = getView();
    if (view != null) {
        boolean showNoConnections = (mTabsAdapter.isLoaded() && mTabsAdapter.getCount() == 0);
        boolean showPager = mTabsAdapter.getCount() > 0;
        view.findViewById(R.id.no_connections).setVisibility(showNoConnections ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.pager).setVisibility(showPager ? View.VISIBLE : View.GONE);
        view.findViewById(R.id.pager_tabs).setVisibility(showPager ? View.VISIBLE : View.GONE);
    }

    Activity activity = getActivity();
    if (activity != null) {
        activity.invalidateOptionsMenu();
    }

    // FIXME: Fix ViewPager to do this properly above.
    if (mPendingSelectItem >= 0 && mTabsAdapter.getCount() > mPendingSelectItem) {
        viewPager.setCurrentItem(mPendingSelectItem);
        mPendingSelectItem = -1;
    }
}

From source file:com.battlelancer.seriesguide.ui.OverviewActivity.java

private void setupViewPager(View pagerView) {
    ViewPager pager = (ViewPager) pagerView;

    // setup tab strip
    TabStripAdapter tabsAdapter = new TabStripAdapter(getSupportFragmentManager(), this, pager,
            (SlidingTabLayout) findViewById(R.id.tabsOverview));
    Bundle argsShow = new Bundle();
    argsShow.putInt(ShowFragment.InitBundle.SHOW_TVDBID, mShowId);
    tabsAdapter.addTab(R.string.show, ShowFragment.class, argsShow);

    tabsAdapter.addTab(R.string.description_overview, OverviewFragment.class, getIntent().getExtras());

    Bundle argsSeason = new Bundle();
    argsSeason.putInt(SeasonsFragment.InitBundle.SHOW_TVDBID, mShowId);
    tabsAdapter.addTab(R.string.seasons, SeasonsFragment.class, argsSeason);
    tabsAdapter.notifyTabsChanged();//from   w w  w  .ja  v a  2s  .c o  m

    // select overview to be shown initially
    pager.setCurrentItem(1);
}

From source file:de.baumann.hhsmoodle.data_bookmarks.Bookmarks_Fragment.java

public void setBookmarksList() {

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "bookmarks_title", "bookmarks_content", "bookmarks_creation" };
    final Cursor row = db.fetchAllData(getActivity());
    adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override/*  w w  w. j a v a 2 s . c  om*/
        public View getView(final int position, View convertView, ViewGroup parent) {

            Cursor row = (Cursor) lv.getItemAtPosition(position);
            final String _id = row.getString(row.getColumnIndexOrThrow("_id"));
            final String bookmarks_title = row.getString(row.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row.getString(row.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row.getString(row.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row
                    .getString(row.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row.getString(row.getColumnIndexOrThrow("bookmarks_creation"));

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            final ImageView iv_attachment = (ImageView) v.findViewById(R.id.att_notes);

            switch (bookmarks_icon) {
            case "01":
                iv_icon.setImageResource(R.drawable.circle_red);
                break;
            case "02":
                iv_icon.setImageResource(R.drawable.circle_yellow);
                break;
            case "03":
                iv_icon.setImageResource(R.drawable.circle_green);
                break;
            case "04":
                iv_icon.setImageResource(R.drawable.ic_school_grey600_48dp);
                break;
            case "05":
                iv_icon.setImageResource(R.drawable.ic_view_dashboard_grey600_48dp);
                break;
            case "06":
                iv_icon.setImageResource(R.drawable.ic_face_profile_grey600_48dp);
                break;
            case "07":
                iv_icon.setImageResource(R.drawable.ic_calendar_grey600_48dp);
                break;
            case "08":
                iv_icon.setImageResource(R.drawable.ic_chart_areaspline_grey600_48dp);
                break;
            case "09":
                iv_icon.setImageResource(R.drawable.ic_bell_grey600_48dp);
                break;
            case "10":
                iv_icon.setImageResource(R.drawable.ic_settings_grey600_48dp);
                break;
            case "11":
                iv_icon.setImageResource(R.drawable.ic_web_grey600_48dp);
                break;
            case "12":
                iv_icon.setImageResource(R.drawable.ic_magnify_grey600_48dp);
                break;
            case "13":
                iv_icon.setImageResource(R.drawable.ic_pencil_grey600_48dp);
                break;
            case "14":
                iv_icon.setImageResource(R.drawable.ic_check_grey600_48dp);
                break;
            case "15":
                iv_icon.setImageResource(R.drawable.ic_clock_grey600_48dp);
                break;
            case "16":
                iv_icon.setImageResource(R.drawable.ic_bookmark_grey600_48dp);
                break;
            }

            switch (bookmarks_attachment) {
            case "":
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_outline);
                break;
            default:
                iv_attachment.setVisibility(View.VISIBLE);
                iv_attachment.setImageResource(R.drawable.star_grey);
                break;
            }

            iv_attachment.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    if (bookmarks_attachment.equals("")) {

                        if (db.isExistFav("true")) {
                            Snackbar.make(lv, R.string.bookmark_setFav_not, Snackbar.LENGTH_LONG).show();
                        } else {
                            iv_attachment.setImageResource(R.drawable.star_grey);
                            db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon,
                                    "true", bookmarks_creation);
                            setBookmarksList();
                            sharedPref.edit().putString("favoriteURL", bookmarks_content)
                                    .putString("favoriteTitle", bookmarks_title).apply();
                            Snackbar.make(lv, R.string.bookmark_setFav, Snackbar.LENGTH_LONG).show();
                        }
                    } else {
                        iv_attachment.setImageResource(R.drawable.star_outline);
                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content, bookmarks_icon, "",
                                bookmarks_creation);
                        setBookmarksList();
                    }
                }
            });

            iv_icon.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    final helper_main.Item[] items = {
                            new helper_main.Item(getString(R.string.note_priority_2), R.drawable.circle_red),
                            new helper_main.Item(getString(R.string.note_priority_1), R.drawable.circle_yellow),
                            new helper_main.Item(getString(R.string.note_priority_0), R.drawable.circle_green),
                            new helper_main.Item(getString(R.string.text_tit_11),
                                    R.drawable.ic_school_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_1),
                                    R.drawable.ic_view_dashboard_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_2),
                                    R.drawable.ic_face_profile_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_8),
                                    R.drawable.ic_calendar_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_3),
                                    R.drawable.ic_chart_areaspline_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_4),
                                    R.drawable.ic_bell_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_5),
                                    R.drawable.ic_settings_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_6),
                                    R.drawable.ic_web_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_7),
                                    R.drawable.ic_magnify_grey600_48dp),
                            new helper_main.Item(getString(R.string.title_notes),
                                    R.drawable.ic_pencil_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_9),
                                    R.drawable.ic_check_grey600_48dp),
                            new helper_main.Item(getString(R.string.text_tit_10),
                                    R.drawable.ic_clock_grey600_48dp),
                            new helper_main.Item(getString(R.string.title_bookmarks),
                                    R.drawable.ic_bookmark_grey600_48dp), };

                    ListAdapter adapter = new ArrayAdapter<helper_main.Item>(getActivity(),
                            android.R.layout.select_dialog_item, android.R.id.text1, items) {
                        @NonNull
                        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
                            //Use super class to create the View
                            View v = super.getView(position, convertView, parent);
                            TextView tv = (TextView) v.findViewById(android.R.id.text1);
                            tv.setTextSize(18);
                            tv.setCompoundDrawablesWithIntrinsicBounds(items[position].icon, 0, 0, 0);
                            //Add margin between image and text (support various screen densities)
                            int dp5 = (int) (24 * getResources().getDisplayMetrics().density + 0.5f);
                            tv.setCompoundDrawablePadding(dp5);

                            return v;
                        }
                    };

                    new AlertDialog.Builder(getActivity())
                            .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int whichButton) {
                                    dialog.cancel();
                                }
                            }).setAdapter(adapter, new DialogInterface.OnClickListener() {

                                public void onClick(DialogInterface dialog, int item) {
                                    if (item == 0) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "01", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 1) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "02", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 2) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "03", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 3) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "04", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 4) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "05", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 5) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "06", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 6) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "07", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 7) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "08", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 8) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "09", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 9) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "10", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 10) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "11", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 11) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "12", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 12) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "13", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 13) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "14", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 14) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "15", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    } else if (item == 15) {
                                        db.update(Integer.parseInt(_id), bookmarks_title, bookmarks_content,
                                                "16", bookmarks_attachment, bookmarks_creation);
                                        setBookmarksList();
                                    }
                                }
                            }).show();
                }
            });
            return v;
        }
    };

    //display data by filter
    final String note_search = sharedPref.getString("filter_bookmarksBY", "bookmarks_title");
    sharedPref.edit().putString("filter_bookmarksBY", "bookmarks_title").apply();
    filter.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }

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

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            sharedPref.edit().putString("load_next", "true").apply();
            sharedPref.edit().putString("loadURL", bookmarks_content).apply();

            ViewPager viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
            viewPager.setCurrentItem(0);

        }
    });

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

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String bookmarks_title = row2.getString(row2.getColumnIndexOrThrow("bookmarks_title"));
            final String bookmarks_content = row2.getString(row2.getColumnIndexOrThrow("bookmarks_content"));
            final String bookmarks_icon = row2.getString(row2.getColumnIndexOrThrow("bookmarks_icon"));
            final String bookmarks_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("bookmarks_attachment"));
            final String bookmarks_creation = row2.getString(row2.getColumnIndexOrThrow("bookmarks_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark), getString(R.string.todo_menu),
                    getString(R.string.bookmark_createNote), getString(R.string.count_create),
                    getString(R.string.bookmark_createShortcut), getString(R.string.bookmark_createEvent) };
            new AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @SuppressWarnings("ConstantConditions")
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_title, null);

                                final EditText edit_title = (EditText) dialogView.findViewById(R.id.pass_title);
                                edit_title.setHint(R.string.bookmark_edit_title);
                                edit_title.setText(bookmarks_title);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.bookmark_edit_title);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTag = edit_title.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTag, bookmarks_content,
                                                        bookmarks_icon, bookmarks_attachment,
                                                        bookmarks_creation);
                                                setBookmarksList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.todo_menu))) {
                                Todo_helper.newTodo(getActivity(), bookmarks_title, "", "");
                            }

                            if (options[item].equals(getString(R.string.count_create))) {
                                Count_helper.newCount(getActivity(), bookmarks_title, bookmarks_content,
                                        getActivity().getString(R.string.note_content), false);
                            }

                            if (options[item].equals(getString(R.string.bookmark_createEvent))) {
                                helper_main.createCalendarEvent(getActivity(), bookmarks_title,
                                        bookmarks_content);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setBookmarksList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.bookmark_createNote))) {
                                Notes_helper.newNote(getActivity(), bookmarks_title, bookmarks_content, "", "",
                                        "", "");
                            }

                            if (options[item].equals(getString(R.string.bookmark_createShortcut))) {
                                Intent i = new Intent();
                                i.setAction(Intent.ACTION_VIEW);
                                i.setData(Uri.parse(bookmarks_content));

                                Intent shortcut = new Intent();
                                shortcut.putExtra("android.intent.extra.shortcut.INTENT", i);
                                shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                        "THE NAME OF SHORTCUT TO BE SHOWN");
                                shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, bookmarks_title);
                                shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                        Intent.ShortcutIconResource.fromContext(
                                                getActivity().getApplicationContext(), R.mipmap.ic_launcher));
                                shortcut.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
                                getActivity().sendBroadcast(shortcut);
                                Snackbar.make(lv, R.string.toast_shortcut, Snackbar.LENGTH_LONG).show();
                            }

                        }
                    }).show();

            return true;
        }
    });
}