Example usage for android.widget ListView getAdapter

List of usage examples for android.widget ListView getAdapter

Introduction

In this page you can find the example usage for android.widget ListView getAdapter.

Prototype

@Override
public ListAdapter getAdapter() 

Source Link

Document

Returns the adapter currently in use in this ListView.

Usage

From source file:com.adhi.quantumthemer.aFileChooser.FileListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    FileListAdapter adapter = (FileListAdapter) l.getAdapter();
    if (adapter != null) {
        File file = (File) adapter.getItem(position);
        mPath = file.getAbsolutePath();/*from ww  w  . j a  va 2 s  .  co m*/
        ((FileChooserActivity) getActivity()).onFileSelected(file);
    }
}

From source file:org.androidsoft.app.permission.ui.ApplicationsListFragment.java

/**
 * {@inheritDoc }/*from  w w w. ja v  a 2  s.com*/
 */
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Adapter adapter = l.getAdapter();
    AppInfo app = (AppInfo) adapter.getItem(position);
    mContainerCallback.onAppSelected(app.getPackageName());
}

From source file:com.franceaoc.app.ui.fragment.NearestCommunesListFragment.java

/**
 * {@inheritDoc }//from  w  ww .  j  av  a  2  s  .  c  o m
 */
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    Adapter adapter = l.getAdapter();
    Commune commune = (Commune) adapter.getItem(position);
    mContainerCallback.onCommuneSelected(commune.getId());
}

From source file:org.wheelmap.android.fragment.NodetypeSelectFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    CategoryOrNodeType item = (CategoryOrNodeType) l.getAdapter().getItem(position);
    switch (item.type) {
    case NODETYPE:
        mNodeTypeSelected = item.id;//from   w ww .  j  a  v a  2  s  .c om

        Intent intent = getActivity().getIntent();
        intent.putExtra(Extra.NODETYPE, mNodeTypeSelected);
        getActivity().setResult(android.app.Activity.RESULT_OK, intent);
        getActivity().finish();
        break;
    }
}

From source file:com.lolay.android.ui.LolayBaseFragmentActivity.java

/**
 * Thanks to http://nex-otaku-en.blogspot.com/2010/12/android-put-listview-in-scrollview.html
 * WARNING: Only works with Linear Layouts or you'll get a NullPointerException in the measure code
 *//*w w  w .j av  a 2  s. c  o  m*/
public void listViewSetHeightFromChildren(ListView listView) {
    ListAdapter listAdapter = listView.getAdapter();
    if (listAdapter == null) {
        // pre-condition
        return;
    }

    int totalHeight = 0;
    int desiredWidth = View.MeasureSpec.makeMeasureSpec(listView.getWidth(), View.MeasureSpec.AT_MOST);
    for (int i = 0; i < listAdapter.getCount(); i++) {
        View listItem = listAdapter.getView(i, null, listView);
        listItem.measure(desiredWidth, View.MeasureSpec.UNSPECIFIED);
        totalHeight += listItem.getMeasuredHeight();
    }

    ViewGroup.LayoutParams params = listView.getLayoutParams();
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
    listView.setLayoutParams(params);
    listView.requestLayout();
}

From source file:answer.example.answer.view.FileListFragment.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    FileListAdapter adapter = (FileListAdapter) l.getAdapter();
    if (adapter != null) {
        File file = (File) adapter.getItem(position);
        mPath = file.getAbsolutePath();/*from   w ww. j  a  va  2  s.c o m*/
        mListener.onFileSelected(file);
    }
}

From source file:com.eyekabob.CheckinSearchList.java

public void loadData(JSONObject data) {
    try {/*  w ww.j a va 2 s .  c  om*/
        JSONObject response = data.getJSONObject("response");
        ListView lv = (ListView) findViewById(R.id.adList);
        VenueListAdapter adapter = (VenueListAdapter) lv.getAdapter();
        JSONArray venues = response.getJSONArray("venues");
        for (int i = 0; i < venues.length(); i++) {
            JSONObject placeData = venues.getJSONObject(i);
            Venue venue = new Venue();
            venue.setName(placeData.optString("name"));
            venue.setId(placeData.optString("id"));
            JSONObject location = placeData.optJSONObject("location");
            if (location != null) {
                venue.setCity(location.optString("city"));
                venue.setStreet(location.optString("address"));
                venue.setPostalCode(location.optString("postalCode"));
                venue.setCountry(location.optString("country"));
            }
            adapter.add(venue);
        }
    } catch (JSONException e) {
        Toast.makeText(this, "Could not get nearby places", Toast.LENGTH_SHORT).show();
        Log.e(getClass().getName(), "Unable to parse JSON response", e);
    }
}

From source file:au.org.ala.fielddata.mobile.SpeciesListActivity.java

@Override
public void onListItemClick(ListView l, View v, int position, long id) {

    Species species = ((SpeciesAdapter) l.getAdapter()).getSpecies(position);
    onSpeciesSelected(species);/*from   w  ww. jav  a 2s.  co  m*/

}

From source file:fm.krui.kruifm.WordpressViewer.java

@Override
public void onListItemClick(ListView lv, View view, int position, long id) {

    // Get the article for this position
    Article article = (Article) lv.getAdapter().getItem(position);

    // Pass it to the viewer activity as an intent
    Intent intent = new Intent(getActivity(), ArticleViewActivity.class);
    intent.putExtra(article.ARTICLE_INTENT, article);
    startActivity(intent);//from   ww w .j a v  a2s  . c  o  m

}

From source file:com.moonpi.tapunlock.MainActivity.java

public static void updateListViewHeight(ListView myListView) {
    ListAdapter myListAdapter = myListView.getAdapter();

    if (myListAdapter == null)
        return;/*from  w  ww  .  j a  v a 2 s .c  o m*/

    // Get listView height
    int totalHeight = myListView.getPaddingTop() + myListView.getPaddingBottom();
    int adapterCount = myListAdapter.getCount();

    for (int i = 0; i < adapterCount; i++) {
        View listItem = myListAdapter.getView(i, null, myListView);

        if (listItem instanceof ViewGroup) {
            listItem.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
        }

        listItem.measure(0, 0);
        totalHeight += listItem.getMeasuredHeight();
    }

    // Change height of listView
    ViewGroup.LayoutParams paramsList = myListView.getLayoutParams();
    paramsList.height = totalHeight + (myListView.getDividerHeight() * (adapterCount - 1));
    myListView.setLayoutParams(paramsList);
}