Example usage for android.widget ListView smoothScrollToPosition

List of usage examples for android.widget ListView smoothScrollToPosition

Introduction

In this page you can find the example usage for android.widget ListView smoothScrollToPosition.

Prototype

@android.view.RemotableViewMethod
public void smoothScrollToPosition(int position) 

Source Link

Document

Smoothly scroll to the specified adapter position.

Usage

From source file:com.cachirulop.moneybox.activity.MainActivity.java

/**
 * Create left navigation drawer with the list of created moneyboxes.
 *///w  ww .ja  v  a  2s .  c  o m
private void createDrawer() {
    final ListView drawerList;

    _drawerAdapter = new MoneyboxAdapter(this);
    _drawerAdapter.setOnRowClickListener(new MoneyboxAdapter.OnRowClickListener() {
        public void onClick(int position) {
            selectMoneybox((Moneybox) _drawerAdapter.getItem(position));
        }
    });

    // _drawerAdapter.setCurrentMoneyboxId (Preferences.getLastMoneyboxId
    // (this));
    getActionBar().setTitle(_drawerAdapter.getCurrentItem().getDescription());

    drawerList = (ListView) findViewById(R.id.lvMoneyboxes);
    drawerList.setAdapter(_drawerAdapter);

    _drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    _drawerToggle = new ActionBarDrawerToggle(this, _drawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {
        /** Called when a drawer has settled in a completely closed state. */
        public void onDrawerClosed(View view) {
            setTotalVisibility(true);
            getActionBar().setTitle(_drawerAdapter.getCurrentItem().getDescription());
            invalidateOptionsMenu();
        }

        /** Called when a drawer has settled in a completely open state. */
        public void onDrawerOpened(View drawerView) {
            setTotalVisibility(false);
            getActionBar().setTitle(getString(R.string.moneybox_select_moneybox));

            updateMoneyboxesTotal();
            drawerList.smoothScrollToPosition(_drawerAdapter.getPosition());

            invalidateOptionsMenu();
        }
    };

    // Set the drawer toggle as the DrawerListener
    _drawerLayout.setDrawerListener(_drawerToggle);
}

From source file:org.thoughtland.xlocation.ActivityShare.java

public void setState(int uid, int state, String message) {
    final AppState app = mAppsByUid.get(uid);
    app.message = message;//from  w ww  .j  a  va2 s  .c  o m
    app.state = state;
    runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (mAppAdapter != null) {
                mAppAdapter.notifyDataSetChanged();

                int position = mAppAdapter.getPosition(app);
                if (position >= 0) {
                    ListView lvShare = (ListView) findViewById(R.id.lvShare);
                    lvShare.smoothScrollToPosition(position);
                }
            }
        }
    });
}