Example usage for android.widget AdapterView getItemAtPosition

List of usage examples for android.widget AdapterView getItemAtPosition

Introduction

In this page you can find the example usage for android.widget AdapterView getItemAtPosition.

Prototype

public Object getItemAtPosition(int position) 

Source Link

Document

Gets the data associated with the specified position in the list.

Usage

From source file:com.nachtimwald.android.serviceexplorer.ServiceListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_servicelist, container, false);
    ListView lv = (ListView) view.findViewById(R.id.serviceList);

    List<Map<String, String>> serviceData = new ArrayList<>();

    if (getArguments().getBoolean("allServices")) {
        for (PackageInfo packageInfo : getActivity().getPackageManager()
                .getInstalledPackages(PackageManager.GET_SERVICES)) {
            if (packageInfo.services == null) {
                continue;
            }/*  w  w w  . j  a  va2s. c o m*/
            for (ServiceInfo serviceInfo : packageInfo.services) {
                Map<String, String> datum = new HashMap<>();
                datum.put("name", serviceInfo.name);
                datum.put("package", serviceInfo.packageName);
                datum.put("search", serviceInfo.name.replace(".", " ").replace("$", " "));
                serviceData.add(datum);
            }
        }
    } else {
        ActivityManager activityManager = (ActivityManager) getActivity()
                .getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningServiceInfo> runningServiceInfos = activityManager
                .getRunningServices(Integer.MAX_VALUE);
        for (ActivityManager.RunningServiceInfo info : runningServiceInfos) {
            Map<String, String> datum = new HashMap<>();
            datum.put("name", info.service.getClassName());
            datum.put("package", info.service.getPackageName());
            datum.put("search", info.service.getClassName().replace(".", " ").replace("$", " "));
            serviceData.add(datum);
        }
    }

    mServicesAdapter = new SimpleAdapter(getActivity(), serviceData, android.R.layout.simple_list_item_2,
            new String[] { "name", "package", "search" },
            new int[] { android.R.id.text1, android.R.id.text2, 0 });
    lv.setAdapter(mServicesAdapter);

    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent i = new Intent(getActivity(), DetailActivity.class);
            i.putExtra("name", ((HashMap<String, String>) parent.getItemAtPosition(position)).get("name"));
            i.putExtra("package",
                    ((HashMap<String, String>) parent.getItemAtPosition(position)).get("package"));
            startActivity(i);
        }
    });

    if (savedInstanceState != null) {
        lv.onRestoreInstanceState(savedInstanceState.getParcelable(STATE_LISTPOS));
    }

    return view;
}

From source file:org.jboss.aerogear.android.cookbook.aerodoc.ui.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    application = (AeroDocApplication) getApplication();

    contentPanel = findViewById(R.id.contentPanel);

    availableLeadsFragments = new AvailableLeadsFragments();
    acceptedLeadsFragments = new AcceptedLeadsFragments();

    // -- Dropdown (Status)

    Spinner spinner = (Spinner) findViewById(R.id.status);

    ArrayAdapter<String> spinnerAdapter = (ArrayAdapter) spinner.getAdapter();
    int actualStatus = spinnerAdapter.getPosition(application.getSaleAgent().getStatus());
    spinner.setSelection(actualStatus, true);

    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override//w  w w.  jav  a  2 s  .com
        public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
            String status = (String) adapterView.getItemAtPosition(position);
            if (!application.getSaleAgent().getStatus().equals(status)) {
                updateStatus(status);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
        }
    });

    // -- Tabs (Leads - Available & Archived)

    ViewPager pager = (ViewPager) findViewById(R.id.pager);
    TabLayout tabs = (TabLayout) findViewById(R.id.tabs);

    pager.setAdapter(new ViewPagerAdapter(getSupportFragmentManager()));
    tabs.setupWithViewPager(pager);
}

