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.android.projectz.teamrocket.thebusapp.settings.SettingLanguageActivity.java

/**
 * Metodo che serve a far visualizzare la lista con le relative personalizzazioni all'interno della schermata
 * <p>//  w ww .  j a  va 2 s  .c om
 * ho deciso di fare ci in modo tale da richiamare il metodo quando la lingua viene cambiata, cosi la vista 
 * aggiornata con la lingua selezionata
 */
@Override
protected void onStart() {
    super.onStart();
    String[] settingText = { getString(R.string.setting_language), getString(R.string.commit_translation) };
    String[] settingsubtext = {
            getCompleateLanguage(SharedPreferencesUtils.getSelectedLanguage(SettingLanguageActivity.this)),
            getString(R.string.language_bug_subtitle) };
    Drawable[] settingImg = { ContextCompat.getDrawable(this, R.drawable.ic_language),
            ContextCompat.getDrawable(this, R.drawable.ic_report_language) };

    CustomListSettingOther customList = new CustomListSettingOther(SettingLanguageActivity.this, settingText,
            settingsubtext, settingImg);
    ListView list = (ListView) findViewById(R.id.language_setting_list);
    list.setAdapter(customList);
    list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
            switch (position) {
            case 0:
                int languageCode = 0;
                switch (SharedPreferencesUtils.getSelectedLanguage(SettingLanguageActivity.this)) {
                case "it":
                    languageCode = 0;
                    break;
                case "en":
                    languageCode = 1;
                    break;
                case "fr":
                    languageCode = 2;
                    break;
                case "de":
                    languageCode = 3;
                    break;
                case "es":
                    languageCode = 4;
                    break;
                case "ua":
                    languageCode = 5;
                    break;
                case "kg":
                    languageCode = 6;
                    break;
                }
                new MaterialDialog.Builder(SettingLanguageActivity.this).title(R.string.dialog_title_language)
                        .items(R.array.language)
                        .itemsCallbackSingleChoice(languageCode, new MaterialDialog.ListCallbackSingleChoice() {
                            @Override
                            public boolean onSelection(MaterialDialog dialog, View view, int which,
                                    CharSequence text) {
                                try {
                                    SharedPreferencesUtils.setSelectedLanguage(SettingLanguageActivity.this,
                                            getShortLanguage(which));
                                    setLocale(getShortLanguage(which));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                    setLocale("it");
                                }
                                return true;
                            }
                        }).positiveText(R.string.dialog_ok_button).show();
                break;

            case 1:
                Intent intent = new Intent(SettingLanguageActivity.this, BugReportActivity.class);
                intent.putExtra("PRECOMPILED_FORM", getString(R.string.language_bug_textfield));
                startActivity(intent);
                SettingLanguageActivity.this.overridePendingTransition(R.anim.anim_slide_in_left,
                        R.anim.anim_slide_out_left);
                break;
            }
        }
    });
}

From source file:com.hybris.mobile.app.commerce.fragment.OrderConfirmationFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    mOrderConfirmNumber = (TextView) getView().findViewById(R.id.order_confirm_number_text);
    mOrderConfirmEmail = (TextView) getView().findViewById(R.id.order_confirm_email);

    // Product list
    ListView productList = (ListView) getActivity().findViewById(R.id.order_products_list);
    mOrderProductListAdapter = new OrderProductListAdapter(getActivity(), new ArrayList<OrderEntry>());
    productList.setAdapter(mOrderProductListAdapter);

    getView().findViewById(R.id.order_confirm_continue_shopping_button)
            .setOnClickListener(orderConfirmContinueShoppingButtonListener);
    QueryOrder queryOrder = new QueryOrder();
    queryOrder.setCode(getActivity().getIntent().getStringExtra(IntentConstants.ORDER_CODE));

    // Getting the order
    CommerceApplication.getContentServiceHelper().getOrder(this, mOrderRequestId, queryOrder, null, false, null,
            new OnRequestListener() {

                @Override/*from  w w w.j  a  va 2 s .  c o m*/
                public void beforeRequest() {
                    UIUtils.showLoadingActionBar(getActivity(), true);
                    getView().setVisibility(View.INVISIBLE);
                }

                @Override
                public void afterRequestBeforeResponse() {

                }

                @Override
                public void afterRequest(boolean isDataSynced) {
                    getView().setVisibility(View.VISIBLE);
                    UIUtils.showLoadingActionBar(getActivity(), false);
                }
            });
}

