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.listviewanimationdemo.itemanimation.GoogleCardsActivity.java

@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle("Google Card");
    setContentView(R.layout.activity_googlecards);

    ListView listView = (ListView) findViewById(R.id.activity_googlecards_listview);

    mGoogleCardsAdapter = new GoogleCardsAdapter(this);
    SwingBottomInAnimationAdapter swingBottomInAnimationAdapter = new SwingBottomInAnimationAdapter(
            new SwipeDismissAdapter(mGoogleCardsAdapter, this));
    swingBottomInAnimationAdapter.setInitialDelayMillis(300);
    swingBottomInAnimationAdapter.setAbsListView(listView);

    listView.setAdapter(swingBottomInAnimationAdapter);

    mGoogleCardsAdapter.addAll(getItems());
}

From source file:ca.marklauman.dominionpicker.SupplyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_supply);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    ListView card_list = (ListView) findViewById(R.id.card_list);
    View loading = findViewById(android.R.id.progress);
    card_list.setEmptyView(loading);/*from  w w w .  j a  va  2 s .  c om*/
    resView = (TextView) findViewById(R.id.resources);
    resView.setVisibility(View.GONE);

    // Setup the adapter
    adapter = new CardAdapter(this);
    adapter.changeCursor(null);
    card_list.setAdapter(adapter);

    // Restore the supply if this is a restore
    supply = null;
    if (savedInstanceState != null) {
        Supply supply = savedInstanceState.getParcelable(KEY_SUPPLY);
        if (supply != null)
            setSupply(supply);

    } else {
        // No supply? Shuffle one!
        SupplyShuffler shuffler = new SupplyShuffler(this);
        // Pool must be passed as type Long not long
        long[] cards = getIntent().getExtras().getLongArray(PARAM_CARDS);
        Long[] pool = new Long[cards.length];
        for (int i = 0; i < cards.length; i++)
            pool[i] = cards[i];
        shuffler.execute(pool);
    }
}

From source file:com.example.dashclock.examplehost.ExampleHostActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);//from   w  w w.j  a va2s  . c om

    ListView listView = (ListView) findViewById(R.id.extensions);
    listView.setOnItemClickListener(this);

    try {
        mHost = new Host();
        mAdapter = new ExtensionAdapter(this, mHost, this);
        listView.setAdapter(mAdapter);
        mAdapter.notifyDataSetChanged();

    } catch (SecurityException ex) {
        Toast.makeText(this, "Not enough permissions", Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Not enough permissions", ex);
    }

    // Listen for new multiplexer package changes
    IntentFilter filter = new IntentFilter();
    filter.addAction(ACTION_MULTIPLEXER_PACKAGE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(mMultiplexerEventsReceiver, filter);

    // Set up force world-readability button
    mOnlyShowingWorldReadableExtensionsView = findViewById(R.id.only_showing_world_readable_view);
    mOnlyShowingWorldReadableExtensionsView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                startActivity(mHost.getEnableForceWorldReadabilityIntent());
            } catch (ActivityNotFoundException e) {
            }
        }
    });
}

From source file:com.android.browser.GearsSettingsDialog.java

