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) 

Source Link

Document

Constructor

Usage

From source file:com.yschi.castscreen.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState != null) {
        mResultCode = savedInstanceState.getInt(STATE_RESULT_CODE);
        mResultData = savedInstanceState.getParcelable(STATE_RESULT_DATA);
    }//from  www  .ja v a 2s  . c o m

    mContext = this;
    mMediaProjectionManager = (MediaProjectionManager) getSystemService(Context.MEDIA_PROJECTION_SERVICE);

    mDiscoverdMap = new HashMap<>();
    mDiscoverListView = (ListView) findViewById(R.id.discover_listview);
    mDiscoverAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
    mDiscoverAdapter.addAll(mDiscoverdMap.keySet());
    mDiscoverListView.setAdapter(mDiscoverAdapter);
    mDiscoverListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            String name = mDiscoverAdapter.getItem(i);
            String ip = mDiscoverdMap.get(name);
            Log.d(TAG, "Select receiver name: " + name + ", ip: " + ip);
            mReceiverIp = ip;
            updateReceiverStatus();
            mContext.getSharedPreferences(PREF_COMMON, 0).edit().putString(PREF_KEY_RECEIVER, mReceiverIp)
                    .commit();
        }
    });

    // add server mode option
    mDiscoverAdapter.add(mContext.getString(R.string.server_mode));
    mDiscoverdMap.put(mContext.getString(R.string.server_mode), "");

    mReceiverTextView = (TextView) findViewById(R.id.receiver_textview);
    final EditText ipEditText = (EditText) findViewById(R.id.ip_edittext);
    final Button selectButton = (Button) findViewById(R.id.select_button);
    selectButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ipEditText.getText().length() > 0) {
                mReceiverIp = ipEditText.getText().toString();
                Log.d(TAG, "Using ip: " + mReceiverIp);
                updateReceiverStatus();
                mContext.getSharedPreferences(PREF_COMMON, 0).edit()
                        .putString(PREF_KEY_INPUT_RECEIVER, mReceiverIp).commit();
                mContext.getSharedPreferences(PREF_COMMON, 0).edit().putString(PREF_KEY_RECEIVER, mReceiverIp)
                        .commit();
            }
        }
    });
    ipEditText.setText(mContext.getSharedPreferences(PREF_COMMON, 0).getString(PREF_KEY_INPUT_RECEIVER, ""));

    Spinner formatSpinner = (Spinner) findViewById(R.id.format_spinner);
    ArrayAdapter<CharSequence> formatAdapter = ArrayAdapter.createFromResource(this, R.array.format_options,
            android.R.layout.simple_spinner_item);
    formatAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    formatSpinner.setAdapter(formatAdapter);
    formatSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            mSelectedFormat = FORMAT_OPTIONS[i];
            mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_FORMAT, i).commit();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            mSelectedFormat = FORMAT_OPTIONS[0];
            mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_FORMAT, 0).commit();
        }
    });
    formatSpinner.setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_FORMAT, 0));

    Spinner resolutionSpinner = (Spinner) findViewById(R.id.resolution_spinner);
    ArrayAdapter<CharSequence> resolutionAdapter = ArrayAdapter.createFromResource(this,
            R.array.resolution_options, android.R.layout.simple_spinner_item);
    resolutionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    resolutionSpinner.setAdapter(resolutionAdapter);
    resolutionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            mSelectedWidth = RESOLUTION_OPTIONS[i][0];
            mSelectedHeight = RESOLUTION_OPTIONS[i][1];
            mSelectedDpi = RESOLUTION_OPTIONS[i][2];
            mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_RESOLUTION, i).commit();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            mSelectedWidth = RESOLUTION_OPTIONS[0][0];
            mSelectedHeight = RESOLUTION_OPTIONS[0][1];
            mSelectedDpi = RESOLUTION_OPTIONS[0][2];
            mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_RESOLUTION, 0).commit();
        }
    });
    resolutionSpinner
            .setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_RESOLUTION, 0));

    Spinner bitrateSpinner = (Spinner) findViewById(R.id.bitrate_spinner);
    ArrayAdapter<CharSequence> bitrateAdapter = ArrayAdapter.createFromResource(this, R.array.bitrate_options,
            android.R.layout.simple_spinner_item);
    bitrateAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    bitrateSpinner.setAdapter(bitrateAdapter);
    bitrateSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            mSelectedBitrate = BITRATE_OPTIONS[i];
            mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_BITRATE, i).commit();
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {
            mSelectedBitrate = BITRATE_OPTIONS[0];
            mContext.getSharedPreferences(PREF_COMMON, 0).edit().putInt(PREF_KEY_BITRATE, 0).commit();
        }
    });
    bitrateSpinner.setSelection(mContext.getSharedPreferences(PREF_COMMON, 0).getInt(PREF_KEY_BITRATE, 0));

    mReceiverIp = mContext.getSharedPreferences(PREF_COMMON, 0).getString(PREF_KEY_RECEIVER, "");
    updateReceiverStatus();
    startService();
}

