Example usage for android.widget ListView setSelection

List of usage examples for android.widget ListView setSelection

Introduction

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

Prototype

@Override
public void setSelection(int position) 

Source Link

Document

Sets the currently selected item.

Usage

From source file:com.tweetlanes.android.core.view.UserFeedFragment.java

@Override
public void onJumpToTop() {
    if (mUserFeedListView != null) {
        ListView listView = mUserFeedListView.getRefreshableView();
        if (listView != null && listView.getAdapter() != null && !listView.getAdapter().isEmpty()) {
            listView.setSelection(0);
        }//from ww w  .  ja  v a2  s .c o  m
    }
}

From source file:com.tweetlanes.android.view.UserFeedFragment.java

@Override

public void onJumpToTop() {
    if (mUserFeedListView != null) {
        ListView listView = mUserFeedListView.getRefreshableView();
        if (listView != null && listView.getAdapter() != null && listView.getAdapter().isEmpty() == false) {
            listView.setSelection(0);
        }/*from ww  w.ja  v  a2 s. c o  m*/
    }
}

From source file:com.shafiq.mytwittle.view.UserFeedFragment.java

@Override
public void onJumpToTop() {
    if (mUserFeedListView != null) {
        ListView listView = mUserFeedListView.getRefreshableView();
        if (listView != null && listView.getAdapter() != null && listView.getAdapter().isEmpty() == false) {
            listView.setSelection(0);
        }// w  w  w .j  a v  a  2  s.  c  o  m
    }
}

From source file:mp.teardrop.LibraryPagerAdapter.java

@Override
public boolean handleMessage(Message message) {
    switch (message.what) {
    case MSG_RUN_QUERY: {
        //we are on the worker thread here
        LibraryAdapter adapter = (LibraryAdapter) message.obj;
        Handler handler = mUiHandler;
        handler.sendMessage(/*www  . ja  v  a  2s  . c  om*/
                handler.obtainMessage(MSG_COMMIT_QUERY, adapter.getMediaType(), 0, adapter.query()));
        break;
    }
    case MSG_COMMIT_QUERY: {
        //we are on the UI thread here
        int index = message.arg1;
        if (index == MediaUtils.TYPE_UNIFIED) {
            //MediaInfoHolder mih = (MediaInfoHolder) message.obj;
            mAdapters[index].commitQuery(message.obj);
            //showInLocalLibrary(mih);
        } else {
            mAdapters[index].commitQuery(message.obj);
            int pos;
            if (mSavedPositions == null) {
                pos = 0;
            } else {
                pos = mSavedPositions[index];
                mSavedPositions[index] = 0;
            }
            ListView listView = (ListView) mContainingLayouts[index].findViewById(R.id.actual_list_view);
            listView.setSelection(pos);
        }
        ((ListView) mContainingLayouts[getCurrentType()].findViewById(R.id.actual_list_view))
                .smoothScrollToPosition(0);
        ;
        break;
    }
    case MSG_SAVE_SORT: {
        MediaAdapter adapter = (MediaAdapter) message.obj;
        SharedPreferences.Editor editor = PlaybackService.getSettings(mActivity).edit();
        editor.putInt(String.format("sort_%d_%d", adapter.getMediaType(), adapter.getLimiterType()),
                adapter.getSortMode());
        editor.commit();
        break;
    }
    case MSG_REQUEST_REQUERY:
        requestRequery((LibraryAdapter) message.obj);
        break;
    default:
        return false;
    }

    return true;
}

From source file:org.melato.bus.android.activity.ScheduleActivity.java

private void setSchedule(ScheduleId scheduleId) {
    if (scheduleId == null) {
        scheduleId = Info.getStickyScheduleId();
    } else {//from   w w w.j  a  v  a2  s  .  c o m
        Info.setStickyScheduleId(scheduleId);
    }
    if (scheduleId != null) {
        daySchedule = schedule.getSchedule(scheduleId);
    } else {
        daySchedule = schedule.getSchedule(currentTime);
        if (daySchedule != null) {
            scheduleId = daySchedule.getScheduleId();
        }
    }
    String scheduleText = getScheduleName();
    IntentHelper helper = new IntentHelper(this);
    String title = helper.getRoute().getFullTitle();
    if (stopName != null) {
        scheduleText += " - " + stopName;
        if (timeOffset > 0) {
            scheduleText += " (+" + Schedule.formatDuration(timeOffset) + ")";
        }
    }
    String comment = schedule.getComment();
    if (comment != null) {
        scheduleText += "\n" + comment;
    }
    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText(scheduleText);
    setTitle(title);
    ListView listView = (ListView) findViewById(R.id.listView);

    if (daySchedule != null) {
        TimeOfDayList times = new TimeOfDayList(daySchedule, currentTime);
        times.setTimeOffset(timeOffset);
        List<RouteException> exceptions = schedule.getExceptions(daySchedule.getScheduleId());
        times.setExceptions(exceptions);
        scheduleAdapter = new ScheduleAdapter(times);
        listView.setAdapter(scheduleAdapter);
        listView.setOnItemClickListener(this);
        int pos = times.getDefaultPosition();
        if (pos >= 0) {
            if (pos > 0)
                pos--;
            listView.setSelection(pos);
        }
    }
}

From source file:hku.fyp14017.blencode.ui.fragment.LookFragment.java

