private void setupSpinner(Spinner spinner, int optionResourceId, int defaultSelection) {
    Context context = getContext();
    if (context != null) {
      ArrayAdapter<CharSequence> adapter =
          ArrayAdapter.createFromResource(
              context, optionResourceId, android.R.layout.simple_spinner_item);

      adapter.setDropDownViewResource(R.layout.spinner_centered_wrapped);
      spinner.setGravity(Gravity.CENTER);
      spinner.setAdapter(adapter);
      spinner.setSelection(defaultSelection);
    }
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (container == null) {
      return null;
    }

    Log.e(">>@@", "onCreateView");

    super.onCreate(savedInstanceState);

    View view = inflater.inflate(R.layout.device_ft2232htest, container, false);

    readData_0 = new byte[readLength];
    readDataToText_0 = new char[readLength];
    readData_1 = new byte[readLength];
    readDataToText_1 = new char[readLength];
    // setContentView(R.layout.main);

    // cleanPreference();
    /* create editable text objects */
    readText_0 = (EditText) view.findViewById(R.id.ReadValues);
    readText_0.setInputType(0);
    writeText_0 = (EditText) view.findViewById(R.id.WriteValues);
    configButton_0 = (Button) view.findViewById(R.id.configButton);
    writeButton_0 = (Button) view.findViewById(R.id.WriteButton);

    readText_1 = (EditText) view.findViewById(R.id.ReadValues1);
    readText_1.setInputType(0);
    writeText_1 = (EditText) view.findViewById(R.id.WriteValues1);
    configButton_1 = (Button) view.findViewById(R.id.configButton1);
    writeButton_1 = (Button) view.findViewById(R.id.WriteButton1);
    // originalDrawable = configButton.getBackground();

    /* allocate buffer */
    //		writeBuffer = new char[64];
    //		readBuffer = new char[64];
    //		actualNumBytes = new byte[1];

    /* setup the baud rate list */
    baudSpinner = (Spinner) view.findViewById(R.id.baudRateValue);
    ArrayAdapter<CharSequence> baudAdapter =
        ArrayAdapter.createFromResource(
            DeviceFT2232HTestContext, R.array.baud_rate, android.R.layout.simple_spinner_item);
    baudAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    baudSpinner.setAdapter(baudAdapter);
    baudSpinner.setGravity(0x10);
    baudSpinner.setSelection(4);
    /* by default it is 9600 */
    baudRate = 9600;

    /* stop bits */
    stopSpinner = (Spinner) view.findViewById(R.id.stopBitValue);
    ArrayAdapter<CharSequence> stopAdapter =
        ArrayAdapter.createFromResource(
            DeviceFT2232HTestContext, R.array.stop_bits, android.R.layout.simple_spinner_item);

    stopAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    stopSpinner.setAdapter(stopAdapter);
    stopSpinner.setGravity(0x01);
    /* default is stop bit 1 */
    stopBit = 1;

    /* daat bits */
    dataSpinner = (Spinner) view.findViewById(R.id.dataBitValue);
    ArrayAdapter<CharSequence> dataAdapter =
        ArrayAdapter.createFromResource(
            DeviceFT2232HTestContext, R.array.data_bits, android.R.layout.simple_spinner_item);

    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    dataSpinner.setAdapter(dataAdapter);
    dataSpinner.setGravity(0x11);
    dataSpinner.setSelection(1);
    /* default data bit is 8 bit */
    dataBit = 8;

    /* parity */
    paritySpinner = (Spinner) view.findViewById(R.id.parityValue);
    ArrayAdapter<CharSequence> parityAdapter =
        ArrayAdapter.createFromResource(
            DeviceFT2232HTestContext, R.array.parity, android.R.layout.simple_spinner_item);

    parityAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    paritySpinner.setAdapter(parityAdapter);
    paritySpinner.setGravity(0x11);
    /* default is none */
    parity = 0;

    /* flow control */
    flowSpinner = (Spinner) view.findViewById(R.id.flowControlValue);
    ArrayAdapter<CharSequence> flowAdapter =
        ArrayAdapter.createFromResource(
            DeviceFT2232HTestContext, R.array.flow_control, android.R.layout.simple_spinner_item);

    flowAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    flowSpinner.setAdapter(flowAdapter);
    flowSpinner.setGravity(0x11);
    /* default flow control is is none */
    flowControl = 0;

    /* set the adapter listeners for baud */
    baudSpinner.setOnItemSelectedListener(new MyOnBaudSelectedListener());
    /* set the adapter listeners for stop bits */
    stopSpinner.setOnItemSelectedListener(new MyOnStopSelectedListener());
    /* set the adapter listeners for data bits */
    dataSpinner.setOnItemSelectedListener(new MyOnDataSelectedListener());
    /* set the adapter listeners for parity */
    paritySpinner.setOnItemSelectedListener(new MyOnParitySelectedListener());
    /* set the adapter listeners for flow control */
    flowSpinner.setOnItemSelectedListener(new MyOnFlowSelectedListener());

    configButton_0.setOnClickListener(
        new View.OnClickListener() {
          // @Override
          public void onClick(View v) {
            // configButton.setBackgroundResource(drawable.start);
            Log.e(">>@@", "configButton_0 - onClick+");

            if (true == SetConfig(0, baudRate, dataBit, stopBit, parity, flowControl)) {
              read_thread_0 = new readThread(handler);
              read_thread_0.start();
            }
            Log.e(">>@@", "configButton_0 - onClick-");
          }
        });

    configButton_1.setOnClickListener(
        new View.OnClickListener() {
          // @Override
          public void onClick(View v) {
            // configButton.setBackgroundResource(drawable.start);
            Log.e(">>@@", "configButton_1 - onClick+");

            if (true == SetConfig(1, baudRate, dataBit, stopBit, parity, flowControl)) {
              read_thread_1 = new readThread_1(handler);
              read_thread_1.start();
            }
            Log.e(">>@@", "configButton_1 - onClick-");
          }
        });

    /* handle write click */
    writeButton_0.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Log.e(">>@@", "writeButton_1 - onClick+");
            SendMessage(v);
            Log.e(">>@@", "writeButton_1 - onClick-");
          }
        });

    writeButton_1.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View v) {
            Log.e(">>@@", "writeButton_1 - onClick+");
            SendMessage_1(v);
            Log.e(">>@@", "writeButton_1 - onClick-");
          }
        });

    return view;
  }