From source file:br.unisinos.evertonlucas.passshelter.app.SendResourceGroupActivity.java

public void loadListAdapter(ListView listView, List<String> names, int resource) {
    String[] from = { "name" };
    int[] to = { R.id.txt_send_resource_group };
    SimpleAdapter adapter = new SimpleAdapter(this, listResources(names), resource, from, to);
    listView.setAdapter(adapter);
}

From source file:carsharing.starter.automotive.iot.ibm.com.mobilestarterapp.Reservations.Reservations.java

public void setContent(final ArrayList<ReservationsData> reservationsArray) {
    final FragmentActivity activity = getActivity();
    if (activity == null) {
        return;//from w  w  w . ja  va2s . com
    }
    final ListView listView = (ListView) view.findViewById(R.id.listView);

    final ReservationsDataAdapter adapter = new ReservationsDataAdapter(activity.getApplicationContext(),
            reservationsArray);
    listView.setAdapter(adapter);

    final ArrayList<ReservationsData> finalReservationsArray = reservationsArray;
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapter, View view, int position, long arg) {
            final Intent completeReservation = new Intent(view.getContext(), CompleteReservation.class);

            final Bundle bundle = new Bundle();
            bundle.putSerializable("reservationData", finalReservationsArray.get(position));
            completeReservation.putExtras(bundle);

            startActivity(completeReservation);
        }
    });

    final ActionBar supportActionBar = ((AppCompatActivity) activity).getSupportActionBar();
    switch (reservations.size()) {
    case 0:
        supportActionBar.setTitle("You have no reservations.");
    case 1:
        supportActionBar.setTitle("You have one reservation.");
    default:
        supportActionBar.setTitle("You have " + reservations.size() + " reservations.");
    }
}

From source file:ch.jeda.platform.android.SelectionDialogFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    final ListView result = new ListView(this.getActivity());
    this.listAdapter = new ListAdapterImp(this.getActivity());
    this.listAdapter.setItems(this.request.getDisplayItems());
    result.setAdapter(this.listAdapter);
    result.setOnItemClickListener(new OnItemClickListenerImp(this));
    this.selectedItemPosition = -1;
    return result;
}

From source file:com.classiqo.nativeandroid_32bitz.ui.MediaBrowserFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    LogHelper.d(TAG, "fragment.onCreateView");
    View rootView = inflater.inflate(R.layout.fragment_list, container, false);

    mErrorView = rootView.findViewById(R.id.playback_error);
    mErrorMessage = (TextView) mErrorView.findViewById(R.id.error_message);

    mBrowserAdapter = new BrowserAdapter(getActivity());

    ListView listView = (ListView) rootView.findViewById(R.id.list_view);
    listView.setAdapter(mBrowserAdapter);
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from  w  ww.j  a  va 2s.  c  om
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            checkForUserVisibleErrors(false);
            MediaBrowserCompat.MediaItem item = mBrowserAdapter.getItem(position);
            mMediaFragmentListener.onMediaItemSelected(item);
        }
    });

    return rootView;
}

From source file:org.bitbucket.ntakimura.android.support.fragment.OpenSourceLicenseFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    mLogger.entering(getClass().getName(), "onCreateView",
            new Object[] { inflater, container, savedInstanceState });

    FrameLayout lframe = new FrameLayout(getActivity());

    ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);/*from w  ww. ja  v a 2  s  . co  m*/
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    lframe.setBackgroundColor(getResources().getColor(android.R.color.background_light));

    ArrayAdapter<Parcelable> adapter = new SoftwareArrayAdapter(getActivity(), R.layout.card_item);
    if (getArguments() != null && getArguments().containsKey(EXTRA_OSS)) {
        adapter.addAll(getArguments().getParcelableArrayList(EXTRA_OSS));
    }

    ListView listView = (ListView) lframe.findViewById(android.R.id.list);
    listView.setAdapter(adapter);

    getDialog().setTitle(R.string.open_source_licenses);

    mLogger.exiting(getClass().getName(), "onCreateView", lframe);
    return lframe;
}

