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.angelina.travelapp.route.RouteDirectionsFragment.java

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

    // Set up the header
    ImageView backBtn = (ImageView) getActivity().findViewById(R.id.btnCloseDirections);
    backBtn.setOnClickListener(new View.OnClickListener() {
        @Override//from  w w w.j av a  2s. c o  m
        public void onClick(View v) {
            ((MapActivity) getActivity()).restoreRouteView();
        }
    });

    // Hide the action bar
    final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
    if (ab != null) {
        ab.hide();
    }

    // Setup list adapter
    final ListView listView = (ListView) view.findViewById(R.id.directions_list);
    mAdapter = new DirectionsListAdapter(mDirectionManeuvers);
    listView.setAdapter(mAdapter);

    // When directions are tapped, show selected route section
    // highlighted on map and zoomed in with route section description
    // overlayed on map
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ((MapActivity) getActivity()).showRouteDetail(position);
        }
    });

    return view;
}

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

@Override
protected void onContent() {
    getParent().setProgressBarIndeterminateVisibility(false);

    mCredits = mContent.path("credit");

    if (mCredits.size() == 0) {
        setContentView(R.layout.no_results);
    } else {/*from   w w w  .  j  a  va2s .c o m*/
        setContentView(R.layout.list_explore);

        JsonNode[] credits = new JsonNode[mCredits.size()];
        int i = 0;
        for (JsonNode credit : mCredits) {
            credits[i++] = credit;
        }

        setContentView(R.layout.list_explore);
        ListView lv = (ListView) findViewById(R.id.list_explore);
        CreditsAdapter adapter = new CreditsAdapter(this, R.layout.item_credits, credits);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(mOnItemClickListener);
    }
}

From source file:com.eyekabob.EventList.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.adlistactivity);
    adapter = new EventListAdapter(getApplicationContext());
    ListView lv = (ListView) findViewById(R.id.adList);
    lv.setAdapter(adapter);
    Uri uri = this.getIntent().getData();
    if (getIntent().hasExtra("zip")) {
        // Search by zip.
        String zip = getIntent().getExtras().getString("zip");
        if (zip != null) {
            zip = zip.trim();//from   w ww . ja  v  a2 s.  co  m
        }
        if (zipToGeoMap.containsKey(zip)) {
            Log.d(getClass().getName(), "Using cached zip");
            String[] latLong = zipToGeoMap.get(zip).split("\\|");
            Uri lastFMURI = getLastFMURI(latLong[0], latLong[1]);
            sendLastFMRequest(lastFMURI.toString());
        } else {
            Log.d(getClass().getName(), "Getting zip from geonames service");
            sendJSONRequest(uri.toString());
        }
    } else if (getIntent().hasExtra("city")) {
        // Search by city/state.
        String city = getIntent().getExtras().getString("city");
        String encodedCity;
        try {
            encodedCity = URLEncoder.encode(city, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            Log.e(getClass().getName(), "Problem with city", e);
            return;
        }
        String state = getIntent().getExtras().getString("state");
        Map<String, String> params = new HashMap<String, String>();
        params.put("address", encodedCity + "," + state);
        Uri googleURI = EyekabobHelper.GoogleMaps.getURI(params);
        sendMapsRequest(googleURI.toString());
    } else {
        Log.d(getClass().getName(), "Searching for events using current location");
        sendLastFMRequest(uri.toString());
    }

    lv.setOnItemClickListener(listItemListener);
}

From source file:com.textuality.gpstats.GPlusSnowflake.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);/*ww  w .ja  va2s  .  com*/

    final ListView list = (ListView) findViewById(R.id.list);
    final PostArrayAdapter adapter = new PostArrayAdapter(this);

    mPopular = new MostPopular(adapter, (TextView) findViewById(R.id.output));
    list.setAdapter(adapter);
    list.setOnItemClickListener(adapter);

    Intent intent = AccountPicker.newChooseAccountIntent(null, null, new String[] { "com.google" }, false, null,
            null, null, null);
    startActivityForResult(intent, GPS_REQUEST_CODE);
}