From source file:at.jclehner.rxdroid.preferences.DrugNamePreference2.java

@Override
protected View onCreateDialogView() {
    mEditText = new AutoCompleteTextView(getContext());
    mAutoCompleteAdapter = new ArrayAdapter<String>(this.getContext(),
            android.R.layout.simple_dropdown_item_1line);
    System.out.println("Initializing autocomplete...");
    mEditText.setThreshold(3);/*from  w  ww .j  a va  2  s . c  o m*/
    mEditText.setAdapter(mAutoCompleteAdapter);
    mEditText.addTextChangedListener(new TextWatcher() {
        private boolean shouldAutoComplete = true;

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            shouldAutoComplete = true;
            for (int position = 0; position < mAutoCompleteAdapter.getCount(); position++) {
                if (mAutoCompleteAdapter.getItem(position).equalsIgnoreCase(s.toString())) {
                    shouldAutoComplete = false;
                    break;
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (shouldAutoComplete) {
                new DoAutoCompleteSearch().execute(s.toString());
            }
        }
    });
    //      mEditText = new EditText(getContext());
    mEditText.setText(getValue());
    mEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    //mEditText.setSelectAllOnFocus(true);
    mEditText.addTextChangedListener(mWatcher);
    return mEditText;
}

From source file:com.authorwjf.bounce.BluetoothChat.java

private void setupChat() {
    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);

    // Initialize the BluetoothChatService to perform bluetooth connections
    mChatService = new BluetoothChatService(this, mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");

    BluetoothAdapter myAdapter = BluetoothAdapter.getDefaultAdapter();

    BluetoothDevice remoteDevice = myAdapter.getRemoteDevice(Main.macAddress);

    try {//from   w  w w . j  a  va 2s.c o m
        BluetoothSocket btSocket = remoteDevice
                .createRfcommSocketToServiceRecord(BluetoothChatService.MY_UUID_INSECURE);
        btSocket.connect();
    } catch (IOException exc) {
        System.out.println("Error connecting");
        stopSelf();
    }
    new AutomaticQueryThread(mSendButton, this).start();
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentSearch.java

private void InitiateClick() {
    listContainer.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override//from   w ww  . j av a 2s. co  m
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            mealId1 = mItem.get(position - 1).getID();
            mealBrand = mItem.get(position - 1).getBrand();
            mealFaborite = "false";
            AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity())
                    .setTitle("Choose Meal: ");
            final ArrayAdapter<String> mAdapterMoveMeal = new ArrayAdapter<>(getActivity(),
                    android.R.layout.simple_list_item_1);
            mAdapterMoveMeal.add("Snack");
            mAdapterMoveMeal.add("Breakfast");
            mAdapterMoveMeal.add("Lunch");
            mAdapterMoveMeal.add("Dinner");
            builderSingle.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            builderSingle.setAdapter(mAdapterMoveMeal, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String strName = mAdapterMoveMeal.getItem(which);
                    Intent i = new Intent(getActivity(), SaveSearchAddItemActivityMain.class);
                    i.putExtra(Globals.MEAL_TYPE, strName);
                    i.putExtra(Globals.MEAL_FAVORITE, "false");
                    i.putExtra(Globals.MEAL_ID, mealId1);
                    i.putExtra(Globals.MEAL_BRAND, mealBrand);
                    startActivity(i);
                }
            });
            builderSingle.show();
        }
    });
}

