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:by.gdgminsk.animationguide.GuideMainMenuActivity.java

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

    ListView samples = (ListView) findViewById(R.id.samples);
    samples.setOnItemClickListener(this);
    mSamplesAdapter = new SamplesAdapter(this);
    samples.setAdapter(mSamplesAdapter);
}

From source file:com.blandware.android.atleap.sample.ui.MasterFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    SimpleCursorAdapterLoadable adapter = new SimpleCursorAdapterLoadable(getActivity(),
            DefaultContract.CONTENT_URI_REPOSITORIES_USERS,
            new String[] {
                    DefaultContract.Repository.TABLE + "." + DefaultContract.Repository._ID + " AS "
                            + DefaultContract.Repository._ID,
                    DefaultContract.User.AVATAR_URL, DefaultContract.Repository.FULL_NAME,
                    DefaultContract.Repository.STARGAZERS_COUNT, DefaultContract.Repository.DESCRIPTION },
            null, //selection
            null, //selectionArgs
            DefaultContract.Repository.STARGAZERS_COUNT + " DESC", //sortOrder
            R.layout.listitem_repository,
            new String[] { DefaultContract.User.AVATAR_URL, DefaultContract.Repository.FULL_NAME,
                    DefaultContract.Repository.STARGAZERS_COUNT, DefaultContract.Repository.DESCRIPTION },
            new int[] { R.id.avatar_url, R.id.full_name, R.id.stargazers_count, R.id.description });
    LoaderManagerCreator loaderManagerCreator = new LoaderManagerCreator(this, adapter);

    ListView listView = (ListView) getView().findViewById(R.id.list_repositories);
    listView.setAdapter(adapter);

    adapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override//from w  ww.  java  2 s .co m
        public boolean setViewValue(View view, Cursor cursor, int i) {
            if (view.getId() == R.id.avatar_url) {
                ImageView imageView = (ImageView) view;
                String avatarUrl = cursor.getString(i);
                Picasso.with(getActivity()).load(avatarUrl).into(imageView);
                return true;
            } else {
                return false;
            }
        }
    });

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Cursor cursor = (Cursor) parent.getAdapter().getItem(position);
            int repositoryId = cursor.getInt(cursor.getColumnIndex(DefaultContract.Repository._ID));
            NavUtil.replaceFragment(getActivity(), R.id.container, DetailFragment.newInstance(repositoryId));
        }
    });
}

From source file:net.dahanne.android.google.client.GoogleActivity.java

private void showGoogleOptions() {
    Connection<Google> findPrimaryConnection = connectionRepository.findPrimaryConnection(Google.class);
    Log.e(TAG, findPrimaryConnection.getDisplayName());

    String[] options = { "Disconnect", "Profile" };
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            options);/*from w  ww  .  j a v  a  2  s .c  om*/
    ListView listView = (ListView) this.findViewById(R.id.google_activity_options_list);
    listView.setAdapter(arrayAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parentView, View childView, int position, long id) {
            Intent intent;
            switch (position) {
            case 0:
                disconnect();
                showConnectOption();
                break;
            case 1:
                intent = new Intent();
                intent.setClass(parentView.getContext(), GoogleProfileActivity.class);
                startActivity(intent);
                break;
            default:
                break;
            }
        }
    });
}

From source file:com.arantius.tivocommander.ToDo.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (MindRpc.init(this, null)) {
        return;//w  ww  . j  a  v  a 2s.  c o m
    }

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.list_todo);
    setTitle("To Do List");

    mListAdapter = new ShowsAdapter(this);
    ListView lv = getListView();
    lv.setAdapter(mListAdapter);
    lv.setOnItemClickListener(mOnClickListener);
    lv.setLongClickable(true);
    lv.setOnItemLongClickListener(this);

    mDetailCallback = new MindRpcResponseListener() {
        public void onResponse(MindRpcResponse response) {
            setProgressIndicator(-1);

            String itemId = "recording";
            final JsonNode items = response.getBody().path(itemId);

            ArrayList<Integer> slotMap = mRequestSlotMap.get(response.getRpcId());

            for (int i = 0; i < items.size(); i++) {
                int pos = slotMap.get(i);
                JsonNode item = items.get(i);
                mShowData.set(pos, item);
                mShowStatus.set(pos, ShowStatus.LOADED);
            }

            mRequestSlotMap.remove(response.getRpcId());
            mListAdapter.notifyDataSetChanged();
        }
    };

    mIdSequenceCallback = new MindRpcResponseListener() {
        public void onResponse(MindRpcResponse response) {
            JsonNode body = response.getBody();

            setProgressIndicator(-1);

            mShowIds = (ArrayNode) body.findValue("objectIdAndType");
            if (mShowIds == null)
                return;

            for (int i = 0; i < mShowIds.size(); i++) {
                mShowData.add(null);
                mShowStatus.add(ShowStatus.MISSING);
            }
            mListAdapter.notifyDataSetChanged();
        }
    };

    startRequest();
}

