Example usage for android.widget ListView setAdapter

List of usage examples for android.widget ListView setAdapter

Introduction

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

Prototype

@Override
public void setAdapter(ListAdapter adapter) 

Source Link

Document

Sets the data behind this ListView.

Usage

From source file:com.example.android.uamp.ui.PlaceholderActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_placeholder);
    initializeToolbar();//ww  w.ja v  a 2 s. com

    mPlaylist = Playlist.getInstance();

    int size = mPlaylist.size();
    Log.i(TAG, "mPlaylist has size " + Integer.toString(size));

    mBrowserAdapter = new BrowseAdapter(this);
    mBrowserAdapter.addAll(mPlaylist.retrieveList());

    ListView listView = (ListView) findViewById(R.id.playlist);
    listView.setAdapter(mBrowserAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            MediaBrowserCompat.MediaItem item = mBrowserAdapter.getItem(position);
            LogHelper.d(TAG, "onItemClick, mediaId=" + item.getMediaId());
            if (item.isPlayable()) {
                getSupportMediaController().getTransportControls().playFromMediaId(item.getMediaId(), null);
            }
        }
    });
}

From source file:be.brunoparmentier.openbikesharing.app.fragments.StationsListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_stations_list, container, false);
    ListView listView = (ListView) view.findViewById(R.id.stationsListView);
    listView.setAdapter(stationsListAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override// w w w.ja  v  a 2  s . co m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Intent intent = new Intent(getActivity(), StationActivity.class);
            intent.putExtra("station", stations.get(position));
            startActivity(intent);
        }
    });
    return view;
}

From source file:com.androidexample.chandigarhexplore.CinemasFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.place_list, container, false);
    // Create a list of places
    final ArrayList<Place> places = new ArrayList<Place>();
    places.add(new Place(R.string.cinema_pvr, R.string.cinema_pvr_1, R.string.cinema_pvr_2,
            R.drawable.cinema_pvr, 30.7050649, 76.7929105));
    places.add(new Place(R.string.cinema_hyperx, R.string.cinema_hyperx_1, R.string.cinema_hyperx_2,
            R.drawable.cinema_hyperx, 30.7050652, 76.7994766));
    places.add(new Place(R.string.cinema_fun, R.string.cinema_fun_1, R.string.cinema_fun_2,
            R.drawable.cinema_fun, 30.7278498, 76.7973474));
    places.add(new Place(R.string.cinema_wave, R.string.cinema_wave_1, R.string.cinema_wave_2,
            R.drawable.cinema_wave, 30.7095765, 76.7988023));

    PlaceAdapter adapter = new PlaceAdapter(getActivity(), places, R.color.white_font);

    ListView listView = (ListView) rootView.findViewById(R.id.list);

    listView.setAdapter(adapter);

    //Sending values to the IndividualInfo Activity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from   ww  w.j a v  a 2  s  . com
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Place current = places.get(position);
            Intent details = new Intent(getActivity(), IndividualInfoActivity.class);
            details.putExtra("location", current.getLocationId());
            details.putExtra("locationAdd1", current.getAddressOneId());
            details.putExtra("locationAdd2", current.getAddressTwoId());
            details.putExtra("locationLon", current.getLongitudeId());
            details.putExtra("locationLat", current.getLatitudeId());
            details.putExtra("locationImage", current.getPlaceImageId());
            startActivity(details);
        }

    });

    return rootView;
}

From source file:com.androidexample.chandigarhexplore.MallsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.place_list, container, false);
    // Create a list of places0000000000000000
    final ArrayList<Place> places = new ArrayList<Place>();
    places.add(new Place(R.string.mall_elante, R.string.mall_elante_1, R.string.mall_elante_2,
            R.drawable.mall_elante_mall, 30.7063869, 76.7947165));
    places.add(new Place(R.string.mall_picad, R.string.mall_picad_1, R.string.mall_picad_2,
            R.drawable.mall_pieca_mall, 30.7235273, 76.7652874));
    places.add(new Place(R.string.mall_north, R.string.mall_north_1, R.string.mall_north_2,
            R.drawable.mall_north_country_mall, 30.73771, 76.6763393));
    places.add(new Place(R.string.mall_adarsh, R.string.mall_adarsh_1, R.string.mall_adarsh_2,
            R.drawable.mall_adardh_mall, 30.7004869, 76.7859671));

    PlaceAdapter adapter = new PlaceAdapter(getActivity(), places, R.color.white_font);

    ListView listView = (ListView) rootView.findViewById(R.id.list);

    listView.setAdapter(adapter);

    //Sending values to the IndividualInfo Activity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from w  w  w  .  ja v  a2 s.  com
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Place current = places.get(position);
            Intent details = new Intent(getActivity(), IndividualInfoActivity.class);
            details.putExtra("location", current.getLocationId());
            details.putExtra("locationAdd1", current.getAddressOneId());
            details.putExtra("locationAdd2", current.getAddressTwoId());
            details.putExtra("locationLon", current.getLongitudeId());
            details.putExtra("locationLat", current.getLatitudeId());
            details.putExtra("locationImage", current.getPlaceImageId());
            startActivity(details);
        }

    });

    return rootView;
}

