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:dk.larsbak.sunshine.ForecastFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Create some dummy data for the ListView.  Here's a sample weekly forecast
    String[] data = { "Mon 6/23- Sunny - 31/17", "Tue 6/24 - Foggy - 21/8", "Wed 6/25 - Cloudy - 22/17",
            "Thurs 6/26 - Rainy - 18/11", "Fri 6/27 - Foggy - 21/10",
            "Sat 6/28 - TRAPPED IN WEATHERSTATION - 23/18", "Sun 6/29 - Sunny - 20/7" };
    List<String> weekForecast = new ArrayList<>(Arrays.asList(data));

    // Now that we have some dummy forecast data, create an ArrayAdapter.
    // The ArrayAdapter will take data from a source (like our dummy forecast) and
    // use it to populate the ListView it's attached to.
    mForecastAdapter = new ArrayAdapter<>(getActivity(), // The current context (this activity)
            R.layout.list_item_forecast, // The name of the layout ID.
            R.id.list_item_forecast_textview, // The ID of the textview to populate.
            weekForecast);//from   w  w  w. j a  v  a2  s  .  com

    View rootView = inflater.inflate(R.layout.fragment_forecast, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);

    // Set listener for onclick
    listView.setOnItemClickListener(onForecastClickListener);

    return rootView;
}

From source file:com.example.bufferandroidproject.abs.ItemListFragment.java

/**
 * Configure list after view has been created
 *
 * @param activity/*from ww  w .j av a 2s .co m*/
 * @param listView
 */
protected void configureList(Activity activity, ListView listView) {
    listView.setAdapter(createAdapter());
}

From source file:com.sftoolworks.nfcoptions.SelectActivity.java

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

    nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    pendingIntent = PendingIntent.getActivity(this, 0,
            new Intent(this, this.getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    Intent intent = getIntent();/*w  w  w.  j  a v  a 2s  . c o m*/
    Parcelable[] rawMessages = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);

    String title = getString(R.string.default_select_title);

    TextView textViewBottom = (TextView) findViewById(R.id.textView2);
    textViewBottom.setText("");

    if (rawMessages != null) {

        ArrayList<Object> entries = new ArrayList<Object>();

        String data = null;

        for (Parcelable rawMessage : rawMessages) {
            NdefMessage message = (NdefMessage) rawMessage;
            NdefRecord[] records = message.getRecords();
            if (records.length > 1) {
                byte[] bArray = records[1].getPayload();
                byte languageLength = bArray[0];

                languageLength++; // because of the length byte

                data = new String(bArray, languageLength, bArray.length - languageLength);
            }
        }

        try {
            JSONObject json = (JSONObject) new JSONTokener(data).nextValue();
            if (json.has("title"))
                title = json.getString("title");
            if (json.has("key"))
                selectKey = json.getString("key");
            if (json.has("options")) {
                JSONArray arr = json.getJSONArray("options");
                for (int i = 0; i < arr.length(); i++) {
                    entries.add(parseJObject(arr.getJSONObject(i)));
                }
            }

            ListView list = (ListView) findViewById(R.id.listView1);
            list.setAdapter(new OptionListAdapter(this, entries.toArray()));

            list.setOnItemClickListener(new ListView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int index, long id) {
                    CheckBox cb = (CheckBox) view.findViewById(R.id.optionListCheckBox);
                    cb.setChecked(!cb.isChecked());
                }
            });

            textViewBottom.setText(getString(R.string.tap_again));

        } catch (Exception e) {
            String message = getString(R.string.json_err);
            message += "\n";
            message += e.getMessage();

            Toast.makeText(this, message, Toast.LENGTH_LONG).show();

            Log.d(TAG, getString(R.string.json_err));
            Log.d(TAG, e.toString());
            Log.d(TAG, data);
        }
    } else {
        title = getString(R.string.no_tag);
    }

    TextView msg = (TextView) findViewById(R.id.textView1);
    msg.setText(title);

}

From source file:com.capstonecontrol.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from  w  ww  .  j  a  v  a2s  . co m
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                CapstoneControlActivity.userChanged = true;
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                // finish();
                // clear the module list so that a new one will get found
                CapstoneControlActivity.modules.clear();
                // instead of finish() go back to the AccountsActivity for
                // new login.
                CapstoneControlActivity.googleUserName = (String) account.getText();
                Intent myIntent = new Intent(v.getContext(), SplashActivity.class);
                startActivity(myIntent);
                myIntent = new Intent(v.getContext(), CapstoneControlActivity.class);
                startActivity(myIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
            }
        });
    }
}