public void updateLookAdapter(LookData lookData) {
    adapter.notifyDataSetChanged();/*  w w  w .jav a2  s  .  c o m*/

    if (lookDataListChangedAfterNewListener != null) {
        lookDataListChangedAfterNewListener.onLookDataListChangedAfterNew(lookData);
    }

    //scroll down the list to the new item:
    final ListView listView = getListView();
    listView.post(new Runnable() {
        @Override
        public void run() {
            listView.setSelection(listView.getCount() - 1);
        }
    });
}

From source file:hku.fyp14017.blencode.ui.fragment.SoundFragment.java

private void updateSoundAdapter(SoundInfo newSoundInfo) {

    if (soundInfoListChangedAfterNewListener != null) {
        soundInfoListChangedAfterNewListener.onSoundInfoListChangedAfterNew(newSoundInfo);
    }//from  ww  w  . j a v a  2  s  .  c o m

    //scroll down the list to the new item:
    final ListView listView = getListView();
    listView.post(new Runnable() {
        @Override
        public void run() {
            listView.setSelection(listView.getCount() - 1);
        }
    });

    if (isResultHandled) {
        isResultHandled = false;

        ScriptActivity scriptActivity = (ScriptActivity) getActivity();
        if (scriptActivity.getIsSoundFragmentFromPlaySoundBrickNew()
                && scriptActivity.getIsSoundFragmentHandleAddButtonHandled()) {
            SoundController.getInstance().switchToScriptFragment(this);
        }
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.FriendsThreadActivity.java

private void scrollToBeAckedPosition(Cursor cursor) {
    ListView lv = getListView();
    int position = (int) mMessageStore.getToAckPosition(mParentMessageKey, mMyEmail);
    if (position == -1)
        lv.setSelection(cursor.getCount() - 1);
    else//  ww w .  j  a v  a  2s.co m
        lv.setSelection(position);
}

From source file:com.meiste.greg.ptw.tab.Schedule.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    setRetainInstance(true);/*from   ww w .ja v  a  2 s  .  c  o m*/
    final View v = inflater.inflate(R.layout.list, container, false);

    mSwipeRefreshWidget = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_widget);
    mSwipeRefreshWidget.setOnRefreshListener(this);
    mSwipeRefreshWidget.setColorSchemeResources(R.color.refresh1, R.color.refresh2, R.color.refresh3,
            R.color.refresh4);
    mSwipeRefreshWidget.setEnabled(BuildConfig.DEBUG);

    final ListView lv = (ListView) v.findViewById(R.id.content);
    mAdapter = new RaceItemAdapter(getActivity(), R.layout.schedule_row);
    lv.setAdapter(mAdapter);

    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(final AdapterView<?> parent, final View v, final int pos, final long id) {
            Util.log("Starting activity for race " + id);

            final Intent intent = new Intent(getActivity(), RaceActivity.class);
            intent.putExtra(RaceActivity.INTENT_ID, (int) id);
            intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
            startActivity(intent);
        }
    });

    if (mNeedScroll) {
        final Race race = Race.getNext(getActivity(), true, true);
        if (race != null) {
            // If possible set previous race so "recent" race is shown (if applicable)
            final int id = race.getId();
            lv.setSelection(id > 0 ? id - 1 : id);
        }
        mNeedScroll = false;
    }

    final IntentFilter filter = new IntentFilter(PTW.INTENT_ACTION_SCHEDULE);
    getActivity().registerReceiver(mScheduleUpdateReceiver, filter);
    return v;
}

From source file:com.android.talkback.controller.CursorControllerAppTest.java

@MediumTest
public void testPrevious_doWrap_doScroll_doUseInputFocus() {
    setContentView(R.layout.cursor_test);

    // Scroll teams list to the last item.
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override//from  w w w .j a v a2 s. co m
        public void run() {
            ListView teamsListView = (ListView) getViewForId(R.id.teams_list);
            teamsListView.setSelection(teamsListView.getCount() - 1);
        }
    });
    getInstrumentation().waitForIdleSync();

    // Put input focus on button AFTER the teams list is done updating.
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            View squareButton = getViewForId(R.id.button_square);
            squareButton.requestFocus();
        }
    });
    getInstrumentation().waitForIdleSync();
    waitForAccessibilityIdleSync();

    AccessibilityNodeInfoCompat teamsList = getNodeForId(R.id.teams_list);
    AccessibilityNodeInfoCompat checkBox = getNodeForId(R.id.check_me);
    AccessibilityNodeInfoCompat firstLabel = getNodeForId(R.id.text_first_item);
    AccessibilityNodeInfoCompat lastLabel = getNodeForId(R.id.text_last_item);

    // This is the expected traversal:
    // (Initial focus) button_square - has input focus
    // 1. text_first_item
    // 2. text_first_item - first previous() pauses on node
    // 3. text_last_item - second previous() wraps around
    // 4-12: teams_list items
    // 13. check_me
    final int traversals = 13;
    List<AccessibilityNodeInfoCompat> nodes = navigate(TraversalStrategy.SEARCH_FOCUS_BACKWARD, traversals,
            true, true, true);

    assertEquals(firstLabel, nodes.get(0));
    assertEquals(firstLabel, nodes.get(1));
    assertEquals(lastLabel, nodes.get(2));
    assertHasParent(teamsList, nodes.subList(3, traversals - 1));
    assertEquals(checkBox, nodes.get(traversals - 1));
}