下面列出了android.widget.AdapterView#getItemAtPosition ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void onItemSelected(AdapterView<?> parent, View v, int position, long id) {
if (position >= 0) {
//Get current cursor
Cursor c = (Cursor) parent.getItemAtPosition(position);
int type = c.getInt(COLUMN_PHONE_TYPE);
String phone = c.getString(COLUMN_PHONE_NUMBER);
String label = null;
//Custom type? Then get the custom label
if (type == Phone.TYPE_CUSTOM) {
label = c.getString(COLUMN_PHONE_LABEL);
}
//Get the readable string
String numberType = (String) Phone.getTypeLabel(getResources(), type, label);
String text = numberType + ": " + phone;
mPhone.setText(text);
}
}
@Override
public void onItemClick(AdapterView<?> adapterView, View arg1, int position, long arg3)
{
Object selectedObject = adapterView.getItemAtPosition(position);
if (selectedObject instanceof File)
{
if (actionMode == null)
{
File selectedFile = (File) selectedObject;
if (selectedFile.isDirectory())
navigateTo(selectedFile);
else
openFile(selectedFile);
}
else
{
toggleFileSelected((File) selectedObject);
}
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
mSearchLocalPage.clearFocus(); // otherwise we have to click "back" twice
File data = (File) parent.getItemAtPosition(position);
if(data == null) { // header is present, start config tool
switch (position) {
case 0: // Watch folders
showFolderSettingsDialog();
break;
case 1: // Download archive
downloadArchive();
break;
}
} else {
ManPageDialogFragment mpdf = ManPageDialogFragment.newInstance(data.getName(), data.getPath());
getFragmentManager()
.beginTransaction()
.addToBackStack("PageFromLocalArchive")
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
.replace(R.id.replacer, mpdf)
.commit();
}
}
@Override
public boolean onItemLongClick(final AdapterView<?> parent,
final View view, final int position, final long id) {
final Status s = (Status) parent.getItemAtPosition(position);
showPopup(view, s);
return true;
}
@Override
protected void realOnItemClick(AdapterView<?> parent, View view, int position, long id)
{
News news = (News) parent.getItemAtPosition(position);
Intent intent = new Intent();
intent.setClass(this, BaiduNewsDetailActivity.class);
intent.putExtra("news_title", news.getTitle());
intent.putExtra("news_url", news.getUrl());
startActivity(intent);
}
@Override
public void onItemSelected(final AdapterView<?> parent, final View view, final int position,
final long id) {
final Helper helper = (Helper) parent.getItemAtPosition(position);
if (helper != TrivialBilling.getHelper()) {
TrivialBilling.setHelper(helper);
startActivity(new Intent(TrivialActivity.this, LauncherActivity.class));
finish();
}
}
@Override
public Iterable<AdaptedData> getDataInAdapterView(AdapterView<? extends Adapter> adapterView) {
List<AdaptedData> datas = Lists.newArrayList();
for (int i = 0; i < adapterView.getCount(); i++) {
int position = i;
Object dataAtPosition = adapterView.getItemAtPosition(position);
datas.add(
new AdaptedData.Builder()
.withDataFunction(new StandardDataFunction(dataAtPosition, position))
.withOpaqueToken(position)
.build());
}
return datas;
}
@Override
protected void realOnItemClick(AdapterView<?> parent, View view, int position, long id)
{
AlbumInfo albumInfo = (AlbumInfo) parent.getItemAtPosition(position);
Intent intent = new Intent(getContext(), ImageGridActivity.class);
intent.putExtra(RockyIntent.EXTRA_ALBUM, albumInfo);
startActivity(intent);
}
@Override
public void onItemClick(AdapterView<?> adapter, View view, int position, long id) {
LinphoneContact contact = (LinphoneContact) adapter.getItemAtPosition(position);
if (editOnClick) {
editConsumed = true;
LinphoneActivity.instance().editContact(contact, sipAddressToAdd);
} else {
lastKnownPosition = contactsList.getFirstVisiblePosition();
LinphoneActivity.instance().displayContact(contact, onlyDisplayChatAddress);
}
}
@Override
public void onItemSelected(final AdapterView<?> parent, final View view, final int pos,
final long id) {
final LocaleRenderer locale = (LocaleRenderer)parent.getItemAtPosition(pos);
if (locale.isMoreLanguages()) {
PreferenceActivity preferenceActivity = (PreferenceActivity)getActivity();
preferenceActivity.startPreferenceFragment(new UserDictionaryLocalePicker(), true);
} else {
mContents.updateLocale(locale.getLocaleString());
}
}
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id)
{
AppInfo app = (AppInfo) parent.getItemAtPosition(position);
Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
String pkg = "com.android.settings";
String cls = "com.android.settings.applications.InstalledAppDetails";
intent.setComponent(new ComponentName(pkg, cls));
intent.setData(Uri.parse("package:" + app.packageName));//指明要打开的应用
startActivity(intent);// 用普通的方法去打开界面
return true;// 消化掉事件
}
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id)
{
Contact c = (Contact) parent.getItemAtPosition(position);
listener.onContactSelected(c.id); // pass selection to MainActivity
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ActivityInfo info = (ActivityInfo) parent.getItemAtPosition(position);
Intent intent = new Intent();
intent.setComponent(new ComponentName(this, info.name));
startActivity(intent);
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view,
int position, long id) {
Place p = (Place) adapterView.getItemAtPosition(position);
doPlace(p);
}
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
SpkListItem item = (SpkListItem) adapterView.getItemAtPosition(position);
installPackage(item.getFile());
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final LanguageConfig selectedLanguage = (LanguageConfig) parent.getItemAtPosition(position);
initService(selectedLanguage);
}
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
AppInfo mAppInfo = (AppInfo)arg0.getItemAtPosition(arg2);
launch_app(mAppInfo);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
NavigationEntry entry = (NavigationEntry) parent.getItemAtPosition(position);
mNavigationController.goToNavigationIndex(entry.getIndex());
dismiss();
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ScreenTimeout st = (ScreenTimeout) parent.getItemAtPosition(position);
setScreenOffTimeout(st.mMillis);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
final LanguageConfig selectedLanguage = (LanguageConfig) parent.getItemAtPosition(position);
initService(selectedLanguage);
}