From source file:com.nextgis.mobile.map.LocalTMSLayer.java

protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName, int type,
        final Uri uri, final LocalTMSLayer layer) {
    final LinearLayout linearLayout = new LinearLayout(map.getContext());
    final EditText input = new EditText(map.getContext());
    input.setText(layerName);//from   ww w .ja v a 2  s.c o m

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(),
            android.R.layout.simple_spinner_item);
    final Spinner spinner = new Spinner(map.getContext());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    adapter.add(map.getContext().getString(R.string.tmstype_qtiles));
    adapter.add(map.getContext().getString(R.string.tmstype_osm));
    adapter.add(map.getContext().getString(R.string.tmstype_normal));
    adapter.add(map.getContext().getString(R.string.tmstype_ngw));

    if (type == TMSTYPE_OSM) {
        spinner.setSelection(1);
    } else {
        spinner.setSelection(2);
    }

    final TextView stLayerName = new TextView(map.getContext());
    stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":");

    final TextView stLayerType = new TextView(map.getContext());
    stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":");

    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(stLayerName);
    linearLayout.addView(input);
    linearLayout.addView(stLayerType);
    linearLayout.addView(spinner);

    new AlertDialog.Builder(map.getContext())
            .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties)
            //                                    .setMessage(message)
            .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (spinner.getSelectedItemPosition()) {
                    case 0:
                    case 1:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 2:
                    case 3:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }

                    if (bCreate) {
                        create(map, input.getText().toString(), tmsType, uri);
                    } else {
                        layer.setName(input.getText().toString());
                        layer.setTMSType(tmsType);
                        map.onLayerChanged(layer);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                    Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show();
                }
            }).show();
}

From source file:com.example.yudiandrean.socioblood.FeedActivity.java

