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:city.uk.co.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<String>(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<String>(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  ww . ja  va 2  s .co  m*/

    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);

    return rootView;
}

From source file:com.example.joseba.sunshine.app.ForecastFragment.java

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

    // 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.
    forecastAdapter = new ArrayAdapter<String>(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.
            new ArrayList<String>());

    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(forecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from  w  w  w .  j  a  v a 2  s . co m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String forecast = forecastAdapter.getItem(position);
            Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    forecast);

            startActivity(intent);

        }
    });
    return rootView;
}

From source file:org.quantumbadger.redreader.activities.AlbumListingActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    PrefsUtility.applyTheme(this);

    OptionsMenuUtility.fixActionBar(AlbumListingActivity.this, getString(R.string.imgur_album));

    if (getActionBar() != null) {
        getActionBar().setHomeButtonEnabled(true);
        getActionBar().setDisplayHomeAsUpEnabled(true);
    }/*from w  w  w  .  j a  v a  2 s .c  o  m*/

    final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    final boolean solidblack = PrefsUtility.appearance_solidblack(this, sharedPreferences)
            && PrefsUtility.appearance_theme(this, sharedPreferences) == PrefsUtility.AppearanceTheme.NIGHT;

    if (solidblack)
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK));

    final Intent intent = getIntent();

    mUrl = intent.getDataString();

    if (mUrl == null) {
        finish();
        return;
    }

    final Matcher matchImgur = LinkHandler.imgurAlbumPattern.matcher(mUrl);
    final String albumId;

    if (matchImgur.find()) {
        albumId = matchImgur.group(2);
    } else {
        Log.e("AlbumListingActivity", "URL match failed");
        revertToWeb();
        return;
    }

    Log.i("AlbumListingActivity", "Loading URL " + mUrl + ", album id " + albumId);

    final ProgressBar progressBar = new ProgressBar(this, null, android.R.attr.progressBarStyleHorizontal);
    progressBar.setIndeterminate(true);

    final LinearLayout layout = new LinearLayout(this);
    layout.setOrientation(LinearLayout.VERTICAL);
    layout.addView(progressBar);

    ImgurAPI.getAlbumInfo(this, albumId, Constants.Priority.IMAGE_VIEW, 0, new GetAlbumInfoListener() {

        @Override
        public void onFailure(final RequestFailureType type, final Throwable t, final StatusLine status,
                final String readableMessage) {
            Log.e("AlbumListingActivity", "getAlbumInfo call failed: " + type);

            if (status != null)
                Log.e("AlbumListingActivity", "status was: " + status.toString());
            if (t != null)
                Log.e("AlbumListingActivity", "exception was: ", t);

            // It might be a single image, not an album

            if (status == null) {
                revertToWeb();
                return;
            }

            ImgurAPI.getImageInfo(AlbumListingActivity.this, albumId, Constants.Priority.IMAGE_VIEW, 0,
                    new GetImageInfoListener() {
                        @Override
                        public void onFailure(final RequestFailureType type, final Throwable t,
                                final StatusLine status, final String readableMessage) {
                            Log.e("AlbumListingActivity", "Image info request also failed: " + type);
                            revertToWeb();
                        }

                        @Override
                        public void onSuccess(final ImageInfo info) {
                            Log.i("AlbumListingActivity", "Link was actually an image.");
                            LinkHandler.onLinkClicked(AlbumListingActivity.this, info.urlOriginal);
                            finish();
                        }

                        @Override
                        public void onNotAnImage() {
                            Log.i("AlbumListingActivity", "Not an image either");
                            revertToWeb();
                        }
                    });
        }

        @Override
        public void onSuccess(final ImgurAPI.AlbumInfo info) {
            Log.i("AlbumListingActivity", "Got album, " + info.images.size() + " image(s)");

            AndroidApi.UI_THREAD_HANDLER.post(new Runnable() {
                @Override
                public void run() {

                    if (info.title != null && !info.title.trim().isEmpty()) {
                        OptionsMenuUtility.fixActionBar(AlbumListingActivity.this,
                                getString(R.string.imgur_album) + ": " + info.title);
                    }

                    layout.removeAllViews();

                    final ListView listView = new ListView(AlbumListingActivity.this);
                    listView.setAdapter(new AlbumAdapter(info));
                    layout.addView(listView);

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

                            LinkHandler.onLinkClicked(AlbumListingActivity.this,
                                    info.images.get(position).urlOriginal, false, null, info, position);
                        }
                    });
                }
            });
        }
    });

    setContentView(layout);
}