From source file:com.listomate.activities.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *///from w  ww  .  ja  v  a 2  s  .  c  o m
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
            }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                finish();
            }
        });
        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();
    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Register in the background and terminate the activity
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                register((String) account.getText());
                finish();
            }
        });

        final Button exitButton = (Button) findViewById(R.id.exit);
        exitButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                finish();
            }
        });
    }
}

From source file:ch.citux.td.ui.TDActivity.java

private void initNavigation() {
    toolbar.setLogo(R.drawable.twitch_logo_white);
    toolbar.setLogoDescription(R.string.app_name);
    setSupportActionBar(toolbar);//from   w ww  .  j  a  va  2  s .c om

    if (drawerLayout != null) {
        toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_open,
                R.string.navigation_close);
        toggle.setDrawerIndicatorEnabled(true);
        drawerLayout.setDrawerListener(toggle);
    }

    ListView lstNav = (ListView) findViewById(R.id.lstNav);
    lstNav.setAdapter(new ArrayAdapter<>(this, R.layout.list_item_navigation,
            getResources().getStringArray(R.array.navigation)));
    lstNav.setOnItemClickListener(this);
}

From source file:falcofinder.android.fuehrerschein.chat.AccountsActivity.java

/**
 * Sets up the 'connect' screen content.
 *//*from   ww  w  . jav a  2  s .  c  om*/
private void setConnectScreenContent() {
    List<String> accounts = getGoogleAccounts();
    if (accounts.size() == 0) {
        // Show a dialog and invoke the "Add Account" activity if requested
        AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
        builder.setMessage(R.string.needs_account);

        /* 
         * rimuovo aggiunta account perche' disponible da versione 2.2
         * ma voglio compatibilita' con 2.1
        builder.setPositiveButton(R.string.add_account, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            startActivity(new Intent(Settings.ACTION_ADD_ACCOUNT));
        }
        });
        builder.setNegativeButton(R.string.skip, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            finish();
        }
        });
        */

        builder.setIcon(android.R.drawable.stat_sys_warning);
        builder.setTitle(R.string.attention);
        builder.show();

    } else {
        final ListView listView = (ListView) findViewById(R.id.select_account);
        listView.setAdapter(new ArrayAdapter<String>(mContext, R.layout.account, accounts));
        listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        listView.setItemChecked(mAccountSelectedPosition, true);

        final Button connectButton = (Button) findViewById(R.id.connect);
        connectButton.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                // Set "connecting" status
                SharedPreferences prefs = Util.getSharedPreferences(mContext);
                prefs.edit().putString(Util.CONNECTION_STATUS, Util.CONNECTING).commit();
                // Get account name
                mAccountSelectedPosition = listView.getCheckedItemPosition();
                TextView account = (TextView) listView.getChildAt(mAccountSelectedPosition);
                // Register
                register((String) account.getText());
                finish();
            }
        });
    }
}