@SuppressLint("NewApi")
@Override//from w  ww.j  a v a 2  s .c o m
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    final Dialog d = new Dialog(context);
    setContentView(R.layout.feed_activity);
    postrequest = (TextView) findViewById(R.id.editText);

    WindowManager manager = (WindowManager) getSystemService(Activity.WINDOW_SERVICE);
    final int width, height;
    ActionBar.LayoutParams params;

    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.FROYO) {
        width = manager.getDefaultDisplay().getWidth();
        height = manager.getDefaultDisplay().getHeight();
    } else {
        Point point = new Point();
        manager.getDefaultDisplay().getSize(point);
        width = point.x;
        height = point.y;
    }

    session = new SessionManager(getApplicationContext());

    // Check if user is already logged in or not
    if (!session.isLoggedIn()) {
        // User is already logged in. Take him to main activity
        Intent intent = new Intent(FeedActivity.this, LoginActivity.class);
        startActivity(intent);
        finish();
    }

    listView = (ListView) findViewById(R.id.list);
    swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeContainer);
    feedItems = new ArrayList<FeedItem>();

    listAdapter = new FeedListAdapter(this, feedItems);
    listView.setAdapter(listAdapter);

    swipeRefreshLayout.setOnRefreshListener(this);

    // add button listener
    postrequest.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {

            try {
                d.requestWindowFeature(Window.FEATURE_NO_TITLE);
                d.setContentView(R.layout.post_request);
                WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
                lp.copyFrom(d.getWindow().getAttributes());
                lp.width = width;
                lp.height = height;
                d.getWindow().setAttributes(lp);
            } catch (AndroidRuntimeException e) {
            } catch (Exception e) {
            }

            final Spinner rhesusspinner = (Spinner) d.findViewById(R.id.rhesus_spinner);
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(FeedActivity.this,
                    android.R.layout.simple_spinner_dropdown_item) {

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {

                    View v = super.getView(position, convertView, parent);
                    if (position == getCount()) {
                        ((TextView) v.findViewById(android.R.id.text1)).setText("");
                        ((TextView) v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed"
                    }

                    return v;
                }

                @Override
                public int getCount() {
                    return super.getCount() - 1; // you dont display last item. It is used as hint.
                }

            };

            adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            adapter.add("+");
            adapter.add("-");
            adapter.add("Rhesus");

            rhesusspinner.setAdapter(adapter);
            rhesusspinner.setSelection(adapter.getCount()); //display hint

            final Spinner bloodspinner = (Spinner) d.findViewById(R.id.bloodtype_spinner);
            ArrayAdapter<String> bloodadapter = new ArrayAdapter<String>(FeedActivity.this,
                    android.R.layout.simple_spinner_dropdown_item) {

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {

                    View v = super.getView(position, convertView, parent);
                    if (position == getCount()) {
                        ((TextView) v.findViewById(android.R.id.text1)).setText("");
                        ((TextView) v.findViewById(android.R.id.text1)).setHint(getItem(getCount())); //"Hint to be displayed"
                    }

                    return v;
                }

                @Override
                public int getCount() {
                    return super.getCount() - 1; // you dont display last item. It is used as hint.
                }

            };

            bloodadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            bloodadapter.add("O");
            bloodadapter.add("A");
            bloodadapter.add("B");
            bloodadapter.add("AB");
            bloodadapter.add("Desired Type");

            bloodspinner.setAdapter(bloodadapter);
            bloodspinner.setSelection(bloodadapter.getCount()); //display hint

            //Buttons-Editexts
            Button btnpost = (Button) d.findViewById(R.id.post);
            final EditText userInput = (EditText) d.findViewById(R.id.editTextDialogUserInput);

            d.show();

            btnpost.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if (bloodspinner.getSelectedItem().toString().equals("Desired Type")) {
                        Toast.makeText(getApplicationContext(), "Input Blood Type!", Toast.LENGTH_SHORT).show();
                    } else if (rhesusspinner.getSelectedItem().toString().equals("Rhesus")) {
                        Toast.makeText(getApplicationContext(), "Input Rhesus!", Toast.LENGTH_SHORT).show();
                    } else if (userInput.getText().toString().equals("")) {
                        Toast.makeText(getApplicationContext(), "Input your request message!",
                                Toast.LENGTH_SHORT).show();
                    } else {

                        int uid = session.currentUID();

                        String message = userInput.getText().toString();
                        String post_bloodtype = bloodspinner.getSelectedItem().toString();
                        String post_rhesus = rhesusspinner.getSelectedItem().toString();

                        NetAsync(d, view, uid, message, post_bloodtype, post_rhesus);

                    }
                }
            });

        }
    });

    //        // We first check for cached request
    //        Cache cache = FeedController.getInstance().getRequestQueue().getCache();
    //        Entry entry = cache.get(URL_FEED);
    //        if (entry != null) {
    //            // fetch the data from cache
    //            try {
    //                String data = new String(entry.data, "UTF-8");
    //                try {
    //                    parseJsonFeed(new JSONObject(data));
    //                } catch (JSONException e) {
    //                    e.printStackTrace();
    //                }
    //            } catch (UnsupportedEncodingException e) {
    //                e.printStackTrace();
    //            }
    //
    //        } else {
    // making fresh volley request and getting json

    /**
     * Showing Swipe Refresh animation on activity create
     * As animation won't start on onCreate, post runnable is used
     */
    swipeRefreshLayout.post(new Runnable() {
        @Override
        public void run() {
            swipeRefreshLayout.setRefreshing(true);
            getTimelineAsync();
        }
    });

}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.MainActivity.java