public void setup() {
    // First let's add the permissions' resources
    LOCAL_STORAGE.setResources(R.string.settings_storage_title, R.string.settings_storage_subtitle_on,
            R.string.settings_storage_subtitle_off);
    LOCATION_DATA.setResources(R.string.settings_location_title, R.string.settings_location_subtitle_on,
            R.string.settings_location_subtitle_off);
    // add the permissions to the list of permissions.
    mPermissions = new Vector<PermissionType>();
    mPermissions.add(LOCAL_STORAGE);//ww  w . j a  v  a  2s . c o  m
    mPermissions.add(LOCATION_DATA);
    OriginPermissions.setListener(this);

    setupDialog();

    // We manage the permissions using three vectors, mSitesPermissions,
    // mOriginalPermissions and mCurrentPermissions.
    // The dialog's arguments are parsed and a list of permissions is
    // generated and stored in those three vectors.
    // mOriginalPermissions is a separate copy and will not be modified;
    // mSitesPermissions contains the current permissions _only_ --
    // if an origin is removed, it is also removed from mSitesPermissions.
    // Finally, mCurrentPermissions contains the current permissions and
    // is a clone of mSitesPermissions, but removed sites aren't removed,
    // their permissions are simply set to PERMISSION_NOT_SET. This
    // allows us to easily generate the final difference between the
    // original permissions and the final permissions, while directly
    // using mSitesPermissions for the listView adapter (SettingsAdapter).

    mSitesPermissions = new Vector<OriginPermissions>();
    mOriginalPermissions = new Vector<OriginPermissions>();

    try {
        JSONObject json = new JSONObject(mDialogArguments);
        if (json.has("permissions")) {
            JSONArray jsonArray = json.getJSONArray("permissions");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject infos = jsonArray.getJSONObject(i);
                String name = null;
                int localStorage = PermissionType.PERMISSION_NOT_SET;
                int locationData = PermissionType.PERMISSION_NOT_SET;
                if (infos.has("name")) {
                    name = infos.getString("name");
                }
                if (infos.has(LOCAL_STORAGE_STRING)) {
                    JSONObject perm = infos.getJSONObject(LOCAL_STORAGE_STRING);
                    if (perm.has("permissionState")) {
                        localStorage = perm.getInt("permissionState");
                    }
                }
                if (infos.has(LOCATION_DATA_STRING)) {
                    JSONObject perm = infos.getJSONObject(LOCATION_DATA_STRING);
                    if (perm.has("permissionState")) {
                        locationData = perm.getInt("permissionState");
                    }
                }
                OriginPermissions perms = new OriginPermissions(name);
                perms.setPermission(LOCAL_STORAGE, localStorage);
                perms.setPermission(LOCATION_DATA, locationData);

                mSitesPermissions.add(perms);
                mOriginalPermissions.add(new OriginPermissions(perms));
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, "JSON exception ", e);
    }
    mCurrentPermissions = (Vector<OriginPermissions>) mSitesPermissions.clone();

    View listView = findViewById(R.id.sites_list);
    if (listView != null) {
        ListView list = (ListView) listView;
        mListAdapter = new SettingsAdapter(mActivity, mSitesPermissions);
        list.setAdapter(mListAdapter);
        list.setScrollBarStyle(android.view.View.SCROLLBARS_OUTSIDE_INSET);
        list.setOnItemClickListener(mListAdapter);
    }
    if (mDebug) {
        printPermissions();
    }
}

From source file:com.example.android.miwok.activity.ColorsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.word_list);//from w  w  w  .  j av a  2  s .com

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    // Create a list of words
    final ArrayList<Word> words = new ArrayList<Word>();
    words.add(new Word("red", "weei", R.drawable.color_red, R.raw.color_red));
    words.add(new Word("mustard yellow", "chiwii", R.drawable.color_mustard_yellow,
            R.raw.color_mustard_yellow));
    words.add(new Word("dusty yellow", "opiis", R.drawable.color_dusty_yellow, R.raw.color_dusty_yellow));
    words.add(new Word("green", "chokokki", R.drawable.color_green, R.raw.color_green));
    words.add(new Word("brown", "akaakki", R.drawable.color_brown, R.raw.color_brown));
    words.add(new Word("gray", "opoppi", R.drawable.color_gray, R.raw.color_gray));
    words.add(new Word("black", "kululli", R.drawable.color_black, R.raw.color_black));
    words.add(new Word("white", "kelelli", R.drawable.color_white, R.raw.color_white));

    // Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The
    // adapter knows how to create list items for each item in the list.
    WordAdapter adapter = new WordAdapter(this, words);

    // Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
    // There should be a {@link ListView} with the view ID called list, which is declared in the
    // word_list.xml layout file.
    ListView listView = (ListView) findViewById(R.id.list);
    listView.setBackgroundColor(Color.parseColor("#8800A0"));
    //listView.setBackgroundColor(R.color.category_colors);

    // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
    // {@link ListView} will display list items for each {@link Word} in the list.
    listView.setAdapter(adapter);

    //plays the audio for number one when any item in the list is clicked click
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            //release current resources being used for media player if it currently exists
            //because we are about to play a different sound file.
            releaseMediaPlayer();

            //get the word located in the list that is at same position as the item clicked in the list
            Word currentWord = words.get(position);

            // Request audio focus for playback
            int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener,
                    // Use the music stream.
                    AudioManager.STREAM_MUSIC,
                    // Request temporary focus.
                    AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

            if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {

                //create the medial player with the audio file that is stored in the list for that word.
                mMediaPlayer = MediaPlayer.create(getApplicationContext(), currentWord.getmMiwokAudio());
                //play the file
                mMediaPlayer.start();

                //listener to stop and release the media player and resources being used
                // once the sounds has finished playing
                mMediaPlayer.setOnCompletionListener(mCompletionListener);
            }

        }
    });
}