From source file:com.QuarkLabs.BTCeClient.fragments.HomeFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    //add pair to dashboard action
    case R.id.action_add:
        final CheckBoxListAdapter checkBoxListAdapter = new CheckBoxListAdapter(getActivity(),
                getResources().getStringArray(R.array.ExchangePairs), CheckBoxListAdapter.SettingsScope.PAIRS);
        ListView listView = new ListView(getActivity());
        listView.setAdapter(checkBoxListAdapter);
        new AlertDialog.Builder(getActivity()).setTitle(this.getString(R.string.SelectPairsPromptTitle))
                .setView(listView).setNeutralButton(getResources().getString(R.string.DialogSaveButton),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                checkBoxListAdapter.saveValuesToPreferences();
                                updateStorageWithTickers();
                                mTickersDashboardAdapter.update();
                                getActivity()
                                        .sendBroadcast(new Intent(getActivity(), StartServiceReceiver.class));
                            }/*ww  w  .  j  a v  a 2 s .  com*/
                        })
                .show();
        break;
    //refresh dashboard action
    case R.id.action_refresh:
        mRefreshItem = item;
        mRefreshItem.setActionView(R.layout.progress_bar_action_view);
        mRefreshItem.expandActionView();
        getActivity().sendBroadcast(new Intent(getActivity(), StartServiceReceiver.class));
        break;
    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:bus_vn.gena.bus_vn.com.bus_vn.tabs.Tab_time.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Context context = getActivity();
    DbOpenHelper dbOpenHelper = new DbOpenHelper(context);
    SQLiteDatabase db;/*from   w  w w.  ja va2s .  co  m*/
    db = dbOpenHelper.getWritableDatabase();
    ContentValues cv = new ContentValues();
    cv.clear();

    String busStopPathId = "";
    String st = "";
    st = "SELECT bus_stop_path_table.id  FROM bus_stop_path_table ";
    st = st + " WHERE bus_stop_path_table.Bus_path_id='" + busPathId + "'";
    st = st + " AND bus_stop_path_table.Bus_stop_id='" + busStopId + "'";
    st = st + " AND bus_stop_path_table.Type_day_id='" + typeDay + "'";
    Cursor c = db.rawQuery(st, null);
    while (c.moveToNext()) {
        busStopPathId = c.getString(0);
    }
    st = "";
    st = "SELECT bus_time_table.Time  FROM bus_time_table ";
    st = st + " WHERE bus_time_table.Bus_path_stop_id='" + busStopPathId + "'";
    st = st + " AND bus_time_table.Type_day_id='" + typeDay + "'";
    c = db.rawQuery(st, null);
    ArrayList<String> busTimeArray = new ArrayList<String>();
    while (c.moveToNext()) {
        String str = c.getString(0).replaceAll(" ", "");
        if (str.equals("-")) {
        } else {
            busTimeArray.add(c.getString(0));
        }
    }
    String st3;
    String hour;
    for (int i = 0; i < busTimeArray.size(); i++) {
        st3 = busTimeArray.get(i);
        hour = st3.substring(0, st3.indexOf(':'));
        int k = 0;
        int number = 0;
        for (int j = 0; j < allTime.size(); j++) {
            if (hour.equals(allTime.get(j).Get_hour())) {
                k = 1;
                number = j;
            }
        }
        if (k == 0) {
            Time myTime = new Time();
            myTime.Set_hour(hour);
            myTime.Add_minutes(st3.substring(st3.indexOf(':') + 1, st3.length()));
            allTime.add(myTime);
        } else {
            allTime.get(number).Add_minutes(st3.substring(st3.indexOf(':') + 1, st3.length()));
        }
    }
    ArrayList<String> hours = new ArrayList<String>();
    for (int i = 0; i < allTime.size(); i++) {
        hours.add(allTime.get(i).Get_hour());
    }
    String[] resultsHours = hours.toArray(new String[hours.size()]);
    ListView listView = (ListView) getView().findViewById(R.id.lv);
    listView.setOnItemClickListener((android.widget.AdapterView.OnItemClickListener) this);
    ListviewArrayAdapterBusTime caa;
    caa = new ListviewArrayAdapterBusTime(getActivity(), resultsHours, allTime);
    listView.setAdapter(caa);
}

From source file:com.example.amit.tellymoviebuzzz.UpcomingMoviesForecast.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // The CursorAdapter will take data from our cursor and populate the ListView.
    mForecastAdapter = new ForecastAdapter(getActivity(), null, 0);

    View rootView = inflater.inflate(R.layout.upcomingmovies_main, container, false);

    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_upcoming_movies);
    listView.setAdapter(mForecastAdapter);

    // We'll call our MainActivity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//from   w  w w. j  a  v a  2  s  . c  o  m
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            // CursorAdapter returns a cursor at the correct position for getItem(), or null
            // if it cannot seek to that position.
            Cursor cursor = (Cursor) adapterView.getItemAtPosition(position);
            if (cursor != null) {
                // String locationSetting = Utility.getPreferredLocation(getActivity());
                String movieSetting = "upcoming";

                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);
                Log.v("MovieSetting", movieSetting);

                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));
                Log.v("cursor position", String.valueOf(cursor.getPosition()));

                // Intent intent = new Intent(getActivity(), DetailActivity.class)
                //        .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate(
                //               locationSetting, cursor.getLong(COL_WEATHER_DATE)
                //       ));

                Intent intent = new Intent(getActivity(), DetailActivity.class).setData(
                        MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, "87101"));

                startActivity(intent);
            }
        }
    });
    return rootView;
}