Ejemplo n.º 1
0
 public void mOnClick(View v) {
   switch (v.getId()) {
     case R.id.btn3:
       mItem.clear();
       for (int i = 1001; i <= 1003; i++) {
         mItem.add(Integer.toString(i));
       }
       mAdapter.notifyDataSetChanged();
       break;
     case R.id.btn10:
       mItem.clear();
       for (int i = 1001; i <= 1010; i++) {
         mItem.add(Integer.toString(i));
       }
       mAdapter.notifyDataSetChanged();
       break;
     case R.id.btnalways:
       mList.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
       break;
     case R.id.btnnever:
       mList.setOverScrollMode(View.OVER_SCROLL_NEVER);
       break;
     case R.id.btnifscroll:
       mList.setOverScrollMode(View.OVER_SCROLL_IF_CONTENT_SCROLLS);
       break;
   }
 }
Ejemplo n.º 2
0
  @Override
  public void onStart() {
    super.onStart();
    if (D) Log.d(TAG, "++ ON START ++");

    if (!mBluetoothAdapter.isEnabled()) {
      // ask the user to enable BlueTooth
      Intent enableIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
      startActivityForResult(enableIntent, REQUEST_ENABLE_BT);
    } else {
      // this only works if you already bonded with this device
      if (D) Log.d(TAG, "BT already enabled");

      final BluetoothDevice[] bondedDevices =
          new BluetoothDevice[mBluetoothAdapter.getBondedDevices().size()];
      mBluetoothAdapter.getBondedDevices().toArray(bondedDevices);

      List<CharSequence> devices = new ArrayList<CharSequence>();

      // update the "Select device" spinner
      for (BluetoothDevice btd : bondedDevices) {
        Log.d(TAG, "Found bonded device: " + btd.getName());
        devices.add(btd.getName());
      }

      ArrayAdapter spinnerAdapter =
          new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, devices);
      spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

      Spinner selectDeviceSpinner = (Spinner) findViewById(R.id.spinner);
      selectDeviceSpinner.setAdapter(spinnerAdapter);

      selectDeviceSpinner.setOnItemSelectedListener(
          new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
              if (D) Log.d(TAG, "Selected: " + bondedDevices[pos].getName());
              btDevice = bondedDevices[pos];
            }

            public void onNothingSelected(AdapterView<?> arg0) {}
          });
    }
  }