From source file:au.id.tmm.anewreader.view.MainActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.activity_main_activity);

    ListView feedListView = (ListView) this.findViewById(R.id.drawer_layout_feed_list);
    this.feedArrayAdapter = new FeedArrayAdapter(this, android.R.layout.simple_list_item_1);
    feedListView.setAdapter(this.feedArrayAdapter);
    feedListView.setOnItemClickListener(onFeedListItemClickListener);

    ListView itemListView = (ListView) this.findViewById(R.id.item_list);
    this.itemArrayAdapter = new ItemArrayAdapter(this, android.R.layout.simple_list_item_1);
    itemListView.addFooterView(// w  ww  .j av a  2 s.  c o m
            this.getLayoutInflater().inflate(R.layout.adapter_view_item_list_loading_footer, null));
    itemListView.setAdapter(this.itemArrayAdapter);
    itemListView.setOnItemClickListener(onItemListItemClickListener);
    itemListView.setOnScrollListener(onItemListScrollListener);

    DisplayItems.getInstance().registerListener(this.displayItemsListener);

    pullToRefreshAttacher = PullToRefreshAttacher.get(this);
    pullToRefreshAttacher.addRefreshableView(itemListView, this.onPullToRefreshListener);
    pullToRefreshAttacher.setEnabled(false);

    this.findViewById(R.id.main_activity_error_panel).setOnClickListener(onErrorPanelClickListener);

    this.retrieveAccount();

}

From source file:com.example.android.miwok.activity.PhrasesActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.word_list);/*w w w .j  a  v  a2 s .  c  om*/

    mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);

    // Create a list of words
    final ArrayList<Word> words = new ArrayList<Word>();
    words.add(new Word("Where are you going?", "minto wuksus", R.raw.phrase_where_are_you_going));
    words.add(new Word("What is your name?", "tinn oyaase'n", R.raw.phrase_what_is_your_name));
    words.add(new Word("My name is...", "oyaaset...", R.raw.phrase_my_name_is));
    words.add(new Word("How are you feeling?", "michkss?", R.raw.phrase_how_are_you_feeling));
    words.add(new Word("Im feeling good.", "kuchi achit", R.raw.phrase_im_feeling_good));
    words.add(new Word("Are you coming?", "ns'aa?", R.raw.phrase_are_you_coming));
    words.add(new Word("Yes, Im coming.", "h nm", R.raw.phrase_yes_im_coming));
    words.add(new Word("Im coming.", "nm", R.raw.phrase_im_coming));
    words.add(new Word("Lets go.", "yoowutis", R.raw.phrase_lets_go));
    words.add(new Word("Come here.", "nni'nem", R.raw.phrase_come_here));

    // Create an {@link WordAdapter}, whose data source is a list of {@link Word}s. The
    // adapter knows how to create list items for each item in the list.
    WordAdapter adapter = new WordAdapter(this, words);

    // Find the {@link ListView} object in the view hierarchy of the {@link Activity}.
    // There should be a {@link ListView} with the view ID called list, which is declared in the
    // word_list.xml layout file.
    ListView listView = (ListView) findViewById(R.id.list);
    listView.setBackgroundColor(Color.parseColor("#16AFCA"));
    //listView.setBackgroundColor(R.color.category_phrases);

    // Make the {@link ListView} use the {@link WordAdapter} we created above, so that the
    // {@link ListView} will display list items for each {@link Word} in the list.
    listView.setAdapter(adapter);

    //plays the audio for number one when any item in the list is clicked click
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            //release current resources being used for media player if it currently exists
            //because we are about to play a different sound file.
            releaseMediaPlayer();

            //get the word located in the list that is at same position as the item clicked in the list
            Word currentWord = words.get(position);

            /// Request audio focus for playback
            int result = mAudioManager.requestAudioFocus(mAudioFocusChangeListener,
                    // Use the music stream.
                    AudioManager.STREAM_MUSIC,
                    // Request temporary focus.
                    AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

            if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {

                //create the medial player with the audio file that is stored in the list for that word.
                mMediaPlayer = MediaPlayer.create(getApplicationContext(), currentWord.getmMiwokAudio());
                //play the file
                mMediaPlayer.start();

                //listener to stop and release the media player and resources being used
                // once the sounds has finished playing
                mMediaPlayer.setOnCompletionListener(mCompletionListener);
            }
        }
    });
}

