List of usage examples for android.widget AdapterView getItemAtPosition
public Object getItemAtPosition(int position)
From source file:edu.mit.mobile.android.locast.casts.CastDetail.java
@Override public void onItemClick(AdapterView<?> adapter, View v, int position, long id) { final Cursor c = (Cursor) adapter.getItemAtPosition(position); CastMedia.showMedia(this, c, mCastMediaUri); }
From source file:net.ustyugov.jtalk.activity.muc.Muc.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.MUC);//from w ww . ja va 2s .c o m getActionBar().setDisplayHomeAsUpEnabled(true); setContentView(R.layout.paged_activity); LinearLayout linear = (LinearLayout) findViewById(R.id.linear); linear.setBackgroundColor(Colors.BACKGROUND); MainPageAdapter adapter = new MainPageAdapter(mPages); LayoutInflater inflater = LayoutInflater.from(this); 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 page = inflater.inflate(R.layout.list_activity, null); page.setTag(account); mPages.add(page); ListView list = (ListView) page.findViewById(R.id.list); list.setDividerHeight(0); list.setCacheColorHint(0x00000000); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { RosterItem item = (RosterItem) parent.getItemAtPosition(position); String name = item.getName(); String account = item.getAccount(); if (item.isGroup()) { if (item.isCollapsed()) { while (service.getCollapsedGroups().contains(name)) service.getCollapsedGroups().remove(name); item.setCollapsed(false); } else { service.getCollapsedGroups().add(name); item.setCollapsed(true); } updateList(); } else if (item.isEntry()) { RosterEntry re = item.getEntry(); String jid = re.getUser(); Intent i = new Intent(Muc.this, Chat.class); i.putExtra("account", account); i.putExtra("jid", jid); startActivity(i); } else if (item.isMuc()) { Intent i = new Intent(Muc.this, Chat.class); i.putExtra("account", account); i.putExtra("jid", item.getName()); startActivity(i); } } }); list.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View v, int position, long id) { RosterItem item = (RosterItem) parent.getItemAtPosition(position); if (item.isGroup()) { // } else if (item.isEntry()) { String j = item.getEntry().getUser(); String group = StringUtils.parseBareAddress(j); String nick = StringUtils.parseResource(j); MucDialogs.userMenu(Muc.this, item.getAccount(), group, nick); } else if (item.isMuc()) { MucDialogs.roomMenu(Muc.this, item.getAccount(), item.getName()); } return true; } }); MucRosterAdapter mra = new MucRosterAdapter(this, account); list.setAdapter(mra); adapters.add(mra); } 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.carver.paul.truesight.Ui.CounterPicker.CounterPickerFragment.java
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { // An item was selected. You can retrieve the selected item using String role = (String) parent.getItemAtPosition(pos); for (int stringId : roleStringIds) { if (role.equals(getString(stringId))) { mPresenter.setRoleFilter(stringId); return; }/* w ww . j av a 2s. c o m*/ } }
From source file:com.remdo.app.EditDeviceActivity.java
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // On selecting a spinner item String item = parent.getItemAtPosition(position).toString(); deviceType = dh.getODDeviceType(item).id; }
From source file:edu.nimbus.glass.TopicSelectActivity.java
/** * Method to poll the ROS Server to get the list of topics that are currenly being published. *///from www . j a v a 2 s . co m private void createTopics() { final String url = TopicService.HOST_ADDRESS; final WebSocketConnection mConnection = new WebSocketConnection(); try { Log.d("Socket", "Atempting connection"); mConnection.connect(url, new WebSocketHandler() { boolean message_received = false; @Override public void onOpen() { //send the request JSONObject jsonRequest = new JSONObject(); try { jsonRequest.put("op", "call_service"); jsonRequest.put("service", "/list_topics"); } catch (Exception e) { } Log.d("Main Connection", "Status: Connected to " + url); mConnection.sendTextMessage(jsonRequest.toString()); } @Override public void onTextMessage(String payload) { message_received = true; Log.d("Main Payload", payload); //We got a message back from the server so lets create the cards for selection. JSONObject obj; String topics = "n/a"; try { obj = new JSONObject(payload); topics = obj.getJSONObject("values").getString("topics"); } catch (JSONException e) { topics = "n/a"; } if (topics.equals("n/a")) { Card card1 = new Card(getBaseContext()); card1.setText("No Topics Returned Check Setup."); View card1View = card1.toView(); setContentView(card1View); } else { //Split topics and create cards. stringArr = topics.split(","); ArrayList<String> topicNames = getTopics(); createCards(topicNames); mCardScrollView = new CardScrollView(TopicSelectActivity.this); TopicCardScrollAdapter adapter = new TopicCardScrollAdapter(); mCardScrollView.setAdapter(adapter); mCardScrollView.setOnItemClickListener(new OnItemClickListener() { /** * On click we are going to get the name of the topic and create the service to display messages * from that topic. */ @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String topic = ((Card) parent.getItemAtPosition(position)).getText(); //bindService(new Intent(TopicSelectActivity.this, TopicService.class), mServiceConnection, 0); Intent intt = new Intent(TopicSelectActivity.this, TopicService.class); intt.putExtra("view_state", TopicService.ALL_FIELDS); intt.putExtra("topic", topic); startService(intt); } }); //Show the scroll cards and close the connection. mCardScrollView.activate(); setContentView(mCardScrollView); mConnection.disconnect(); } } @Override public void onClose(int code, String reason) { if (!message_received) { Card card1 = new Card(getBaseContext()); card1.setText("No Web Connection"); View card1View = card1.toView(); setContentView(card1View); } } }); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.damianhinch.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//from w w w . j a va 2s .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 = Helpers.getUserPreferredLocation(getActivity()); Intent intent = new Intent(getActivity(), DetailView.class).setData(WeatherContract.WeatherEntry .buildWeatherLocationWithDate(locationSetting, cursor.getLong(COL_WEATHER_DATE))); startActivity(intent); } } }); return rootView; }
From source file:com.z3r0byte.magis.GradeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_grade); Bundle extras = getIntent().getExtras(); mMagister = GlobalMagister.MAGISTER; mToolbar = (Toolbar) findViewById(R.id.Toolbar); mToolbar.setTitle(R.string.title_grades); setSupportActionBar(mToolbar);/*from w w w . j a v a 2s . c om*/ studies[0] = new Study(); studies[0].description = "Laden..."; studyAdapter = new StudyAdapter(this, studies); spinner = (Spinner) findViewById(R.id.studyPicker); spinner.getBackground().setColorFilter(getResources().getColor(R.color.md_white_1000), PorterDuff.Mode.SRC_ATOP); spinner.setAdapter(studyAdapter); spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { Log.d(TAG, "onItemSelected: Study: " + adapterView.getItemAtPosition(i).toString()); if (!studies[0].description.equals("Laden...")) { mainGradesFragment.study = (Study) adapterView.getItemAtPosition(i); mainGradesFragment.loadGrades(); } } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); mProfile = new Gson().fromJson(getSharedPreferences("data", MODE_PRIVATE).getString("Profile", null), Profile.class); mUser = new Gson().fromJson(getSharedPreferences("data", MODE_PRIVATE).getString("User", null), User.class); mSchool = new Gson().fromJson(getSharedPreferences("data", MODE_PRIVATE).getString("School", null), School.class); navigationDrawer = new NavigationDrawer(this, mToolbar, mProfile, mUser, "Cijfers"); navigationDrawer.SetupNavigationDrawer(); //Setting up Tabs tabHost = (MaterialTabHost) findViewById(R.id.materialTabHost); viewPager = (ViewPager) findViewById(R.id.viewpager); pagerAdapter = new ViewPagerAdapter(getSupportFragmentManager()); viewPager.setAdapter(pagerAdapter); viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { @Override public void onPageSelected(int position) { tabHost.setSelectedNavigationItem(position); } }); for (int i = 0; i < pagerAdapter.getCount(); i++) { tabHost.addTab(tabHost.newTab().setText(pagerAdapter.getPageTitle(i)).setTabListener(this)); } new Thread(new Runnable() { @Override public void run() { try { String date = DateUtils.formatDate(DateUtils.getToday(), "yyyy-MM-dd"); StudyHandler studyHandler = new StudyHandler(mMagister); studies = studyHandler.getStudies(true, date); Collections.reverse(Arrays.asList(studies)); //reversing so the newest Study moves to top studyAdapter = new StudyAdapter(getApplicationContext(), studies); runOnUiThread(new Runnable() { @Override public void run() { spinner.setAdapter(studyAdapter); } }); Log.d(TAG, "onCreate: Amount of studies: " + studies.length); for (Study study : studies) { Log.d(TAG, "onCreate: Study: " + study.description); } } catch (IOException e) { Log.e(TAG, "onCreate: Geen verbinding"); } catch (NullPointerException e) { Log.e(TAG, "run: Not logged in", e); studies = new Study[1]; studies[0] = new Study(); studies[0].description = getString(R.string.err_not_logged_in); studies[0].id = 999; studyAdapter = new StudyAdapter(getApplicationContext(), studies); runOnUiThread(new Runnable() { @Override public void run() { spinner.setAdapter(studyAdapter); } }); for (Study study : studies) { Log.d(TAG, "onCreate: Study: " + study.description); } } } }).start(); }
From source file:com.creationgroundmedia.taskmaster.TaskDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mView = inflater.inflate(R.layout.task_detail, container, false); mNameView = (EditText) mView.findViewById(R.id.task_detail_name); mDescriptionView = (EditText) mView.findViewById(R.id.task_detail_description); mDateView = (DatePicker) mView.findViewById(R.id.task_detail_due_date); mCompletedView = (CheckBox) mView.findViewById(R.id.task_detail_status); ArrayAdapter<CharSequence> spinnerAdapter = ArrayAdapter.createFromResource(mContext, R.array.priority, android.R.layout.simple_spinner_item); spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mPriorityView = (Spinner) mView.findViewById(R.id.task_detail_priority); mPriorityView.setAdapter(spinnerAdapter); mPriorityView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override/*from w ww . ja va 2 s . c o m*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { mPriority = (String) parent.getItemAtPosition(position); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); if (mNewTask) { // Make "normal" the default priority. // the position for "normal" should be 1 mPriorityView.setSelection(1); mPriority = mPriorityView.getSelectedItem().toString(); } Button saveView = (Button) mView.findViewById(R.id.save); saveView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { saveData(); if (mNewTask) { dismiss(); } } }); if (!mBackFromRotation && !mNewTask) { mCursorLoader = getActivity().getSupportLoaderManager().initLoader(URL_LOADER, null, this); } return mView; }
From source file:org.alfresco.mobile.android.application.widgets.DocumentFolderPickerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { int titleId = R.string.shortcut_action_create; if (getActivity() instanceof FolderShortcutActivity) { titleId = R.string.shortcut_create; }// ww w .j av a2 s. c o m UIUtils.displayTitle(getActivity(), titleId); rootView = inflater.inflate(R.layout.app_docfolder_picker, container, false); spinnerAccount = (Spinner) rootView.findViewById(R.id.accounts_spinner); spinnerAccount.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) { selectedAccount = (AlfrescoAccount) parent.getItemAtPosition(pos); } @Override public void onNothingSelected(AdapterView<?> arg0) { // Do nothing } }); return rootView; }
From source file:org.openintents.historify.ui.fragments.SourcesConfigurationFragment.java
/** Called to have the fragment instantiate its user interface view. */ @Override//from w ww .j a va 2s.c o m public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.fragment_sources_configuration, container, false); // init sources list mLstSources = (ListView) layout.findViewById(R.id.sources_lstSources); mLstSources.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (position == parent.getCount() - 1) { // need more message new WebsiteHelper().navigateToMoreInfo(getActivity()); } else { EventSource source = (EventSource) parent.getItemAtPosition(position); boolean checked = mLstSources.getCheckedItemPositions().get(position); onSourceClicked(source, checked); } } }); // sources adapter mSourcesAdapter = new SourcesAdapter(getActivity(), mLstSources); mLstSources.setAdapter(mSourcesAdapter); return layout; }