From source file:com.brq.wallet.lt.activity.TraderInfoFragment.java

@Override
public void onResume() {
    _adapter = new TraderInfoAdapter(getActivity(), new ArrayList<TraderInfoAdapter.InfoItem>());
    ListView list = (ListView) findViewById(R.id.lvTraderInfo);
    list.setAdapter(_adapter);
    updateUi();// ww  w.j  a  va  2 s  .c  o m
    super.onResume();
}

From source file:com.aegiswallet.actions.CurrencyActivity.java

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

    prefs = PreferenceManager.getDefaultSharedPreferences(this);

    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    getActionBar().setCustomView(R.layout.aegis_send_actionbar);

    TextView titleTextView = (TextView) findViewById(R.id.action_bar_title_text);
    titleTextView.setText(getString(R.string.currencies_activity_label));

    ImageButton backButton = (ImageButton) findViewById(R.id.action_bar_icon_back);
    backButton.setOnClickListener(new View.OnClickListener() {
        @Override// w  ww. j av a 2s  .  c o m
        public void onClick(View view) {
            Intent openMainActivity = new Intent(context, MainActivity.class);
            openMainActivity.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
            context.startActivity(openMainActivity);
            finish();
        }
    });

    ArrayList<CurrencyPojo> currencies = new ArrayList<CurrencyPojo>();

    JSONObject jsonObject = BasicUtils.parseJSONData(getApplicationContext(),
            Constants.BLOCKCHAIN_CURRENCY_FILE_NAME);

    if (jsonObject != null) {

        Iterator i = jsonObject.keys();
        while (i.hasNext()) {

            try {
                String currency = (String) i.next();
                JSONObject detailObj = jsonObject.getJSONObject(currency);
                CurrencyPojo newPojo = new CurrencyPojo(currency, detailObj.getDouble("last"),
                        detailObj.getString("symbol"));

                currencies.add(newPojo);
            } catch (JSONException e) {
                Log.e("Currency Activity", "JSON Exception " + e.getMessage());
            }
        }

        String currentCurrency = prefs.getString(Constants.CURRENCY_PREF_KEY, null);
        CurrencyPojo firstPojo = currencies.get(0);

        for (int j = 0; j < currencies.size(); j++) {
            CurrencyPojo pojo = currencies.get(j);
            if (pojo.getCurrency().equals(currentCurrency)) {
                currencies.set(0, pojo);
                currencies.set(j, firstPojo);
            }
        }

    }

    CurrencyAdapter currencyAdapter = new CurrencyAdapter(this, R.layout.currency_list_item, currencies, prefs);

    ListView transactionListView = (ListView) findViewById(R.id.currency_list);
    transactionListView.setAdapter(currencyAdapter);

}

From source file:com.cuddlesoft.nori.TagFilterSettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Inflate layout XML.
    setContentView(R.layout.activity_tag_filter_settings);

    // Get shared preferences.
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    // Load list of filtered tags from shared preferences.
    if (sharedPreferences.contains(getString(R.string.preference_tagFilter_key))) {
        final String tagFilter = sharedPreferences.getString(getString(R.string.preference_tagFilter_key), "")
                .trim();/*w  w  w.  ja v  a 2  s. com*/
        if (!TextUtils.isEmpty(tagFilter)) {
            filteredTags.addAll(Arrays.asList(tagFilter.split(" ")));
        }
    }

    // Hide the app icon and use the activity title as the home button.
    final ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayHomeAsUpEnabled(true);

    // Set up the ListView adapter.
    final ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(tagListAdapter);
}