From source file:com.androidexample.chandigarhexplore.TourismFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.place_list, container, false);
    // Create a list of places
    final ArrayList<Place> places = new ArrayList<Place>();
    places.add(new Place(R.string.tourism_rock, R.string.tourism_rock_1, R.string.tourism_rock_2,
            R.drawable.tourism_rock_garden, 30.753491, 76.805420));
    places.add(new Place(R.string.tourism_rose, R.string.tourism_rose_1, R.string.tourism_rose_2,
            R.drawable.tourism_rose_garden, 30.746108, 76.781981));
    places.add(new Place(R.string.tourism_sukhna, R.string.tourism_sukhna_1, R.string.tourism_sukhna_2,
            R.drawable.tourism_sukhna_lake, 30.7421, 76.8188));
    places.add(new Place(R.string.tourism_doll, R.string.tourism_doll_1, R.string.tourism_doll_2,
            R.drawable.tourism_international_doll_museum, 30.7416, 76.7708));

    PlaceAdapter adapter = new PlaceAdapter(getActivity(), places, R.color.white_font);

    ListView listView = (ListView) rootView.findViewById(R.id.list);

    listView.setAdapter(adapter);

    //Sending values to the IndividualInfo Activity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//ww  w.  j a v  a2s.com
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Place current = places.get(position);
            Intent details = new Intent(getActivity(), IndividualInfoActivity.class);
            details.putExtra("location", current.getLocationId());
            details.putExtra("locationAdd1", current.getAddressOneId());
            details.putExtra("locationAdd2", current.getAddressTwoId());
            details.putExtra("locationLon", current.getLongitudeId());
            details.putExtra("locationLat", current.getLatitudeId());
            details.putExtra("locationImage", current.getPlaceImageId());
            startActivity(details);
        }

    });

    return rootView;
}

From source file:br.pro.menotti.opus.pt.DisplayBooks.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    SQLiteHelper db;/*from  w w w .  j a v a  2 s .  com*/
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    db = new SQLiteHelper(this);
    db.openDataBase();

    List<Book> books = new ArrayList<Book>();
    books = db.getBooks();
    db.close();

    ListView lv = (ListView) findViewById(android.R.id.list);

    lv.setAdapter(new ArrayAdapter<Book>(this, android.R.layout.simple_list_item_1, books));

    Toast.makeText(getApplicationContext(), (getString(R.string.display_aleatory_point)), Toast.LENGTH_SHORT)
            .show();

    lv.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            showPoints(position);
        }
    });

    lv.setOnItemLongClickListener(new OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            SQLiteHelper db;
            db = new SQLiteHelper(getBaseContext());
            db.openDataBase();
            BookPoint bp = db.getBookPoint(position);
            DialogFragment newFragment = new DialogPoint(bp);
            newFragment.show(getSupportFragmentManager(), bp.toString());
            db.close();
            return true;
        }
    });
}

From source file:com.beter.timehole.fragments.HelpFragment.java