From source file:com.example.kylelehman.sunshine.ForecastFragment.java

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

    // The SimpleCursorAdapter will take data from the database through the
    // Loader and use it to populate the ListView it's attached to.
    mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null,
            // the column names to use to fill the textviews
            new String[] { WeatherEntry.COLUMN_DATETEXT, WeatherEntry.COLUMN_SHORT_DESC,
                    WeatherEntry.COLUMN_MAX_TEMP, WeatherEntry.COLUMN_MIN_TEMP },
            // the textviews to fill with the data pulled from the columns above
            new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview,
                    R.id.list_item_high_textview, R.id.list_item_low_textview },
            0);/*from w w w  .j a v  a  2  s  . c o  m*/

    mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            boolean isMetric = Utility.isMetric(getActivity());
            switch (columnIndex) {
            case COL_WEATHER_MAX_TEMP:
            case COL_WEATHER_MIN_TEMP: {
                // we have to do some formatting and possibly a conversion
                ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric));
                return true;
            }
            case COL_WEATHER_DATE: {
                String dateString = cursor.getString(columnIndex);
                TextView dateView = (TextView) view;
                dateView.setText(Utility.formatDate(dateString));
                return true;
            }
            }
            return false;
        }
    });

    View rootView = inflater.inflate(R.layout.fragment_main, 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);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Cursor cursor = mForecastAdapter.getCursor();
            if (cursor != null && cursor.moveToPosition(position)) {
                Intent intent = new Intent(getActivity(), DetailActivity.class)
                        .putExtra(DetailActivity.DATE_KEY, cursor.getString(COL_WEATHER_DATE));
                startActivity(intent);
            }
        }
    });

    return rootView;
}

From source file:net.idlesoft.android.apps.github.activities.Branch.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.branch);/*  ww w .j  a  v a 2  s .c o m*/

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    ((ImageButton) findViewById(R.id.btn_search)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            startActivity(new Intent(Branch.this, Search.class));
        }
    });

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mRepositoryName = extras.getString("repo_name");
        mRepositoryOwner = extras.getString("repo_owner");
        mBranchName = extras.getString("branch_name");
        mBranchSha = extras.getString("branch_sha");

        final TextView branchName = (TextView) findViewById(R.id.tv_branch_name);
        final TextView branchSha = (TextView) findViewById(R.id.tv_branch_sha);
        final ListView infoList = (ListView) findViewById(R.id.lv_branch_infoList);

        branchName.setText(mBranchName);
        branchSha.setText(mBranchSha);

        infoList.setAdapter(new ArrayAdapter<String>(Branch.this, R.layout.branch_info_item,
                R.id.tv_branchInfoItem_text1, new String[] { "Commit Log", "View Branch's Tree" }));
        infoList.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(final AdapterView<?> parent, final View v, final int position,
                    final long id) {
                if (position == 0) {
                    mIntent = new Intent(Branch.this, CommitsList.class);
                    mIntent.putExtra("repo_owner", mRepositoryOwner);
                    mIntent.putExtra("repo_name", mRepositoryName);
                    mIntent.putExtra("branch_name", mBranchName);
                    startActivity(mIntent);
                } else if (position == 1) {
                    mIntent = new Intent(Branch.this, BranchTree.class);
                    mIntent.putExtra("repo_owner", mRepositoryOwner);
                    mIntent.putExtra("repo_name", mRepositoryName);
                    mIntent.putExtra("branch_name", mBranchName);
                    mIntent.putExtra("branch_sha", mBranchSha);
                    startActivity(mIntent);
                }
            }
        });
    }
}

From source file:com.example.rossetto.organizer.MainActivityFragment.java

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

    ArrayList<CompromissoItem> objects = new ArrayList<CompromissoItem>();
    mAdapter = new CompromissoAdapter(getActivity(), R.layout.list_item_compromisso, objects);

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

    mListView = rootView.findViewById(R.id.listview_compromisso);
    mProgressView = rootView.findViewById(R.id.main_progress);
    // Get a reference to the ListView, and attach this adapter to it.
    ListView listView = (ListView) rootView.findViewById(R.id.listview_compromisso);
    listView.setAdapter(mAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override// w  w w.j  av a 2s .c o  m
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            CompromissoItem comp = mAdapter.getItem(position);
            Intent intent = new Intent(getActivity(), ViewCompromissoActivity.class).putExtra("id",
                    comp.getId());
            startActivity(intent);
        }
    });
    return rootView;
}

