List of usage examples for android.widget ListView setSelection
@Override public void setSelection(int position)
From source file:com.ternup.caddisfly.fragment.DetailsFragment.java
private void goBack() { FragmentManager fm = getFragmentManager(); try {/*from ww w . ja v a 2s .c o m*/ if (fm.getBackStackEntryCount() > 0) { fm.popBackStack(); fm.executePendingTransactions(); } else { Fragment fragment = new HomeFragment(); FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction ft = fragmentManager.beginTransaction(); ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE); ft.replace(R.id.container, fragment, "0"); ft.addToBackStack(null); ft.commit(); fm.executePendingTransactions(); ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer); drawerList.setItemChecked(0, true); drawerList.setSelection(0); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.ternup.caddisfly.fragment.DetailsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getActivity().setTitle(R.string.details); mContext = getActivity();/* ww w. j a v a 2 s.c om*/ ListView listView = getListView(); mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY); View header = getActivity().getLayoutInflater().inflate(R.layout.fragment_result, null, false); mPpmText = (TextView) header.findViewById(R.id.ppmText); mDateView = (TextView) header.findViewById(R.id.testDate); mTitleView = (TextView) header.findViewById(R.id.titleView); mResultTextView = (TextView) header.findViewById(R.id.result); mAddressText = (TextView) header.findViewById(R.id.address1); mAddress2Text = (TextView) header.findViewById(R.id.address2); mAddress3Text = (TextView) header.findViewById(R.id.address3); mSourceText = (TextView) header.findViewById(R.id.sourceType); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); mFolderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY); mId = getArguments().getLong(getString(R.string.currentTestId)); mLocationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1); File directory = new File(FileUtils.getStoragePath(getActivity(), mLocationId, mFolderName, false)); long locationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1); final ArrayList<String> imagePaths = FileUtils.getFilePaths(getActivity(), mFolderName, "/small/", locationId); if (mId > -1) { if (!directory.exists()) { Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); goBack(); } else if (imagePaths.size() > 0) { displayResult(); } else { FileUtils.deleteFolder(getActivity(), mLocationId, mFolderName); goBack(); } } ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer); drawerList.setItemChecked(-1, true); drawerList.setSelection(-1); assert listView != null; listView.addHeaderView(header); // Gradient shading for title assert header != null; //Collections.sort(imagePaths); GalleryListAdapter adapter = new GalleryListAdapter(getActivity(), mTestTypeId, mId, imagePaths, true); setListAdapter(adapter); Shader textShader = new LinearGradient(0, 0, 0, mTitleView.getPaint().getTextSize(), new int[] { getResources().getColor(R.color.textGradientStart), getResources().getColor(R.color.textGradientEnd) }, new float[] { 0, 1 }, Shader.TileMode.CLAMP); mTitleView.getPaint().setShader(textShader); }
From source file:com.ternup.caddisfly.fragment.ResultFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); getActivity().setTitle(R.string.result); mContext = getActivity();//from w ww . ja va 2 s . c o m mPpmText = (TextView) view.findViewById(R.id.ppmText); mDateView = (TextView) view.findViewById(R.id.testDate); mTitleView = (TextView) view.findViewById(R.id.titleView); mResultTextView = (TextView) view.findViewById(R.id.result); //mResultIcon = (ImageView) view.findViewById(R.id.resultIcon); mAddressText = (TextView) view.findViewById(R.id.address1); mAddress2Text = (TextView) view.findViewById(R.id.address2); mAddress3Text = (TextView) view.findViewById(R.id.address3); mSourceText = (TextView) view.findViewById(R.id.sourceType); ListView drawerList = (ListView) getActivity().findViewById(R.id.navigation_drawer); drawerList.setItemChecked(-1, true); drawerList.setSelection(-1); folderName = getArguments().getString(PreferencesHelper.FOLDER_NAME_KEY); mId = getArguments().getLong(getString(R.string.currentTestId)); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); mLocationId = sharedPreferences.getLong(getString(R.string.currentLocationId), -1); /*Button deleteButton = (Button) view.findViewById(R.id.deleteButton); deleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertUtils.askQuestion(getActivity(), R.string.delete, R.string.areYouSure, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { FileUtils.deleteFolder(getActivity(), mLocationId, folderName); Uri uri = ContentUris .withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); int value = 0; int counter = 0; SharedPreferences.Editor editor = sharedPreferences.edit(); while (value != -1) { value = sharedPreferences .getInt(String.format("result_%d_%d", mId, counter), -1); if (value > -1) { editor.remove(String.format("result_%d_%d", mId, counter)); editor.commit(); counter++; } } goBack(); } }, null ); } }); Button sendButton = (Button) view.findViewById(R.id.sendButton); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (NetworkUtils.checkInternetConnection(mContext)) { if (progressDialog == null) { progressDialog = new ProgressDialog(getActivity()); progressDialog.setMessage("Sending..."); progressDialog.setCancelable(false); } progressDialog.show(); postResult("testresults"); } } }); */ ArrayList<String> filePaths = FileUtils.getFilePaths(getActivity(), folderName, mLocationId); File directory = new File(FileUtils.getStoragePath(getActivity(), mLocationId, folderName, false)); if (!directory.exists()) { Uri uri = ContentUris.withAppendedId(TestContentProvider.CONTENT_URI, mId); mContext.getContentResolver().delete(uri, null, null); goBack(); } else if (filePaths.size() > 0) { displayResult(); } else { FileUtils.deleteFolder(getActivity(), mLocationId, folderName); } }
From source file:de.hshannover.f4.trust.ironcontrol.view.list_activities.ListSavedConnectionsActivity.java
@Override protected void onListItemClick(ListView l, View v, int position, long id) { super.onListItemClick(l, v, position, id); // reset old view if (selectedView != null) { selectedView.setBackgroundColor(0); }/* w w w . j a v a 2s . c o m*/ // set color v.setBackgroundColor(colorSteelBlue); // jump to select l.setSelection(position); selectedView = v; selectedId = id; }
From source file:org.pencilsofpromise.rss.RSSFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.rss_fragment, container, false); // feed=getFeed(RSSFEEDOFCHOICE); if (InternetState) { DownloadFeedTask task = new DownloadFeedTask(); task.execute(null, null, null);/*from w w w . ja v a 2 s . c om*/ } try { TextView title = (TextView) v.findViewById(R.id.title); TextView pubdate = (TextView) v.findViewById(R.id.pub_date); TextView description = (TextView) v.findViewById(R.id.description); String[] uiBindFrom = { RSSnote.RSS_tab.COL_TITLE, RSSnote.RSS_tab.COL_DESCRIPTION, RSSnote.RSS_tab.COL_PUB_DATE, RSSnote.RSS_tab.COL_IMAGE }; int[] uiBindTo = { R.id.title, R.id.description, R.id.pub_date, R.id.imageview0 }; getLoaderManager().initLoader(RSS_LIST_LOADER, null, this); ListView itemlist = (ListView) v.findViewById(android.R.id.list); adapter = new SimpleCursorAdapter(getActivity().getApplicationContext(), R.layout.list_xml, null, uiBindFrom, uiBindTo, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER); adapter.setViewBinder(new ProductViewBinder()); itemlist.setAdapter(adapter); itemlist.setOnItemClickListener(this); itemlist.setSelection(0); } catch (Exception e) { Toast.makeText(getActivity().getApplicationContext(), "No internet, first time load", Toast.LENGTH_LONG) .show(); } return v; }
From source file:com.digium.respoke.ChatActivity.java
public void onMessage(String message, RespokeDirectConnection sender) { conversation.addMessage(message, remoteEndpoint.getEndpointID(), true); // Tell the ListView to reconfigure itself based on the new data listAdapter.notifyDataSetChanged();/* w w w. java 2 s . c o m*/ listAdapter.notifyDataSetInvalidated(); final ListView lv = (ListView) findViewById(R.id.list); //retrieve the instance of the ListView from your main layout lv.post(new Runnable() { @Override public void run() { // Select the last row so it will scroll into view... lv.setSelection(listAdapter.getCount() - 1); } }); }
From source file:com.shafiq.mytwittle.view.DirectMessageFeedFragment.java
@Override public void onJumpToTop() { if (mConversationListView != null) { ListView listView = mConversationListView.getRefreshableView(); if (listView != null && listView.getAdapter() != null && listView.getAdapter().isEmpty() == false) { listView.setSelection(0); }/* ww w . j av a2s . c om*/ } }
From source file:com.digium.respoke.ChatActivity.java
private void sendChatMessage() { EditText chatText = (EditText) findViewById(R.id.chatText); String message = chatText.getText().toString(); if (message.length() > 0) { chatText.setText(""); conversation.addMessage(message, ContactManager.sharedInstance().username, directConnection != null); // Tell the ListView to reconfigure itself based on the new data listAdapter.notifyDataSetChanged(); listAdapter.notifyDataSetInvalidated(); final ListView lv = (ListView) findViewById(R.id.list); //retrieve the instance of the ListView from your main layout lv.post(new Runnable() { @Override/*from w ww . j a va2 s .c om*/ public void run() { // Select the last row so it will scroll into view... lv.setSelection(listAdapter.getCount() - 1); } }); if (null != directConnection) { directConnection.sendMessage(message, new Respoke.TaskCompletionListener() { @Override public void onSuccess() { Log.d(TAG, "direct message sent"); } @Override public void onError(String errorMessage) { Log.d(TAG, "Error sending direct message! " + errorMessage); } }); } else { remoteEndpoint.sendMessage(message, false, true, new Respoke.TaskCompletionListener() { @Override public void onSuccess() { Log.d(TAG, "message sent"); } @Override public void onError(String errorMessage) { Log.d(TAG, "Error sending message! " + errorMessage); } }); } } }
From source file:com.android.deskclock.RingtonePickerDialogFragment.java
@Override public void onLoadFinished(Loader<RingtoneManager> loader, RingtoneManager ringtoneManager) { // Swap in the new ringtone manager. mRingtoneAdapter.setRingtoneManager(ringtoneManager); // Preserve the selected ringtone. final ListView listView = mDialog.getListView(); final int checkedPosition = mRingtoneAdapter.getRingtonePosition(mSelectedRingtoneUri); if (checkedPosition != ListView.INVALID_POSITION) { listView.setItemChecked(checkedPosition, true); // Also scroll the list to the selected ringtone (this method is poorly named). listView.setSelection(checkedPosition); } else {/*from ww w. ja va 2 s . c o m*/ // Can't find the selected ringtone, clear the current selection. mSelectedRingtoneUri = null; listView.clearChoices(); } // Enable the positive button if we have a valid selection (Note: the positive button may // be null if this callback returns before onStart). final View positiveButton = mDialog.getButton(DialogInterface.BUTTON_POSITIVE); if (positiveButton != null) { positiveButton.setEnabled(mSelectedRingtoneUri != null); } // On M devices the checked view's drawable state isn't updated properly when it is first // bound, so we must use a blunt approach to force it to refresh correctly. if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { listView.post(new Runnable() { @Override public void run() { for (int i = listView.getChildCount() - 1; i >= 0; --i) { listView.getChildAt(i).refreshDrawableState(); } } }); } }
From source file:com.audiokernel.euphonyrmt.fragments.QueueFragment.java
public void scrollToNowPlaying() { final int songPos = mApp.oMPDAsyncHelper.oMPD.getStatus().getSongPos(); if (songPos == -1) { Log.d(TAG, "Missing list item."); } else {/* w w w .j a v a 2s . c o m*/ if (mActivity instanceof MainMenuActivity) { ((MainMenuActivity) mActivity).showQueue(); } final ListView listView = getListView(); listView.requestFocusFromTouch(); listView.setSelection(songPos); listView.clearFocus(); } }