From source file:androidGLUESigner.ui.Fragments.SignedDocListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    this.settingsHelper = new SettingsHelper(getActivity());
    this.view = inflater.inflate(R.layout.fragment_sdoclist, container, false);
    final ListView listview = (ListView) view.findViewById(R.id.sdocListView);
    list = settingsHelper.getSignedDocList();
    adapter = new SdocListAdapter(getActivity(), android.R.layout.simple_list_item_1, list);
    listview.setAdapter(adapter);
    listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override//from w  w  w . j a v a  2 s.c o  m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SignedDocActivity activity = (SignedDocActivity) getActivity();
            activity.launchReader(list.get(position));

        }
    });
    listview.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) {
            final String item = (String) parent.getItemAtPosition(position);
            showDeleteButton(item, list);

            return true;
        }
    });
    this.deleteButton = (ImageButton) view.findViewById(R.id.sigListDeleteButton);
    return view;
}

From source file:app.com.example.android.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 WEATHER STATION - 23/18", "Sun 6/29 - Sunny - 20/7" };
    List<String> weekForecast = new ArrayList<String>(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.
    forecastAdapter = new ArrayAdapter<String>(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 .ja v a 2s . c om

    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(forecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            Toast.makeText(getActivity(), forecastAdapter.getItem(position), Toast.LENGTH_LONG).show();
            Intent detailIntent = new Intent(getActivity(), DetailActivity.class);
            detailIntent.putExtra(Intent.EXTRA_TEXT, forecastAdapter.getItem(position));
            startActivity(detailIntent);

        }
    });
    return rootView;
}

From source file:com.example.faisal.sunshine.app.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
    final 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" };
    final List<String> weekForecast = new ArrayList<String>(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<String>(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);/*  ww  w. ja  va 2 s  .  c o  m*/

    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.list_view_forecast);
    listView.setAdapter(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Toast toast = Toast.makeText(getActivity(), mForecastAdapter.getItem(position), Toast.LENGTH_SHORT);
            toast.show();

            Intent detailIntent = new Intent(getActivity(), DetailActivity.class);
            detailIntent.putExtra(Intent.EXTRA_TEXT, mForecastAdapter.getItem(position));
            startActivity(detailIntent);
        }
    });

    return rootView;
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_market);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // Get View items
    but_draw = findViewById(R.id.market_draw);
    choice_panel = findViewById(R.id.market_choices);
    sold_out = findViewById(R.id.market_sold_out);

    // Setup the list & adapter
    ListView card_list = (ListView) findViewById(R.id.card_list);
    adapter = new CardAdapter(this);
    adapter.changeCursor(null);//ww  w  .  ja  v  a  2 s.  c  om
    card_list.setAdapter(adapter);
    card_list.setOnItemClickListener(this);

    // Restore app state or set it up
    stock = null;
    choices = null;
    if (savedInstanceState != null) {
        long[] arrStock = savedInstanceState.getLongArray(KEY_STOCK);
        stock = new LinkedList<>();
        for (long id : arrStock)
            stock.add(id);
        choices = savedInstanceState.getLongArray(KEY_CHOICES);
    } else
        setupMarketStall();

    // Setup the display based off of app state
    if (choices == null) {
        if (stock == null || stock.size() < 1) {
            but_draw.setVisibility(View.GONE);
            sold_out.setVisibility(View.VISIBLE);
        }
    } else {
        but_draw.setVisibility(View.GONE);
        choice_panel.setVisibility(View.VISIBLE);
        getSupportLoaderManager().restartLoader(4, null, this);
    }
}

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

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

    Intent intent = getIntent();/*  w w  w.  java2 s .c  om*/
    final int book = intent.getIntExtra("book", 0);
    int chapter = intent.getIntExtra("chapter", 0);
    final String search_key = intent.getStringExtra("search_key");
    final boolean favorites = intent.getBooleanExtra("favorites", false);

    db = new SQLiteHelper(this);
    db.openDataBase();
    //      final String book_name = db.getBook(book).toString();

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

    if (favorites) {
        setTitle(getString(R.string.display_favorites));
        List<BookPoint> points = new ArrayList<BookPoint>();
        points = db.getFavoritePoints();
        lv.setAdapter(new ArrayAdapter<BookPoint>(this, android.R.layout.simple_list_item_1, points));
    } else if (search_key != null) {
        setTitle(getString(R.string.display_search) + ": " + search_key);
        List<BookPoint> points = new ArrayList<BookPoint>();
        points = db.getPoints(search_key);
        lv.setAdapter(new ArrayAdapter<BookPoint>(this, android.R.layout.simple_list_item_1, points));
    } else {
        setTitle(db.getBook(book) + ": " + db.getChapter(book, chapter));
        List<BookPoint> points = new ArrayList<BookPoint>();
        points = db.getBookPoints(book, chapter);
        lv.setAdapter(new ArrayAdapter<BookPoint>(this, android.R.layout.simple_list_item_1, points));
    }

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

    db.close();
}

From source file:com.digium.respoke.GroupChatActivity.java

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

    Button buttonSend = (Button) findViewById(R.id.buttonSend);

    EditText chatText = (EditText) findViewById(R.id.chatText);
    chatText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                sendChatMessage();//from  w w  w . j a va 2  s .  c om
                return true;
            }
            return false;
        }
    });
    buttonSend.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            sendChatMessage();
        }
    });

    String groupID = null;

    // Check whether we're recreating a previously destroyed instance
    if (savedInstanceState != null) {
        groupID = savedInstanceState.getString(GROUP_ID_KEY);
    } else {
        Bundle extras = getIntent().getExtras();
        if (extras != null) {
            groupID = extras.getString(GROUP_ID_KEY);
        } else {
            // The activity must have been destroyed while it was hidden to save memory. Use the most recent persistent data.
            SharedPreferences prefs = getSharedPreferences(ConnectActivity.RESPOKE_SETTINGS, 0);
            groupID = prefs.getString(GROUP_ID_KEY, "");
        }
    }

    this.setTitle(groupID);

    for (RespokeGroup eachGroup : ContactManager.sharedInstance().groups) {
        if (eachGroup.getGroupID().equals(groupID)) {
            group = eachGroup;
            break;
        }
    }

    conversation = ContactManager.sharedInstance().groupConversations.get(groupID);

    listAdapter = new ListDataAdapter();

    ListView lv = (ListView) findViewById(R.id.list); //retrieve the instance of the ListView from your main layout
    lv.setAdapter(listAdapter); //assign the Adapter to be used by the ListView
}

From source file:com.kylemcintire.sunshine.ForecastFragment.java

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

    forecastAdapter = new ArrayAdapter<String>(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.
            new ArrayList<String>());

    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(forecastAdapter);

    //Click listener for list items to redirect to detail activity
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*  w w  w.j a  v a 2  s. co  m*/
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            //Retrieve forecast from forecast adapter using position based on item click
            String forecast = forecastAdapter.getItem(position);
            //Create intent to pass in forecast data to start detail activity
            Intent detailIntent = new Intent(getActivity(), DetailActivity.class);
            detailIntent.putExtra("forecast", forecast);
            startActivity(detailIntent);
        }
    });

    return rootView;
}