List of usage examples for android.widget AdapterView getItemAtPosition
public Object getItemAtPosition(int position)
From source file:net.sourceforge.servestream.fragment.UrlListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); mPreferences = PreferenceManager.getDefaultSharedPreferences(getActivity()); DragSortListView list = (DragSortListView) getListView(); list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); list.setDropListener(dropListener);/*from w w w . j av a 2 s. co m*/ list.setOnItemClickListener(new AdapterView.OnItemClickListener() { public synchronized void onItemClick(AdapterView<?> parent, View view, int position, long id) { if (mActionMode == null) { UriBean uriBean = (UriBean) parent.getItemAtPosition(position); processUri(uriBean.getUri().toString()); } else { for (int i = 0; i < mChecked.size(); i++) { if (mChecked.keyAt(i) == position && mChecked.valueAt(i)) { view.setBackgroundResource(0); getListView().setItemChecked(position, false); mAdapter.notifyDataSetChanged(); } } // Notice how the ListView api is lame // You can use mListView.getCheckedItemIds() if the adapter // has stable ids, e.g you're using a CursorAdaptor SparseBooleanArray checked = getListView().getCheckedItemPositions(); boolean hasCheckedElement = false; checked = getListView().getCheckedItemPositions(); for (int i = 0; i < checked.size(); i++) { if (checked.valueAt(i)) { View v = getListView().getChildAt(checked.keyAt(i)); if (v != null) { v.setBackgroundColor(getActivity().getResources() .getColor(R.color.selection_background_color_light)); } } } mAdapter.notifyDataSetChanged(); for (int i = 0; i < checked.size() && !hasCheckedElement; i++) { hasCheckedElement = checked.valueAt(i); } if (hasCheckedElement) { if (mActionMode == null) { mActionMode = ((ActionBarActivity) getActivity()) .startSupportActionMode(mActionModeCallback); } } else { if (mActionMode != null) { mActionMode.finish(); mActionMode = null; } } mChecked = getListView().getCheckedItemPositions().clone(); } } }); list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { if (mActionMode == null) { mActionMode = ((ActionBarActivity) getActivity()).startSupportActionMode(mActionModeCallback); getListView().setItemChecked(position, true); view.setBackgroundColor( getActivity().getResources().getColor(R.color.selection_background_color_light)); mChecked = getListView().getCheckedItemPositions().clone(); return true; } return false; } }); DragSortController controller = new DragSortController(list); controller.setDragInitMode(DragSortController.ON_DRAG); controller.setDragHandleId(R.id.drag_handle); list.setOnTouchListener(controller); mAdapter = new UrlListAdapter(getActivity(), new ArrayList<UriBean>(), this); setListAdapter(mAdapter); }
From source file:es.usc.citius.servando.calendula.fragments.MedicineCreateOrEditFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_create_or_edit_medicine, container, false); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); mNameTextView = (AutoCompleteTextView) rootView.findViewById(R.id.medicine_edit_name); mPresentationTv = (TextView) rootView.findViewById(R.id.textView3); mDescriptionTv = (TextView) rootView.findViewById(R.id.medicine_edit_description); searchButton = (ImageView) rootView.findViewById(R.id.search_button); mNameTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override/*from ww w . j av a 2s .c om*/ public void onItemClick(AdapterView<?> parent, View arg1, int pos, long id) { Prescription p = (Prescription) parent.getItemAtPosition(pos); String shortName = p.shortName(); mNameTextView.setText(shortName); mDescriptionTv.setText(p.name); hideKeyboard(); // save referenced prescription to med cn = p.cn; } }); pColor = DB.patients().getActive(getActivity()).color(); mDescriptionTv.setTextColor(pColor); mPresentationTv.setTextColor(pColor); enableSearch = prefs.getBoolean("enable_prescriptions_db", false); if (enableSearch) { enableSearchButton(); } else { searchButton.setVisibility(View.GONE); } presentationScroll = (HorizontalScrollView) rootView.findViewById(R.id.med_presentation_scroll); Log.d(getTag(), "Arguments: " + (getArguments() != null) + ", savedState: " + (savedInstanceState != null)); if (getArguments() != null) { mMedicineId = getArguments().getLong(CalendulaApp.INTENT_EXTRA_MEDICINE_ID, -1); } if (mMedicineId == -1 && savedInstanceState != null) { mMedicineId = savedInstanceState.getLong(CalendulaApp.INTENT_EXTRA_MEDICINE_ID, -1); } if (mMedicineId != -1) { mMedicine = Medicine.findById(mMedicineId); } setupMedPresentationChooser(rootView); mNameTextView.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { String name = mNameTextView.getText().toString(); if (mPrescription != null && !mPrescription.shortName().toLowerCase().equals(name.toLowerCase())) { mPrescription = null; mDescriptionTv.setText(""); } } }); mNameTextView.requestFocus(); askForPrescriptionUsage(); return rootView; }
From source file:com.money.manager.ex.investment.watchlist.WatchlistFragment.java
private void initializeAccountsSelector() { ActionBar actionBar = getActionBar(); if (actionBar == null) return;/*from ww w . jav a 2 s .co m*/ actionBar.setDisplayShowTitleEnabled(false); actionBar.setCustomView(R.layout.spinner); actionBar.setDisplayShowCustomEnabled(true); Spinner spinner = getAccountsSpinner(); if (spinner == null) return; // Load accounts into the spinner. AccountService accountService = new AccountService(getActivity()); accountService.loadInvestmentAccountsToSpinner(spinner, true); // e account switching. spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { // switch account. Cursor cursor = (Cursor) adapterView.getItemAtPosition(i); Account account = Account.from(cursor); int accountId = account.getId(); switchAccount(accountId); } @Override public void onNothingSelected(AdapterView<?> adapterView) { } }); }
From source file:org.csploit.android.plugins.LoginCracker.java
public void onCreate(Bundle savedInstanceState) { SharedPreferences themePrefs = getSharedPreferences("THEME", 0); Boolean isDark = themePrefs.getBoolean("isDark", false); if (isDark)/*from w w w . j a va 2 s . c om*/ setTheme(R.style.DarkTheme); else setTheme(R.style.AppTheme); super.onCreate(savedInstanceState); if (!System.getCurrentTarget().hasOpenPorts()) new FinishDialog(getString(R.string.warning), getString(R.string.no_open_ports), this).show(); final ArrayList<String> ports = new ArrayList<String>(); for (Port port : System.getCurrentTarget().getOpenPorts()) ports.add(Integer.toString(port.getNumber())); mProtocolAdapter = new ProtocolAdapter(); mPortSpinner = (Spinner) findViewById(R.id.portSpinner); mPortSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ports)); mPortSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) { String port = (String) adapter.getItemAtPosition(position); int protocolIndex = mProtocolAdapter.getIndexByPort(port); if (protocolIndex != -1) mProtocolSpinner.setSelection(protocolIndex); } public void onNothingSelected(AdapterView<?> arg0) { } }); mProtocolSpinner = (Spinner) findViewById(R.id.protocolSpinner); mProtocolSpinner.setAdapter(new ProtocolAdapter()); mProtocolSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) { int portIndex = mProtocolAdapter.getPortIndexByProtocol(position); if (portIndex != -1) mPortSpinner.setSelection(portIndex); } public void onNothingSelected(AdapterView<?> arg0) { } }); mCharsetSpinner = (Spinner) findViewById(R.id.charsetSpinner); mCharsetSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, CHARSETS)); mCharsetSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) { if (CHARSETS_MAPPING[position] == null) { new InputDialog(getString(R.string.custom_charset), getString(R.string.enter_chars_wanted), LoginCracker.this, new InputDialogListener() { @Override public void onInputEntered(String input) { input = input.trim(); if (!input.isEmpty()) mCustomCharset = "aA1" + input; else { mCustomCharset = null; mCharsetSpinner.setSelection(0); } } }).show(); } else mCustomCharset = null; } public void onNothingSelected(AdapterView<?> arg0) { } }); mUserSpinner = (Spinner) findViewById(R.id.userSpinner); mUserSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, USERNAMES)); mUserSpinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> adapter, View view, int position, long id) { String user = (String) adapter.getItemAtPosition(position); if (user != null && user.equals("-- ADD --")) { new InputDialog(getString(R.string.add_username), getString(R.string.enter_username), LoginCracker.this, new InputDialogListener() { @Override public void onInputEntered(String input) { USERNAMES = Arrays.copyOf(USERNAMES, USERNAMES.length + 1); USERNAMES[USERNAMES.length - 1] = "-- ADD --"; USERNAMES[USERNAMES.length - 2] = input; mUserSpinner.setAdapter(new ArrayAdapter<String>(LoginCracker.this, android.R.layout.simple_spinner_item, USERNAMES)); mUserSpinner.setSelection(USERNAMES.length - 2); } }).show(); } } public void onNothingSelected(AdapterView<?> arg0) { } }); mMaxSpinner = (Spinner) findViewById(R.id.maxSpinner); mMaxSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, LENGTHS)); mMinSpinner = (Spinner) findViewById(R.id.minSpinner); mMinSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, LENGTHS)); mStartButton = (FloatingActionButton) findViewById(R.id.startFAB); mStatusText = (TextView) findViewById(R.id.statusText); mProgressBar = (ProgressBar) findViewById(R.id.progressBar); mActivity = (ProgressBar) findViewById(R.id.activity); mProgressBar.setMax(100); mReceiver = new AttemptReceiver(); mStartButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mRunning) { setStoppedState(); } else { setStartedState(); } } }); mWordlistPicker = new Intent(); mWordlistPicker.addCategory(Intent.CATEGORY_OPENABLE); mWordlistPicker.setType("text/*"); mWordlistPicker.setAction(Intent.ACTION_GET_CONTENT); if (Build.VERSION.SDK_INT >= 11) mWordlistPicker.putExtra(Intent.EXTRA_LOCAL_ONLY, true); }
From source file:tv.acfun.a63.CommentsActivity.java
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override/*from ww w . java 2 s .c om*/ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { Object o = parent.getItemAtPosition(position); if (o == null || !(o instanceof Comment)) return false; Comment c = (Comment) o; ClipboardManager ma = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { ClipData text = ClipData.newHtmlText(c.userName, c.content, c.content); ((android.content.ClipboardManager) ma).setPrimaryClip(text); } else { ma.setText(c.content); } Toast.makeText(this, "#" + c.count + "?", 0).show(); return true; }
From source file:cx.ring.fragments.CallListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { Log.i(TAG, "onCreateView"); setHasOptionsMenu(true);//from w w w . ja v a 2 s . c om View inflatedView = inflater.inflate(cx.ring.R.layout.frag_call_list, container, false); newconv_btn = (FloatingActionButton) inflatedView.findViewById(R.id.newconv_fab); newconv_btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchMenuItem.expandActionView(); } }); list = (ListView) inflatedView.findViewById(cx.ring.R.id.confs_list); list.setOnItemClickListener(callClickListener); //list.setOnItemLongClickListener(mItemLongClickListener); mHeader = (LinearLayout) inflater.inflate(R.layout.frag_contact_list_header, null); contactList = (StickyListHeadersListView) inflatedView.findViewById(R.id.contacts_stickylv); contactList.setDivider(null); contactList.addHeaderView(mHeader, null, false); contactList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { final CallContact item = (CallContact) parent.getItemAtPosition(position); ((HomeActivity) getActivity()).onTextContact(item); } }); mStarredGrid = (GridView) mHeader.findViewById(R.id.favorites_grid); llMain = (LinearLayout) mHeader.findViewById(R.id.llMain); favHeadLabel = (TextView) mHeader.findViewById(R.id.fav_head_label); newcontact = (ViewGroup) mHeader.findViewById(R.id.newcontact_element); newcontact.setVisibility(View.GONE); newcontact.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CallContact c = (CallContact) v.getTag(); if (c == null) return; startConversation(c); } }); newcontact.findViewById(R.id.quick_call).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { CallContact c = (CallContact) newcontact.getTag(); if (c != null) ((HomeActivity) getActivity()).onCallContact(c); } }); error_msg_pane = (ViewGroup) inflatedView.findViewById(R.id.error_msg_pane); error_msg_txt = (TextView) error_msg_pane.findViewById(R.id.error_msg_txt); list.setVisibility(View.VISIBLE); contactList.setVisibility(View.GONE); LocalService service = mCallbacks.getService(); if (service == null) return inflatedView; mConferenceAdapter = new CallListAdapter(getActivity(), service.get40dpContactCache(), service.getThreadPool()); mListAdapter = new ContactsAdapter(getActivity(), (HomeActivity) getActivity(), service.get40dpContactCache(), service.getThreadPool()); mGridAdapter = new StarredContactsAdapter(getActivity()); mConferenceAdapter.updateDataset(mCallbacks.getService().getConversations()); list.setAdapter(mConferenceAdapter); return inflatedView; }
From source file:com.app_software.chromisstock.ProductDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_product_detail, container, false); m_taxSpinner = ((Spinner) rootView.findViewById(R.id.spn_taxcat)); m_categorySpinner = ((Spinner) rootView.findViewById(R.id.spn_category)); m_image = (ImageView) rootView.findViewById(R.id.iv_image); m_image.setLayerType(View.LAYER_TYPE_SOFTWARE, null); m_txt_location = (TextView) rootView.findViewById(R.id.txt_location); m_edit_name = (EditText) rootView.findViewById(R.id.edit_name); m_edit_reference = (EditText) rootView.findViewById(R.id.edit_reference); m_edit_barcode = (EditText) rootView.findViewById(R.id.edit_barcode); m_edit_instock = (EditText) rootView.findViewById(R.id.edit_instock); m_edit_minqty = (EditText) rootView.findViewById(R.id.edit_minqty); m_edit_maxqty = (EditText) rootView.findViewById(R.id.edit_maxqty); m_edit_pricebuy = (EditText) rootView.findViewById(R.id.edit_pricebuy); m_edit_pricesell = (EditText) rootView.findViewById(R.id.edit_pricesell); m_taxAdaptor = new TaxCatAdapter(m_db.getTaxCats()); m_taxSpinner.setAdapter(m_taxAdaptor); m_taxSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override//from ww w .j av a2s . com public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { DatabaseHandler.TaxCat item = (DatabaseHandler.TaxCat) arg0.getItemAtPosition(arg2); if (item != null) { if (TextUtils.isEmpty(m_LastTaxCat) || m_LastTaxCat.compareTo(item.ChromisId) != 0) { m_db.addChange(mItem.getChromisId(), DatabaseHandler.CHANGETYPE_CHANGEVALUE, StockProduct.TAXCAT, item.ChromisId, item.Name); m_LastTaxCat = item.ChromisId; } } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); m_categoryAdaptor = new CategoryAdapter(m_db.getCategories()); m_categorySpinner.setAdapter(m_categoryAdaptor); m_categorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { DatabaseHandler.Category item = (DatabaseHandler.Category) arg0.getItemAtPosition(arg2); if (item != null) { if (TextUtils.isEmpty(m_LastCategory) || m_LastCategory.compareTo(item.ChromisId) != 0) { m_db.addChange(mItem.getChromisId(), DatabaseHandler.CHANGETYPE_CHANGEVALUE, StockProduct.CATEGORY, item.ChromisId, item.Name); m_LastCategory = item.ChromisId; } } } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); m_image.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { dispatchTakePictureIntent(); } }); rootView.findViewById(R.id.ibAddStock).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onEditItem(v); } }); rootView.findViewById(R.id.ibBarcode).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onScanItem(v); } }); m_edit_instock.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onEditItem(v); } }); rootView.findViewById(R.id.edit_name).setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onEditItem(v); } }); m_edit_reference.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onEditItem(v); } }); m_edit_barcode.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onEditItem(v); } }); m_edit_minqty.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onEditItem(v); } }); m_edit_maxqty.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onEditItem(v); } }); m_edit_pricebuy.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onEditItem(v); } }); m_edit_pricesell.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onEditItem(v); } }); setViewsContent(); return rootView; }
From source file:org.mozilla.gecko.AboutHomeContent.java
public void init() { Context context = getContext(); mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); mInflater.inflate(R.layout.abouthome_content, this); mAccountManager = AccountManager.get(context); // The listener will run on the background thread (see 2nd argument) mAccountManager.addOnAccountsUpdatedListener(new OnAccountsUpdateListener() { public void onAccountsUpdated(Account[] accounts) { final GeckoApp.StartupMode startupMode = GeckoApp.mAppContext.getStartupMode(); final boolean syncIsSetup = isSyncSetup(); GeckoApp.mAppContext.mMainHandler.post(new Runnable() { public void run() { // The listener might run before the UI is initially updated. // In this case, we should simply wait for the initial setup // to happen. if (mTopSitesAdapter != null) updateLayout(startupMode, syncIsSetup); }//www. j a v a 2 s . co m }); } }, GeckoAppShell.getHandler(), false); mTopSitesGrid = (GridView) findViewById(R.id.top_sites_grid); mTopSitesGrid.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { Cursor c = (Cursor) parent.getItemAtPosition(position); String spec = c.getString(c.getColumnIndex(URLColumns.URL)); Log.i(LOGTAG, "clicked: " + spec); if (mUriLoadCallback != null) mUriLoadCallback.callback(spec); } }); mAddonsLayout = (LinearLayout) findViewById(R.id.recommended_addons); mLastTabsLayout = (LinearLayout) findViewById(R.id.last_tabs); TextView allTopSitesText = (TextView) findViewById(R.id.all_top_sites_text); allTopSitesText.setOnClickListener(new OnClickListener() { public void onClick(View v) { GeckoApp.mAppContext.showAwesomebar(AwesomeBar.Type.EDIT); } }); TextView allAddonsText = (TextView) findViewById(R.id.all_addons_text); allAddonsText.setOnClickListener(new OnClickListener() { public void onClick(View v) { if (mUriLoadCallback != null) mUriLoadCallback.callback("https://addons.mozilla.org/android"); } }); TextView syncTextView = (TextView) findViewById(R.id.sync_text); String syncText = syncTextView.getText().toString() + " \u00BB"; String boldName = getContext().getResources().getString(R.string.abouthome_sync_bold_name); int styleIndex = syncText.indexOf(boldName); // Highlight any occurrence of "Firefox Sync" in the string // with a bold style. if (styleIndex >= 0) { SpannableString spannableText = new SpannableString(syncText); spannableText.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), styleIndex, styleIndex + 12, 0); syncTextView.setText(spannableText, TextView.BufferType.SPANNABLE); } RelativeLayout syncBox = (RelativeLayout) findViewById(R.id.sync_box); syncBox.setOnClickListener(new OnClickListener() { public void onClick(View v) { Context context = v.getContext(); Intent intent = new Intent(context, SetupSyncActivity.class); context.startActivity(intent); } }); }
From source file:com.nps.micro.view.TestsSectionFragment.java
private void createDeviceChooser(View rootView, final Button runButton) { availableDevicesListView = (ListView) rootView.findViewById(R.id.availableDevicesListView); availableDevicesAdapter = new ArrayAdapter<String>(getActivity(), R.layout.text_view, devicesList); availableDevicesListView.setAdapter(availableDevicesAdapter); availableDevicesListView.setTextFilterEnabled(true); availableDevicesListView.setOnItemClickListener(new OnItemClickListener() { @Override/*from w ww .j a v a 2s .co m*/ public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { String item = (String) parent.getItemAtPosition(position); selectedDevices.add(ensureUniqueItem(item)); selectedDevicesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view, selectedDevices); selectedDevicesListView.setAdapter(selectedDevicesAdapter); setListViewHeightBasedOnChildren(selectedDevicesListView); updateModelSelectedDevices(); } private String ensureUniqueItem(String item) { if (selectedDevices.contains(item)) { return ensureUniqueItem(item + "'"); } else { return item; } } }); availableDevicesListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) { view.setBackgroundColor(Color.CYAN); final String item = (String) parent.getItemAtPosition(position); final String msg = getResources().getString(R.string.ping_device_info); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.ping_device_title).setMessage(String.format(msg, item)) .setPositiveButton(R.string.ping, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { view.setBackgroundColor(Color.BLACK); if (listener != null) { listener.pingDevice(item); } dialog.dismiss(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { view.setBackgroundColor(Color.BLACK); dialog.dismiss(); } }); builder.create().show(); return true; } }); setListViewHeightBasedOnChildren(availableDevicesListView); selectedDevicesListView = (DynamicListView) rootView.findViewById(R.id.selectedDevicesListView); selectedDevicesListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); selectedDevicesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view, selectedDevices); selectedDevicesListView.setListItems(selectedDevices); selectedDevicesListView.setAdapter(selectedDevicesAdapter); selectedDevicesListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { final String item = (String) parent.getItemAtPosition(position); selectedDevices.remove(item); selectedDevicesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view, selectedDevices); selectedDevicesListView.setAdapter(selectedDevicesAdapter); setListViewHeightBasedOnChildren(selectedDevicesListView); updateModelSelectedDevices(); } }); selectedDevicesListView.setOnTouchListener(new ListView.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: v.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: v.getParent().requestDisallowInterceptTouchEvent(false); break; } v.onTouchEvent(event); return true; } }); setListViewHeightBasedOnChildren(selectedDevicesListView); }
From source file:com.fanfou.app.opensource.HomePage.java
@Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { final Cursor c = (Cursor) parent.getItemAtPosition(position); if (c == null) { return;//from w w w .ja v a 2 s .c om } if (this.mCurrentPage == 2) { CommonHelper.goMessageChatPage(this, c); } else { final Status s = Status.parse(c); if ((s != null) && !s.isNull()) { CommonHelper.goStatusPage(this, s); } } }