List of usage examples for android.widget AdapterView getItemAtPosition
public Object getItemAtPosition(int position)
From source file:com.example.owen.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override// ww w. j a va 2s. co m public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { String locationSetting = Utility.getPreferredLocation(getActivity()); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }
From source file:com.docd.purefm.ui.activities.SearchActivity.java
private void initList() { if (mList != null) { final View emptyView = mList.getEmptyView(); if (emptyView != null) { emptyView.setVisibility(View.GONE); }/*from w w w .java2 s . c o m*/ mList.setVisibility(View.GONE); } final ViewGroup listContainer = (ViewGroup) findViewById(R.id.list_container); if (listContainer == null) { throw new RuntimeException("parent should contain ViewGroup with id R.id.list_container"); } final Settings settings = getSettings(); final View swipeRefreshList; switch (settings.getListAppearance()) { case LIST: swipeRefreshList = getLayoutInflater().inflate(R.layout.browser_listview, listContainer); break; case GRID: swipeRefreshList = getLayoutInflater().inflate(R.layout.browser_gridview, listContainer); break; default: throw new IllegalArgumentException("Unexpected ListApeparance: " + settings.getListAppearance()); } if (swipeRefreshList == null) { throw new RuntimeException("Inflated View is null"); } final ViewGroup swipeRefreshLayoutList = (ViewGroup) swipeRefreshList .findViewById(R.id.browser_list_swipe_refresh); mList = (AbsListView) swipeRefreshLayoutList.getChildAt(0); if (mList instanceof ListView) { mAdapter = new BrowserListAdapter(this); } else { mAdapter = new BrowserGridAdapter(this); } mList.setEmptyView(findViewById(android.R.id.empty)); mList.setAdapter(mAdapter); final View emptyView = mList.getEmptyView(); if (emptyView != null) { emptyView.setVisibility(View.GONE); } mList.setVisibility(View.GONE); mActionModeController.setListView(mList); mList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> av, View v, int pos, long id) { final GenericFile target = (GenericFile) av.getItemAtPosition(pos); if (target == null) { throw new RuntimeException("Item at position is null"); } PFMFileUtils.openFileInExternalApp(SearchActivity.this, target.toFile()); } }); }
From source file:org.strongswan.android.ui.fragment.VpnProfileListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.profile_list_fragment, null); mListView = (ListView) view.findViewById(R.id.profile_list); mListView.setAdapter(mListAdapter);//from ww w.j a v a 2 s .com mListView.setEmptyView(view.findViewById(R.id.profile_list_empty)); //item mListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mListener != null) { VpnProfile vpnProfile = (VpnProfile) parent.getItemAtPosition(position); mListener.onVpnProfileSelected(vpnProfile); } } }); //????listener if (!mReadOnly) { mListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL); mListView.setMultiChoiceModeListener(mVpnProfileSelected); } return view; }
From source file:com.example.mikhail.sunshine.app.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.fragment_my, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//www. ja v a 2 s .c o m public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { String locationSetting = Utility.getPreferredLocation(getActivity()); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }
From source file:net.ustyugov.jtalk.activity.note.NotesActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); service = JTalkService.getInstance(); setTheme(Colors.isLight ? R.style.AppThemeLight : R.style.AppThemeDark); setTitle(R.string.notes);//from ww w.j ava 2 s . c o m getActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.paged_activity); LinearLayout linear = (LinearLayout) findViewById(R.id.linear); linear.setBackgroundColor(Colors.BACKGROUND); LayoutInflater inflater = LayoutInflater.from(this); MainPageAdapter adapter = new MainPageAdapter(mPages); Cursor cursor = service.getContentResolver().query(JTalkProvider.ACCOUNT_URI, null, AccountDbHelper.ENABLED + " = '" + 1 + "'", null, null); if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); do { final String account = cursor.getString(cursor.getColumnIndex(AccountDbHelper.JID)).trim(); View templatePage = inflater.inflate(R.layout.list_activity, null); templatePage.setTag(account); mPages.add(templatePage); ListView list = (ListView) templatePage.findViewById(R.id.list); list.setDividerHeight(1); list.setCacheColorHint(0x00000000); list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) { final Note note = (Note) parent.getItemAtPosition(position); CharSequence[] items = new CharSequence[2]; items[0] = getString(R.string.Edit); items[1] = getString(R.string.Remove); AlertDialog.Builder builder = new AlertDialog.Builder(NotesActivity.this); builder.setTitle(R.string.Actions); builder.setItems(items, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (which) { case 0: createDialog(account, note); break; case 1: try { NoteManager nm = NoteManager.getNoteManager(service.getConnection(account)); nm.removeNote(note); updateNotes(); } catch (Exception ignored) { } break; } } }); builder.create().show(); return true; } }); } while (cursor.moveToNext()); cursor.close(); } mPager = (ViewPager) findViewById(R.id.pager); mPager.setAdapter(adapter); mPager.setCurrentItem(0); TitlePageIndicator mTitleIndicator = (TitlePageIndicator) findViewById(R.id.indicator); mTitleIndicator.setTextColor(0xFF555555); mTitleIndicator.setViewPager(mPager); }
From source file:com.example.houcem.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.List_View_Forecast); listView.setAdapter(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override// w w w . ja v a 2 s . c om public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { String locationSetting = com.example.houcem.sunshine.Utility .getPreferredLocation(getActivity()); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }
From source file:com.procleus.brime.ui.LabelsFragment.java
public void addLabelFunc(View v, NotesDbHelperOld nt) { editText = (CustomEditText) v.findViewById(R.id.addLabelInput); String ed = editText.getText().toString().trim(); if (ed.isEmpty()) { editText.setError("Provide a Label Name"); } else {//from w w w . j a v a2 s. c o m nt.insertLabel(editText.getText().toString()); Log.i("Bless", editText.getText().toString()); ArrayList<String> labelsRetrieved = new ArrayList<String>(); labelsRetrieved = nt.retrieveLabel(); listView = (ListView) getView().findViewById(R.id.listLabel); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(), android.R.layout.simple_list_item_1, labelsRetrieved); listView.setAdapter(arrayAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Intent i = new Intent(getActivity(), LabelOpenActivity.class); i.putExtra("label", String.valueOf(parent.getItemAtPosition(position))); Toast.makeText(getActivity(), "Inside in label" + ":" + String.valueOf(parent.getItemAtPosition(position)), Toast.LENGTH_SHORT).show(); startActivity(i); } }); } }
From source file:com.theelix.libreexplorer.FileManagerActivity.java
/** This function reads the current Folder, and populates the ListView with the content of that folder */ public void refresh() { ((ViewGroup) findViewById(R.id.list_layout)).removeView(itemView); if (FileManager.getCurrentDirectory().getName().equals("")) { mActionBar.setTitle(getString(R.string.app_name)); } else {/*from w ww . ja va 2 s. c om*/ mActionBar.setTitle(getString(R.string.app_name) + ": " + FileManager.getCurrentDirectory().getName()); } boolean useGrid = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_layout_grid", false); int itemLayout; if (useGrid) { itemView = new GridView(this); itemLayout = R.layout.file_grid_element; ((GridView) itemView).setNumColumns(4); ((GridView) itemView).setHorizontalSpacing(0); } else { itemView = new ListView(this); itemLayout = R.layout.file_list_element; } boolean hideHiddenFiles = !PreferenceManager.getDefaultSharedPreferences(this) .getBoolean("pref_show_hidden_files", false); try { ArrayList<File> fileList = new ArrayList<>( Arrays.asList(FileManager.getCurrentDirectory().listFiles())); for (int i = 0; i < fileList.size(); i++) { if (fileList.get(i).isHidden() && hideHiddenFiles) { fileList.remove(fileList.get(i)); } } ArrayAdapter<File> filelistAdapter = new FileListArrayAdapter(this, itemLayout, fileList); filelistAdapter.sort(new FileComparator()); itemView.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); ActionModeCallback callback = new ActionModeCallback(); callback.setListView(itemView); callback.setContext(this); itemView.setMultiChoiceModeListener(callback); mDrawerLayout.closeDrawers(); itemView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View view, int position, long id) { File file = (File) adapter.getItemAtPosition(position); if (file.isDirectory()) { FileManager.setCurrentDirectory(file); } else { FileManager.openFile(file); } } }); itemView.setAdapter(filelistAdapter); itemView.setTextFilterEnabled(true); ((ViewGroup) findViewById(R.id.list_layout)).addView(itemView, new AbsListView.LayoutParams( AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.MATCH_PARENT)); } catch (NullPointerException e) { Toast.makeText(this, "Unable to Access File", Toast.LENGTH_LONG).show(); } //Check if SDCard is mounted, if so shows External Storage on the Sidebar if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (Environment.getExternalStorageState(new File(System.getenv("SECONDARY_STORAGE"))) .equals(Environment.MEDIA_MOUNTED)) { findViewById(R.id.menu_external_storage).setVisibility(View.VISIBLE); } else { findViewById(R.id.menu_external_storage).setVisibility(View.GONE); } } else { //Dirty method, but I think is the only option for devices before L if (new File(System.getenv("SECONDARY_STORAGE")).canRead()) { findViewById(R.id.menu_external_storage).setVisibility(View.VISIBLE); } else { findViewById(R.id.menu_external_storage).setVisibility(View.GONE); } } }
From source file:bhav.sunshine.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); SharedPreferences prefs = getActivity().getSharedPreferences("prefs", Context.MODE_PRIVATE); mLocation = prefs.getString(String.valueOf(R.string.pref_location_key), String.valueOf(R.string.pref_location_default)); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listView_forecast); listView.setAdapter(mForecastAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override//w w w . j a va 2 s. c o m public void onItemClick(AdapterView adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { String locationSetting = Utility.getPreferredLocation(getActivity()); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }
From source file:com.example.abdelsattar.sunshine.app.ForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.fragment_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast); listView.setAdapter(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from w w w .ja v a 2s . com*/ public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { String locationSetting = Utility.getPreferredLocation(getActivity()); Intent intent = new Intent(getActivity(), DetailActivity.class) .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }