Example usage for android.widget ArrayAdapter ArrayAdapter

List of usage examples for android.widget ArrayAdapter ArrayAdapter

Introduction

In this page you can find the example usage for android.widget ArrayAdapter ArrayAdapter.

Prototype

public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @IdRes int textViewResourceId,
        @NonNull List<T> objects) 

Source Link

Document

Constructor

Usage

From source file:com.example.cgraham.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);//ww w . jav a  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.listview_forecast);
    listView.setAdapter(mForecastAdapter);

    return rootView;
}

From source file:com.example.android.sunshine.app.ForcastFragment.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_forcast, // The name of the layout ID.
            R.id.list_item_forcast_textview, // The ID of the textview to populate.
            weekForecast);//  www.  ja v  a2 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.list_view_forcast);
    listView.setAdapter(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Toast.makeText(getActivity(), mForecastAdapter.getItem(i), Toast.LENGTH_SHORT).show();
        }
    });

    return rootView;
}

From source file:com.zsrappdev.Resume.ResumeFragment.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 = { "Contact Information", "Technical Skills", "Project Experience", "Education",
            "Relevant Work Experience - Research Assistant", "Relevant Work Experience - Teaching Assistant",
            "Others" };
    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.
    mResumeAdapter = 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);//w  ww .  j  a va  2s.  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.listview_forecast);
    listView.setAdapter(mResumeAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Toast.makeText(getActivity(), mResumeAdapter.getItem(i), Toast.LENGTH_LONG).show();

            Intent intent = new Intent(getActivity(), DetailActivity.class);
            intent.putExtra("selected", mResumeAdapter.getItem(i));
            startActivity(intent);
        }
    });

    return rootView;
}

From source file:com.example.pawandeep.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
    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);/*  www  .  j  a v  a 2s . 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.listview_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Context context = ForecastFragment.this.getActivity();
            CharSequence text = "Hello toast!";
            int duration = Toast.LENGTH_SHORT;

            Toast toast = Toast.makeText(context, text, duration);
            toast.show();
        }
    });

    return rootView;
}

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

@Override //This "onCreateView" method is where the UI gets initialized
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    /*String[] data = {//w  w  w .ja  v a  2 s  .  c  o  m
        "Monday - Sunny - 14/24",
        "Tuesday - Cloudy - 10/19",
        "Wednesday - Solar Flares - -45/134",
        "Thursday - Everyone is Dead - ?",
        "Friday - Everyone gone - gone.. gone",
        "Saturday - Glowing Green - 22/24",
        "Sunday - Excellent weather for Zombies"
    }; DUMMY DATA
            
    List<String> weekForecast = new ArrayList<String>(Arrays.asList(data));   DUMMY DATA*/

    // Get a reference to the ListView, and attach this adapter to it.
    mForecastAdapter = new ArrayAdapter<String>(
            //The current context (This fragments parent activity)
            getActivity(),
            //ID of list item layout style
            R.layout.list_item_forecast,
            //ID of the textview to populate the layout
            R.id.list_item_forecast_textview,
            // Pass in Forecast Data To populate the text
            new ArrayList<String>());

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

    //Set the mForecast Adapter to send its adapted info to the listview
    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) {
            String forecast = mForecastAdapter.getItem(position);
            //Toast.makeText(getActivity(), forecast, Toast.LENGTH_SHORT).show();
            Intent DetailIntent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    forecast);
            startActivity(DetailIntent);
        }
    });

    return rootView;
}

From source file:com.example.android.sunshine.fragments.ForecastFragment.java

@Override
public void onViewCreated(View view, @Nullable 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.
    // The current context (this activity)
    // The name of the layout ID.
    // The ID of the textview to populate.
    mForecastAdapter = new ArrayAdapter<>(getActivity(), // The current context (this activity)
            R.layout.list_item_forecast, // The name of the layout ID.
            R.id.tvListItemForecast, // The ID of the textview to populate.
            new ArrayList<String>());

    // Get a referece to the ListView and attach the adapter to it.
    ListView listView = (ListView) view.findViewById(R.id.listView_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from   w  ww.  j  a va 2s.  c o  m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String forecast = mForecastAdapter.getItem(position);
            Intent intent = new Intent(getActivity(), DetailActivity.class);
            intent.putExtra(Intent.EXTRA_TEXT, forecast);
            startActivity(intent);
        }
    });
}

From source file:com.sayo.android.sunshine.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.
    mForecastAdapter = new ArrayAdapter<String>(getActivity(), // The current context (this activity)
            R.layout.list_item_forcast, // 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(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override/*from w  ww.  j  a  va  2 s. c om*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String forecast = (String) parent.getItemAtPosition(position);
            Intent otherIntent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    forecast);

            startActivity(otherIntent);
        }
    });
    return rootView;
}

From source file:com.example.abrahamrequena.sunshine.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.
    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.
            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(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from w  w w .  jav a  2 s  .  c om
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            CharSequence forecast = mForecastAdapter.getItem(position);
            Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    forecast);
            startActivity(intent);
        }
    });

    return rootView;
}

From source file:com.thathwam.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);//  w w w . j a  v  a2 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.
    final ListView listView = (ListView) rootView.findViewById(R.id.listview_forecast);
    listView.setAdapter(mForecastAdapter);

    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String forecast = mForecastAdapter.getItem(position);
            Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    forecast);
            startActivity(intent);
        }
    });

    return rootView;
}

From source file:com.davila.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
    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);//w  w w.  j  a v  a 2s . 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.listview_forecast);
    listView.setAdapter(mForecastAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String forecast = mForecastAdapter.getItem(position);
            Intent intent = new Intent(getActivity(), DetailActivity.class).putExtra(Intent.EXTRA_TEXT,
                    forecast);
            startActivity(intent);
            //Toast.makeText(getActivity(), forecast, Toast.LENGTH_SHORT).show();

        }
    });

    return rootView;
}