From source file:com.example.android.bangla.ColorsFragment.java

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

    // Create and setup the AudioManager to request audio focus
    mAudioManager = (AudioManager) getActivity().getSystemService(Context.AUDIO_SERVICE);

    // Create a list of words
    final ArrayList<Word> words = new ArrayList<Word>();
    words.add(new Word(R.string.color_red, R.string.bangla_color_red, R.drawable.color_red, R.raw.color_red));
    words.add(new Word(R.string.color_mustard_yellow, R.string.bangla_color_mustard_yellow,
            R.drawable.color_mustard_yellow, R.raw.color_mustard_yellow));
    words.add(new Word(R.string.color_dusty_yellow, R.string.bangla_color_dusty_yellow,
            R.drawable.color_dusty_yellow, R.raw.color_dusty_yellow));
    words.add(new Word(R.string.color_green, R.string.bangla_color_green, R.drawable.color_green,
            R.raw.color_green));/*ww  w.j a va  2s  .  c o  m*/
    words.add(new Word(R.string.color_brown, R.string.bangla_color_brown, R.drawable.color_brown,
            R.raw.color_brown));
    words.add(
            new Word(R.string.color_gray, R.string.bangla_color_gray, R.drawable.color_gray, R.raw.color_gray));
    words.add(new Word(R.string.color_black, R.string.bangla_color_black, R.drawable.color_black,
            R.raw.color_black));
    words.add(new Word(R.string.color_white, R.string.bangla_color_white, R.drawable.color_white,
            R.raw.color_white));

    WordAdapter adapter = new WordAdapter(getActivity(), words, R.color.category_colors);
    ListView listView = (ListView) rootView.findViewById(R.id.list);
    listView.setAdapter(adapter);

    // Set a click listener to play the audio when the list item is clicked on
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            releaseMediaPlayer();
            Word word = words.get(position);
            int result = mAudioManager.requestAudioFocus(mOnAudioFocusChangeListener, AudioManager.STREAM_MUSIC,
                    AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);

            if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
                mMediaPlayer = MediaPlayer.create(getActivity(), word.getAudioResourceId());
                mMediaPlayer.start();
                mMediaPlayer.setOnCompletionListener(mCompletionListener);
            }
        }
    });

    return rootView;
}

From source file:com.example.refresh.Fragment02.java

@Override
public void onStart() {

    super.onStart();

    Log.d("___", "1");

    mPullRefreshListFragment = (PullToRefreshListFragment) getActivity().getSupportFragmentManager()
            .findFragmentById(R.id.fragment_naver);
    mPullRefreshListView = mPullRefreshListFragment.getPullToRefreshListView();
    mPullRefreshListView.setMode(Mode.PULL_FROM_END);
    mPullRefreshListView.setOnRefreshListener(this);

    adapter = new CustomAdapter(getActivity());
    ListView actualListView = mPullRefreshListView.getRefreshableView();
    actualListView.setAdapter(adapter);

    mPullRefreshListFragment.setListShown(true);

    dml = new DML("test", getActivity());

    cnt = adapter.getCount();// w  ww .j  av  a 2s  .  c  om

    Log.d("___", "cnt=" + new Integer(cnt).toString());

    if (cnt == 0) {
        Cursor cursor = dml.select(cnt);
        Log.d("___", "2");

        while (cursor.moveToNext()) {
            User user = new User();
            user.setUserId(cursor.getString(1));
            user.setUserAddr(cursor.getString(3));
            adapter.add(user);
        }

        adapter.notifyDataSetChanged();
    }

}

From source file:com.aqnote.app.wifianalyzer.wifi.ChannelRatingFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    FragmentActivity activity = getActivity();

    View view = inflater.inflate(R.layout.channel_rating_content, container, false);

    swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.channelRatingRefresh);
    swipeRefreshLayout.setOnRefreshListener(new ListViewOnRefreshListener());

    TextView bestChannels = (TextView) view.findViewById(R.id.channelRatingBestChannels);
    ListView listView = (ListView) view.findViewById(R.id.channelRatingView);

    channelRatingAdapter = new ChannelRatingAdapter(activity, bestChannels);
    listView.setAdapter(channelRatingAdapter);

    Scanner scanner = MainContext.INSTANCE.getScanner();
    scanner.register(channelRatingAdapter);

    return view;//www .ja  va 2 s  .  c o m
}