From source file:alberthsu.sunshine.app.ForecastFragment.java

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

    // The SimpleCursorAdapter will take data from the database through the
    // Loader and use it to populate the ListView it's attached to.
    mForecastAdapter = new SimpleCursorAdapter(getActivity(), R.layout.list_item_forecast, null,
            // the column names to use to fill the textviews
            new String[] { WeatherEntry.COLUMN_DATETEXT, WeatherEntry.COLUMN_SHORT_DESC,
                    WeatherEntry.COLUMN_MAX_TEMP, WeatherEntry.COLUMN_MIN_TEMP },
            // the textviews to fill with the data pulled from the columns above
            new int[] { R.id.list_item_date_textview, R.id.list_item_forecast_textview,
                    R.id.list_item_high_textview, R.id.list_item_low_textview },
            0);//from  w  w w .  j  av a  2 s . c  o m

    mForecastAdapter.setViewBinder(new SimpleCursorAdapter.ViewBinder() {
        @Override
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            boolean isMetric = Utility.isMetric(getActivity());
            switch (columnIndex) {
            case COL_WEATHER_MAX_TEMP:
            case COL_WEATHER_MIN_TEMP: {
                // we have to do some formatting and possibly a conversion
                ((TextView) view).setText(Utility.formatTemperature(cursor.getDouble(columnIndex), isMetric));
                return true;
            }
            case COL_WEATHER_DATE: {
                String dateString = cursor.getString(columnIndex);
                TextView dateView = (TextView) view;
                dateView.setText(Utility.formatDate(dateString));
                return true;
            }
            }
            return false;
        }
    });

    View rootView = inflater.inflate(R.layout.fragment_main, 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);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            Cursor cursor = mForecastAdapter.getCursor();
            if (cursor != null && cursor.moveToPosition(position)) {

                Intent intent = new Intent(getActivity(), detailedActivity.class)
                        .putExtra(detailedActivity.DATE_KEY, cursor.getString(COL_WEATHER_DATE));
                startActivity(intent);
            }
        }
    });

    return rootView;
}

From source file:com.arquitetaweb.restaurantes.MainActivity.java

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

    setContentView(R.layout.example);/*from  w w  w  .ja  v a 2  s  .c  om*/

    viewActionsContentView = (ActionsContentView) findViewById(R.id.actionsContentView);
    viewActionsContentView.setSwipingType(ActionsContentView.SWIPING_ALL);

    final ListView viewActionsList = (ListView) findViewById(R.id.actions);
    final ActionsAdapter actionsAdapter = new ActionsAdapter(this);
    viewActionsList.setAdapter(actionsAdapter);
    viewActionsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View v, int position, long flags) {
            final Uri uri = actionsAdapter.getItem(position);

            updateContent(uri);
            viewActionsContentView.showContent();
        }
    });

    if (savedInstanceState != null) {
        currentUri = Uri.parse(savedInstanceState.getString(STATE_URI));
        currentContentFragmentTag = savedInstanceState.getString(STATE_FRAGMENT_TAG);
    }

    updateContent(currentUri);
}

From source file:com.facebook.samples.socialcafe.MenuFragmentActivity.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.main_menu, parent, false);
    getActivity().setTitle(R.string.menu);

    userNameView = (TextView) v.findViewById(R.id.user_name);
    userPicView = (ImageView) v.findViewById(R.id.user_pic);
    if (userName != null) {
        userNameView.setText(userName);/* ww  w .  j a v a 2  s .  c om*/
    }
    if (userPic != null) {
        userPicView.setImageBitmap(userPic);
    }
    ListView drinkList = (ListView) v.findViewById(R.id.menu_list);
    drinkList.setAdapter(new DrinkListAdapter());

    drinkList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int position, long id) {
            Drink drink = (Drink) arg0.getItemAtPosition(position);
            Intent orderIntent = new Intent(getActivity(), OrderDrinkActivity.class);
            orderIntent.putExtra("DRINK_URL", drink.getURL());
            startActivity(orderIntent);
        }

    });

    return v;
}