From source file:am.roadpolice.roadpolice.ViolationInfoActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    // Get selected Violation Info Item.
    ViolationInfo violationInfo = (ViolationInfo) parent.getItemAtPosition(position);
    // Create a Bundle object to pass some data to Dialog Action.
    Bundle bundle = new Bundle();
    bundle.putBoolean(ActionDialogFragment.EXTRA_IS_PAYED, violationInfo.isPayed());
    bundle.putString(ActionDialogFragment.EXTRA_PIN, violationInfo.getPin());

    ActionDialogFragment dialog = (ActionDialogFragment) getSupportFragmentManager()
            .findFragmentByTag("action_dialog");
    if (dialog == null)
        dialog = new ActionDialogFragment();

    dialog.setCancelable(false);//from   www.ja va 2s.  c om
    dialog.setArguments(bundle);
    // Start showing progress dialog fragment.
    FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
    transaction.add(dialog, "action_dialog");
    transaction.commitAllowingStateLoss();
}

From source file:com.mattprecious.notisync.fragment.StandardProfileListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.standard_list, container, false);

    ArrayList<ProfileType> titles = new ArrayList<ProfileType>();
    titles.add(ProfileType.TEXT);/*from w  w  w . j  a v a 2s  .  c  o  m*/
    titles.add(ProfileType.PHONE);
    titles.add(ProfileType.GTALK);

    listAdapter = new StandardProfileAdapter(getActivity(), titles);

    listView = (ListView) view.findViewById(R.id.list);
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ProfileType type = (ProfileType) parent.getItemAtPosition(position);

            Intent intent = new Intent();
            intent.setClass(getActivity(), StandardProfileActivity.class);
            intent.putExtra(StandardProfileActivity.EXTRA_TYPE, type);

            getActivity().startActivityForResult(intent, MainActivity.REQUEST_CODE_EDIT_PROFILE);
        }
    });

    return view;
}

From source file:com.facebook.samples.socialcafe.MenuFragmentActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.main_menu, parent, false);
    getActivity().setTitle(R.string.menu);

    userNameView = (TextView) v.findViewById(R.id.user_name);
    userPicView = (ImageView) v.findViewById(R.id.user_pic);
    if (userName != null) {
        userNameView.setText(userName);//from  w w  w . j  av  a  2s  .  co  m
    }
    if (userPic != null) {
        userPicView.setImageBitmap(userPic);
    }
    ListView drinkList = (ListView) v.findViewById(R.id.menu_list);
    drinkList.setAdapter(new DrinkListAdapter());

    drinkList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
            Drink drink = (Drink) arg0.getItemAtPosition(position);
            Intent orderIntent = new Intent(getActivity(), OrderDrinkActivity.class);
            orderIntent.putExtra("DRINK_URL", drink.getURL());
            startActivity(orderIntent);
        }

    });

    return v;
}

From source file:com.vrs.reqdroid.fragments.DependenciasFragment.java

/**
 * Configura o texto dos dois requisitos selecionados nas listas de selecao.
 *//*  w  w  w.  j av a 2s.co  m*/
private void selecionaRequisitosSpinners() {
    final TextView tvRequisitoSelecionado1 = (TextView) rootView.findViewById(R.id.requisitoSelecionado1);
    final TextView tvRequisitoSelecionado2 = (TextView) rootView.findViewById(R.id.requisitoSelecionado2);
    final String titulo = getResources().getString(R.string.tela_detalhes_requisito_nome_requisito);

    spinnerPrimeiroRequisito.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View v, int posicao, long id) {
            //pega nome pela posicao
            primeiroRequisitoSelecionado = (Integer) parent.getItemAtPosition(posicao);
            tvRequisitoSelecionado1.setText(titulo + String.valueOf(primeiroRequisitoSelecionado));
        }

        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });

    spinnerSegundoRequisito.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View v, int posicao, long id) {
            segundoRequisitoSelecionado = (Integer) parent.getItemAtPosition(posicao);
            tvRequisitoSelecionado2.setText(titulo + String.valueOf(segundoRequisitoSelecionado));
        }

        public void onNothingSelected(AdapterView<?> arg0) {
        }
    });
}