@Nullable
@Override/*from  w  w w  .j  a v  a 2  s  .c o  m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View helpRootView = inflater.inflate(R.layout.help_fragment, container, false);

    String[] list = { "How to Use?", "FAQ", "End-User License Agreement", "Troubleshooting", "Send Feedback",
            "AboutUs" };
    ListView helpList = (ListView) helpRootView.findViewById(R.id.helpList);
    helpList.setAdapter(new ArrayAdapter(getActivity(), R.layout.support_simple_spinner_dropdown_item, list));

    helpList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            if (position == 0) {
                Intent howToUseIntent = new Intent(getActivity(), HowToUseActivity.class);
                startActivity(howToUseIntent);
            } else if (position == 1) {
                Intent FAQIntent = new Intent(getActivity(), FAQActivity.class);
                startActivity(FAQIntent);
            } else if (position == 2) {
                Intent EULAIntent = new Intent(getActivity(), EULAActivity.class);
                startActivity(EULAIntent);
            } else if (position == 3) {
                Intent TSIntent = new Intent(getActivity(), TroubleshootingActivity.class);
                startActivity(TSIntent);
            } else if (position == 4) {
                Intent SendFeedbackIntent = new Intent(getActivity(), SendFeedbackActivity.class);
                startActivity(SendFeedbackIntent);
            } else if (position == 5) {
                Intent AboutUsIntent = new Intent(getActivity(), AboutUsActivity.class);
                startActivity(AboutUsIntent);
            }
        }
    });

    return helpRootView;
}

From source file:com.androidexample.chandigarhexplore.RestaurantsFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.place_list, container, false);
    // Create a list of places
    final ArrayList<Place> places = new ArrayList<Place>();
    places.add(new Place(R.string.restaurant_swag, R.string.restaurant_swag_1, R.string.restaurant_swag_2,
            R.drawable.restaurant_swagath, 30.72851, 76.8021428));
    places.add(new Place(R.string.restaurant_virgin, R.string.restaurant_virgin_1, R.string.restaurant_virgin_2,
            R.drawable.restaurant_virgin, 30.7343645, 76.7953791));
    places.add(new Place(R.string.restaurant_pirates, R.string.restaurant_pirates_1,
            R.string.restaurant_pirates_2, R.drawable.restaurant_pirates, 30.7059303, 76.7985013));
    places.add(new Place(R.string.restaurant_china, R.string.restaurant_china_1, R.string.restaurant_china_2,
            R.drawable.restaurant_mainland, 30.725223, 76.8034613));
    places.add(new Place(R.string.restaurant_delux, R.string.restaurant_delux_1, R.string.restaurant_delux_2,
            R.drawable.restaurant_delux, 30.7160944, 76.8027994));

    PlaceAdapter adapter = new PlaceAdapter(getActivity(), places, R.color.white_font);

    ListView listView = (ListView) rootView.findViewById(R.id.list);

    listView.setAdapter(adapter);

    //Sending values to the IndividualInfo Activity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*  w ww.j  av a  2  s .c  o m*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Place current = places.get(position);
            Intent details = new Intent(getActivity(), IndividualInfoActivity.class);
            details.putExtra("location", current.getLocationId());
            details.putExtra("locationAdd1", current.getAddressOneId());
            details.putExtra("locationAdd2", current.getAddressTwoId());
            details.putExtra("locationLon", current.getLongitudeId());
            details.putExtra("locationLat", current.getLatitudeId());
            details.putExtra("locationImage", current.getPlaceImageId());
            startActivity(details);
        }

    });

    return rootView;
}

From source file:com.eyekabob.ArtistList.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.adlistactivity);
    adapter = new ArtistListAdapter(getApplicationContext());
    ListView lv = (ListView) findViewById(R.id.adList);
    lv.setAdapter(adapter);
    lv.setOnItemClickListener(listItemListener);
    String artist = getIntent().getExtras().getString("artist");
    if (artist != null) {
        artist = artist.trim();/*from  w ww  .  j a v  a 2s. co  m*/
    }

    // Send last.fm request.
    Map<String, String> lastFMParams = new HashMap<String, String>();
    lastFMParams.put("artist", artist);
    Uri lastFMUri = EyekabobHelper.LastFM.getUri("artist.search", lastFMParams);
    new LastFMRequestTask().execute(lastFMUri.toString());
}

From source file:com.survivingwithandroid.tutorial.asynclistview.MainActivity.java

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

    adpt = new SimpleAdapter(new ArrayList<Contact>(), this);
    ListView lView = (ListView) findViewById(R.id.listview);

    lView.setAdapter(adpt);

    // Exec async load task
    (new AsyncListViewLoader()).execute("http://10.0.2.2:8080/JSONServer/rest/ContactWS/get");
}