From source file:com.example.app.tweetui.TimelineActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tweetui_swipe_timeline);
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setTitle(R.string.refresh_timeline_title);
    }/*w  w  w .j a v a2s . c o m*/

    // launch the app login activity when a guest user tries to favorite a Tweet
    final Callback<Tweet> actionCallback = new Callback<Tweet>() {
        @Override
        public void success(Result<Tweet> result) {
            // Intentionally blank
        }

        @Override
        public void failure(TwitterException exception) {
            if (exception instanceof TwitterAuthException) {
                startActivity(TwitterCoreMainActivity.newIntent(TimelineActivity.this));
            }
        }
    };

    final SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_layout);
    final View emptyView = findViewById(android.R.id.empty);
    final ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setEmptyView(emptyView);

    final SearchTimeline timeline = new SearchTimeline.Builder().query("#twitter").build();
    final TweetTimelineListAdapter adapter = new TweetTimelineListAdapter.Builder(this).setTimeline(timeline)
            .setViewStyle(R.style.tw__TweetLightWithActionsStyle).setOnActionCallback(actionCallback).build();
    listView.setAdapter(adapter);

    swipeLayout.setColorSchemeResources(R.color.twitter_blue, R.color.twitter_dark);

    // set custom scroll listener to enable swipe refresh layout only when at list top
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        boolean enableRefresh = false;

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (listView != null && listView.getChildCount() > 0) {
                // check that the first item is visible and that its top matches the parent
                enableRefresh = listView.getFirstVisiblePosition() == 0 && listView.getChildAt(0).getTop() >= 0;
            } else {
                enableRefresh = false;
            }
            swipeLayout.setEnabled(enableRefresh);
        }
    });

    // specify action to take on swipe refresh
    swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            swipeLayout.setRefreshing(true);
            adapter.refresh(new Callback<TimelineResult<Tweet>>() {
                @Override
                public void success(Result<TimelineResult<Tweet>> result) {
                    swipeLayout.setRefreshing(false);
                }

                @Override
                public void failure(TwitterException exception) {
                    swipeLayout.setRefreshing(false);
                    final Activity activity = activityRef.get();
                    if (activity != null && !activity.isFinishing()) {
                        Toast.makeText(activity, exception.getMessage(), Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
    });
}

From source file:com.example.venkatagovardhan.docorganizer.FolderActivity.java

void loadFavourites(FavouritesManager favouritesManager) {
    ListView listNavigation = (ListView) findViewById(R.id.listNavigation);
    NavDrawerAdapter navDrawerAdapter = new NavDrawerAdapter(this,
            new ArrayList<NavDrawerAdapter.NavDrawerItem>(favouritesManager.getFolders()));
    navDrawerAdapter.setFontApplicator(fontApplicator);
    listNavigation.setAdapter(navDrawerAdapter);
    listNavigation.setOnItemClickListener(this);
}

From source file:com.android.talkbacktests.testsession.PopupViewTest.java

/**
 * Shows a PopupWindow at the anchor view with given window height and list size.
 *///from w  ww  . j a  v  a  2  s  .c o m
private void showPopupWindow(View button, int height, int listSize, boolean useDefaultInflater) {
    final Context context = button.getContext();
    final ListView listView = new ListView(context);
    final BaseAdapter adapter;
    if (useDefaultInflater) {
        adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, android.R.id.text1,
                createSampleArray(listSize));
    } else {
        adapter = new MyAdapter(button.getContext(), createSampleArray(listSize));
    }
    listView.setAdapter(adapter);

    listView.setVerticalScrollBarEnabled(true);
    listView.setBackgroundColor(0xFFFFFF);
    final PopupWindow window = new PopupWindow(listView, ViewGroup.LayoutParams.WRAP_CONTENT, height, true);
    window.setBackgroundDrawable(context.getResources().getDrawable(android.R.drawable.editbox_background));
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            if (window.isShowing()) {
                window.dismiss();
            }
        }
    });
    PopupWindowCompat.showAsDropDown(window, button, 0, 0, Gravity.NO_GRAVITY);
}