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:Main.java

public static void fillList(Context context, ListView lv, List<String> ls) {
    ArrayAdapter<String> adapter = new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, ls);
    lv.setAdapter(adapter);
}

From source file:li.klass.fhem.adapter.devices.genericui.AvailableTargetStatesDialogUtil.java

public static <D extends FhemDevice<D>> TypeHandler<D> handlerForSelectedOption(D device, Context context,
        final String option, final TargetStateSelectedCallback callback) {

    SetList setList = device.getSetList();
    final SetListValue setListValue = setList.get(option);

    final DeviceStateRequiringAdditionalInformation specialDeviceState = DeviceStateRequiringAdditionalInformation
            .deviceStateForFHEM(option);

    if (setListValue instanceof SetListSliderValue) {
        final SetListSliderValue sliderValue = (SetListSliderValue) setListValue;
        return new TypeHandler<D>() {
            private int dimProgress = 0;

            @Override/*  w ww .j av  a2s . co  m*/
            public View getContentViewFor(Context context, D device) {
                TableLayout tableLayout = new TableLayout(context);
                int initialProgress = 0;
                if (device instanceof DimmableDevice) {
                    initialProgress = ((DimmableDevice) device).getDimPosition();
                }

                tableLayout.addView(new DeviceDimActionRowFullWidth<D>(initialProgress, sliderValue.getStart(),
                        sliderValue.getStep(), sliderValue.getStop(), null,
                        R.layout.device_detail_seekbarrow_full_width) {

                    @Override
                    public void onStopDim(Context context, D device, int progress) {
                        dimProgress = progress;
                    }

                    @Override
                    public String toDimUpdateText(D device, int progress) {
                        return null;
                    }
                }.createRow(LayoutInflater.from(context), device));
                return tableLayout;
            }

            @Override
            public boolean onPositiveButtonClick(View view, Context context, D device) {
                callback.onTargetStateSelected(option, "" + dimProgress, device, context);
                return true;
            }
        };
    } else if (setListValue instanceof SetListGroupValue) {
        final SetListGroupValue groupValue = (SetListGroupValue) setListValue;
        final List<String> groupStates = groupValue.getGroupStates();
        return new TypeHandler<D>() {

            @Override
            public View getContentViewFor(final Context context, final D device) {
                ListView listView = new ListView(context);
                listView.setAdapter(
                        new ArrayAdapter<>(context, android.R.layout.simple_list_item_1, groupStates));
                listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                    @Override
                    public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
                        String selection = groupStates.get(position);
                        callback.onTargetStateSelected(option, selection, device, context);
                        dialog.dismiss();
                    }
                });

                return listView;
            }

            @Override
            boolean requiresPositiveButton() {
                return false;
            }
        };
    } else if (specialDeviceState != null) {
        return new TypeHandler<D>() {

            private EditText editText;

            @Override
            public View getContentViewFor(Context context, D device) {
                editText = new EditText(context);
                return editText;
            }

            @Override
            public boolean onPositiveButtonClick(View view, Context context, D device) {
                Editable value = editText.getText();
                String text = value == null ? "" : value.toString();

                if (isValidAdditionalInformationValue(text, specialDeviceState)) {
                    callback.onTargetStateSelected(option, text, device, context);
                    return true;
                } else {
                    DialogUtil.showAlertDialog(context, R.string.error, R.string.invalidInput);
                    return false;
                }
            }
        };
    } else {
        callback.onTargetStateSelected(option, null, device, context);
        return null;
    }
}

From source file:com.aleiacampo.oristanobus.util.NavigationDrawerUtil.java