@SuppressLint("WorldReadableFiles")
@Override/*www . jav a 2s. c om*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);

    mInstance = this;

    mPrefManager = PreferenceManager.getDefaultSharedPreferences(this);

    Bundle extras = getIntent().getExtras();
    if (extras != null) {
        mAutomationPreferences = new HashMap<String, String>();
        mAutomationPreferences.put("pref_run_unattended", extras.getString("pref_run_unattended", ""));
        mAutomationPreferences.put("pref_mobile_service_url", extras.getString("pref_mobile_service_url", ""));
        mAutomationPreferences.put("pref_mobile_service_key", extras.getString("pref_mobile_service_key", ""));
        mAutomationPreferences.put("pref_google_userid", extras.getString("pref_google_userid", ""));
        mAutomationPreferences.put("pref_google_webapp_clientid",
                extras.getString("pref_google_webapp_clientid", ""));
        mAutomationPreferences.put("pref_master_run_id", extras.getString("pref_master_run_id", ""));
        mAutomationPreferences.put("pref_runtime_version", extras.getString("pref_runtime_version", ""));
        mAutomationPreferences.put("pref_daylight_client_id", extras.getString("pref_client_id", ""));
        mAutomationPreferences.put("pref_daylight_client_secret", extras.getString("pref_client_secret", ""));
        mAutomationPreferences.put("pref_daylight_url", extras.getString("pref_daylight_url", ""));
        mAutomationPreferences.put("pref_daylight_project", extras.getString("pref_daylight_project", ""));
    }

    mTestCaseList = (ListView) findViewById(R.id.testCaseList);
    TestCaseAdapter testCaseAdapter = new TestCaseAdapter(this, R.layout.row_list_test_case);
    mTestCaseList.setAdapter(testCaseAdapter);

    mTestGroupSpinner = (Spinner) findViewById(R.id.testGroupSpinner);

    ArrayAdapter<TestGroup> testGroupAdapter = new ArrayAdapter<TestGroup>(this,
            android.R.layout.simple_spinner_item);
    mTestGroupSpinner.setAdapter(testGroupAdapter);
    mTestGroupSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            selectTestGroup(pos);
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // do nothing
        }
    });

    ClientSDKLoginTests.mainActivity = this;

    PushTests.mainActivity = this;
    EnhancedPushTests.mainActivity = this;

    refreshTestGroupsAndLog();
}

From source file:com.example.android.BluetoothChat.BluetoothChat.java

private void setupChat() {
    Log.d(TAG, "setupChat()");

    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message2);
    mConversationView = (ListView) findViewById(R.id.in);
    mConversationView.setAdapter(mConversationArrayAdapter);

    // Initialize the compose field with a listener for the return key
    mOutEditText = (EditText) findViewById(R.id.edit_text_out);
    mOutEditText.setOnEditorActionListener(mWriteListener);

    // Initialize the send button with a listener that for click events
    mSendButton = (Button) findViewById(R.id.button_send);
    mSendButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            TextView view = (TextView) findViewById(R.id.edit_text_out);
            String message = view.getText().toString();
            sendMessage(message);//from  www .j a  va 2 s  .c o  m
        }
    });

    // Initialize the BluetoothChatService to perform bluetooth connections
    mChatService = new BluetoothChatService(this, mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}

From source file:com.example.hudpassthrough.BluetoothChat.java

private void setupChat() {
    // Initialize the array adapter for the conversation thread
    mConversationArrayAdapter = new ArrayAdapter<String>(this, R.layout.message);
    mConversationView = (ListView) findViewById(R.id.in);
    mConversationView.setAdapter(mConversationArrayAdapter);

    // Initialize the compose field with a listener for the return key
    mOutEditText = (EditText) findViewById(R.id.edit_text_out);
    mOutEditText.setOnEditorActionListener(mWriteListener);

    // Initialize the send button with a listener that for click events
    mSendButton = (Button) findViewById(R.id.button_send);
    mSendButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Send a message using content of the edit text widget
            TextView view = (TextView) findViewById(R.id.edit_text_out);
            String message = view.getText().toString();
            sendMessage(message);//  w  w  w.j  av a  2s  .  c om
        }
    });

    // Initialize the BluetoothChatService to perform bluetooth connections
    mChatService = new BluetoothChatService(this, mHandler);

    // Initialize the buffer for outgoing messages
    mOutStringBuffer = new StringBuffer("");
}