From source file:android.example.com.rottentomatillos.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    insertData();/*from w w  w.  j a v a  2  s  . c  o  m*/

    // Get the ListView which will be populated with the TomatilloProvider data.
    ListView listView = (ListView) findViewById(R.id.tomatillo_list_view);

    // Note that the cursor is null because data will be loaded in via a loader
    mAdapter = new RatingAdapter(this, null, 0, CURSOR_LOADER_ID);

    // Attach the adapter to the ListView.
    listView.setAdapter(mAdapter);

    // Initializes the loader.
    getSupportLoaderManager().initLoader(CURSOR_LOADER_ID, null, this);
}

From source file:com.example.android.bluetoothchat.DeviceListActivity.java

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

    // ??// ww  w. ja  v a  2 s.co  m
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    setContentView(R.layout.activity_device_list);

    // ????????????CANCELED
    setResult(Activity.RESULT_CANCELED);

    // ????????
    Button scanButton = (Button) findViewById(R.id.button_scan);
    scanButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            doDiscovery();
            v.setVisibility(View.GONE);
        }
    });

    //???????
    Button startchatButton = (Button) findViewById(R.id.button_start_chat);
    startchatButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            connect();
        }
    });

    // array adapters??.
    // ??????????????
    ArrayAdapter<String> pairedDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);
    mNewDevicesArrayAdapter = new ArrayAdapter<String>(this, R.layout.device_name);

    // ????ListView?
    pairedListView = (ListView) findViewById(R.id.paired_devices);
    pairedListView.setAdapter(pairedDevicesArrayAdapter);
    pairedListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);

    // ????????ListView?
    ListView newDevicesListView = (ListView) findViewById(R.id.new_devices);
    newDevicesListView.setAdapter(mNewDevicesArrayAdapter);
    newDevicesListView.setOnItemClickListener(mDeviceClickListener);

    // ????
    IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    this.registerReceiver(mReceiver, filter);

    // ???
    filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
    this.registerReceiver(mReceiver, filter);

    // local Bluetooth adapter??
    mBtAdapter = BluetoothAdapter.getDefaultAdapter();

    // ????
    Set<BluetoothDevice> pairedDevices = mBtAdapter.getBondedDevices();

    // ????????ArrayAdapter??
    if (pairedDevices.size() > 0) {
        findViewById(R.id.title_paired_devices).setVisibility(View.VISIBLE);
        for (BluetoothDevice device : pairedDevices) {
            pairedDevicesArrayAdapter.add(device.getName() + "\n" + device.getAddress());
        }
    } else {
        String noDevices = getResources().getText(R.string.none_paired).toString();
        pairedDevicesArrayAdapter.add(noDevices);
    }
}

From source file:org.deviceconnect.android.manager.setting.OpenSourceLicenseFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    mLogger.entering(getClass().getName(), "onCreateView",
            new Object[] { inflater, container, savedInstanceState });

    FrameLayout lframe = new FrameLayout(getActivity());

    ListView lv = new ListView(getActivity());
    lv.setId(android.R.id.list);/* w  w  w.jav  a2 s  .  c  om*/
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    lframe.setBackgroundColor(getResources().getColor(android.R.color.background_light));

    ArrayAdapter<Parcelable> adapter = new SoftwareArrayAdapter(getActivity(),
            R.layout.item_open_source_licenses);
    if (getArguments() != null && getArguments().containsKey(EXTRA_OSS)) {
        adapter.addAll(getArguments().getParcelableArrayList(EXTRA_OSS));
    }

    ListView listView = (ListView) lframe.findViewById(android.R.id.list);
    listView.setAdapter(adapter);

    getDialog().setTitle(R.string.activity_settings_open_source_licenses);

    mLogger.exiting(getClass().getName(), "onCreateView", lframe);
    return lframe;
}