public static void setFavourites(final AppCompatActivity appCompatActivity) {

    final Bundle bundle = new Bundle();
    final ArrayList<Stop> stopsList;

    SQLiteHelper db = new SQLiteHelper(appCompatActivity);
    stopsList = db.getAllStops();/*from w w w  .jav a2 s .  c o m*/
    ArrayList<String> stopsNameList = new ArrayList<>();

    for (Stop stop : stopsList) {
        stopsNameList.add(stop.nameStop);
    }

    if (stopsList.isEmpty())
        stopsNameList.add("Nessuna fermata salvata");

    ListView favourites = (ListView) appCompatActivity.findViewById(R.id.favourite_list);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(appCompatActivity.getApplicationContext(),
            R.layout.text_view, stopsNameList);
    favourites.setAdapter(adapter);

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

            bundle.putInt("id_stop", stopsList.get(position).idStop);
            bundle.putInt("id_line", stopsList.get(position).idLine);
            bundle.putString("name_stop", stopsList.get(position).nameStop);
            bundle.putString("name_line", stopsList.get(position).nameLine);

            DrawerLayout drawer = (DrawerLayout) appCompatActivity.findViewById(R.id.drawer_left);
            drawer.closeDrawer(Gravity.LEFT);

            FragmentManager fragmentManager = appCompatActivity.getSupportFragmentManager();
            TimesFragment timesFragment = new TimesFragment();
            timesFragment.setArguments(bundle);
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.home_frag, timesFragment, "Times");
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }
    });

    favourites.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> arg0, View view, final int pos, long id) {

            AlertDialog.Builder alertDialog = new AlertDialog.Builder(appCompatActivity);
            alertDialog.setMessage("Rimuovere la fermata dai preferiti?");
            alertDialog.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    SQLiteHelper db2 = new SQLiteHelper(appCompatActivity);
                    db2.deleteStop(stopsList.get(pos).id); // l'id della fermata caricato dal db
                    NavigationDrawerUtil.setFavourites(appCompatActivity);
                    dialog.cancel();
                }
            });
            alertDialog.setNegativeButton("Nope !", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
            alertDialog.show();
            return true;
        }
    });

    favourites.setLongClickable(true);
}

From source file:com.aleiacampo.oristanobus.util.ViewUtil.java

public static void loadMostSearched(final AppCompatActivity appCompatActivity) {

    final ArrayList<Stop> stopsList = new ArrayList<>();
    final ArrayList<String> stopsNameList = new ArrayList<>();

    new AsyncTask<Void, Void, Void>() {

        @Override/*  w w w.  ja va  2s  .  com*/
        protected void onPreExecute() {
            super.onPreExecute();
            if (!ConnectionsHandler.isNetworkPresent(appCompatActivity)) {
                this.cancel(true);
                stopsNameList.add("Connessione dati non presente");
                ListView listView_searched = (ListView) appCompatActivity
                        .findViewById(R.id.textView_mostSerched);
                ArrayAdapter<String> adapter = new ArrayAdapter<>(appCompatActivity.getApplicationContext(),
                        R.layout.text_view, stopsNameList);
                listView_searched.setAdapter(adapter);
            }
        }

        @Override
        protected Void doInBackground(Void... params) {

            Stop stop;
            String url = "http://www.aleiacampo.com/stops.php?clicked=10";
            WebServerHandler webServerHandler = new WebServerHandler();
            String jsonStr = webServerHandler.getJSONData(url);
            try {
                JSONObject jsonObject = new JSONObject(jsonStr);
                JSONArray stopsJSON = jsonObject.getJSONArray("bus_stops");
                for (int i = 0; i < stopsJSON.length(); i++) {
                    JSONObject bus_stop = stopsJSON.getJSONObject(i);
                    stop = new Stop(bus_stop.getInt("id_line"), bus_stop.getInt("id_stop"),
                            bus_stop.getString("name_line"), bus_stop.getString("name_stop"));
                    stopsList.add(stop);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }

        @Override
        protected void onPostExecute(Void result) {
            super.onPostExecute(result);

            for (Stop stop : stopsList) {
                stopsNameList.add("Linea " + stop.idLine + " - " + stop.nameStop);
            }

            ListView listView_searched = (ListView) appCompatActivity.findViewById(R.id.textView_mostSerched);
            ArrayAdapter<String> adapter = new ArrayAdapter<>(appCompatActivity.getApplicationContext(),
                    R.layout.text_view, stopsNameList);
            listView_searched.setAdapter(adapter);
            listView_searched.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                    Bundle bundle = new Bundle();
                    bundle.putInt("id_stop", stopsList.get(position).idStop);
                    bundle.putInt("id_line", stopsList.get(position).idLine);
                    bundle.putString("name_line", stopsList.get(position).nameLine);
                    bundle.putString("name_stop", stopsList.get(position).nameStop);

                    FragmentManager fragmentManager = appCompatActivity.getSupportFragmentManager();
                    TimesFragment timesFragment = new TimesFragment();
                    timesFragment.setArguments(bundle);
                    appCompatActivity.onBackPressed();
                    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                    fragmentTransaction.replace(R.id.home_frag, timesFragment, "Times");
                    fragmentTransaction.addToBackStack(null);
                    fragmentTransaction.commit();

                }
            });
        }
    }.execute();
}