From source file:es.usc.citius.servando.calendula.activities.PatientsActivity.java

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    Patient item = (Patient) parent.getItemAtPosition(position);

    Intent intent = new Intent(this, PatientDetailActivity.class);
    intent.putExtra("patient_id", item.id());

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        ActivityOptionsCompat activityOptions = ActivityOptionsCompat.makeSceneTransitionAnimation(this,
                new Pair<>(view.findViewById(R.id.patient_avatar), "transition"),
                new Pair<>(findViewById(R.id.add_button), "fab"));
        ActivityCompat.startActivity(this, intent, activityOptions.toBundle());
    } else/*  w  w w  . j  av  a2  s . c o  m*/
        startActivity(intent);
}

From source file:com.vuze.android.remote.dialog.DialogFragmentMoveData.java

private void setupVars(View view) {
    Bundle args = getArguments();// www.ja  v a2 s . com
    String name = args.getString("name");
    torrentId = args.getLong("id");
    String downloadDir = args.getString("downloadDir");
    history = args.getStringArrayList("history");

    ArrayList<String> newHistory = new ArrayList<>();
    if (history != null) {
        newHistory.addAll(history);
    }

    if (downloadDir != null && !newHistory.contains(downloadDir)) {
        if (newHistory.size() > 1) {
            newHistory.add(1, downloadDir);
        } else {
            newHistory.add(downloadDir);
        }
    }

    etLocation = (EditText) view.findViewById(R.id.movedata_editview);
    if (downloadDir != null) {
        etLocation.setText(downloadDir);
    }
    ListView lvHistory = (ListView) view.findViewById(R.id.movedata_historylist);
    cbRememberLocation = (CheckBox) view.findViewById(R.id.movedata_remember);
    TextView tv = (TextView) view.findViewById(R.id.movedata_label);

    tv.setText(getResources().getString(R.string.movedata_label, name));

    ArrayAdapter<String> adapter = new ArrayAdapter<>(view.getContext(), R.layout.list_view_small_font,
            newHistory);
    lvHistory.setAdapter(adapter);

    lvHistory.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, final View view, int position, long id) {
            Object item = parent.getItemAtPosition(position);

            if (item instanceof String) {
                etLocation.setText((String) item);
            }
        }
    });

}

From source file:universe.constellation.orion.viewer.OrionFileManagerActivity.java

private void createRecentView(ListFragment list) {
    ListView recent = list.getListView();
    if (showRecentsAndSavePath()) {
        recent.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                GlobalOptions.RecentEntry entry = (GlobalOptions.RecentEntry) parent
                        .getItemAtPosition(position);
                File file = new File(entry.getPath());
                if (file.exists()) {
                    openFile(file);/*www .ja v a  2s  .  c  o  m*/
                }
            }
        });

        list.setListAdapter(new FileChooser(this, globalOptions.getRecentFiles()));
    } else {
        recent.setVisibility(View.GONE);
    }
}

From source file:com.skubit.iab.fragments.TransactionsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_wallet_transactions, null);

    TextView balanceLabel = (TextView) view.findViewById(R.id.wallet_balance_label);
    balanceLabel.setTypeface(FontManager.CONDENSED_REGULAR);

    TextView availableLabel = (TextView) view.findViewById(R.id.wallet_available_label);
    availableLabel.setTypeface(FontManager.CONDENSED_REGULAR);

    mBalance = (TextView) view.findViewById(R.id.wallet_balance);
    mAvailable = (TextView) view.findViewById(R.id.wallet_available);

    ListView list = (ListView) view.findViewById(R.id.list);
    list.setAdapter(mAdapter);//  w  w w. j a  v  a  2  s.c  o m

    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapter, View arg1, int position, long arg3) {
            TransactionDto transactionDto = (TransactionDto) adapter.getItemAtPosition(position);
            ObjectMapper mapper = new ObjectMapper();
            String value;
            try {
                value = mapper.writeValueAsString(transactionDto);
                startActivity(TransactionDetailsActivity.newIntent(value, getActivity().getPackageName()));
                getActivity().overridePendingTransition(R.anim.pull_in_right, R.anim.none);
            } catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }

    });

    mSwipe = (SwipeRefreshLayout) view.findViewById(R.id.swipe_refresh);

    mSwipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refreshBalance();
            getTransactions();
        }
    });

    return view;
}