From source file:com.bidyut.app.wwquakes.QuakeInfoFragment.java

public void setQuake(Quake quake, AdapterView.OnItemClickListener listener) {
    final ListView lv = (ListView) getView().findViewById(R.id.list);
    lv.setAdapter(new QuakeInfoAdapter(getActivity(), quake));
    lv.setOnItemClickListener(listener);
}

From source file:com.cnpaypal.ObservableScrollView.BaseFragment.java

protected void setDummyData(ListView listView) {
    listView.setAdapter(new ArrayAdapter<>(getActivity(), android.R.layout.simple_list_item_1, getDummyData()));
}

From source file:com.aaa.activity.main.BaseFragment.java

protected void setDummyData(ListView listView) {
    listView.setAdapter(
            new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, getDummyData()));
}

From source file:aleajactatest.appiumcalculator.DummyListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final List<String> items = new ArrayList<String>();
    for (int i = 0; i < 30; i++)
        items.add("Sloubi " + (i + 1));
    final ArrayAdapter<String> la = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1,
            items);/* w  w  w.  j  av  a  2  s.  co  m*/
    ListView lv = (ListView) getView().findViewById(R.id.dummyList);
    lv.setAdapter(la);
}

From source file:com.bruce.study.demo.github.swipe_refresh_layout_demo.SwipeRefreshLayoutActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.swiperefresh_activity_layout);
    ListView mListView = (ListView) findViewById(R.id.listview);
    mListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, getData()));

    mSwipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
    mSwipeLayout.setOnRefreshListener(this);
    mSwipeLayout.setColorSchemeResources(android.R.color.holo_blue_bright, android.R.color.holo_green_light,
            android.R.color.holo_orange_light, android.R.color.holo_red_light);
}

From source file:com.example.android.tourguide.ArtsFragment.java

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

    View v = inflater.inflate(R.layout.fragment_arts, container, false);

    ArrayList<Location> arrayOfLocations = new ArrayList<Location>();
    LocationAdapter adapter = new LocationAdapter(getActivity(), arrayOfLocations);
    ListView listView = (ListView) v.findViewById(R.id.artsListView);

    listView.setAdapter(adapter);

    Location newLocation1 = new Location(getActivity().getString(R.string.glenbowname),
            getActivity().getString(R.string.glenbowaddress));
    Location newLocation2 = new Location(getActivity().getString(R.string.aerospacename),
            getActivity().getString(R.string.aerospaceaddress));
    Location newLocation3 = new Location(getActivity().getString(R.string.telusname),
            getActivity().getString(R.string.telusaddress));
    Location newLocation4 = new Location(getActivity().getString(R.string.hallname),
            getActivity().getString(R.string.halladdress));

    adapter.add(newLocation1);/*w  w  w  .  java2  s  .  co m*/
    adapter.add(newLocation2);
    adapter.add(newLocation3);
    adapter.add(newLocation4);

    return v;
}