List of usage examples for android.widget ArrayAdapter add
public void add(@Nullable T object)
From source file:com.androguide.honamicontrol.kernel.cpucontrol.CPUActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //noinspection ConstantConditions getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setIcon(getResources().getDrawable(R.drawable.ic_tools_cpu_control)); setContentView(R.layout.card_cpu_control); bootPrefs = getSharedPreferences("BOOT_PREFS", 0); graph = (LineGraph) findViewById(R.id.graph); line = new Line(); LinePoint point = new LinePoint(); point.setX(currX);/*ww w .j a va 2s . c o m*/ point.setY(1); line.addPoint(point); line.setColor(Color.parseColor("#FFBB33")); graph.addLine(line); graph.setLineToFill(0); availableFrequencies = new String[0]; String availableFrequenciesLine; mCoresOnline = (TextView) findViewById(R.id.cores_online); mGeneralGovernor = (Spinner) findViewById(R.id.general_governor); mGovernor = (Spinner) findViewById(R.id.governor); mGovernor2 = (Spinner) findViewById(R.id.governor2); mGovernor3 = (Spinner) findViewById(R.id.governor3); mGovernor4 = (Spinner) findViewById(R.id.governor4); Button customizeGov = (Button) findViewById(R.id.governor_customize_btn); customizeGov.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { FragmentManager fm = getSupportFragmentManager(); GovernorDialog editNameDialog = new GovernorDialog(); editNameDialog.show(fm, "governor_fragment"); } }); if (Helpers.doesFileExist(STEPS)) { availableFrequenciesLine = CPUHelper.readOneLineNotRoot(STEPS); if (availableFrequenciesLine != null) { availableFrequencies = availableFrequenciesLine.split(" "); Arrays.sort(availableFrequencies, new Comparator<String>() { @Override public int compare(String object1, String object2) { return Integer.valueOf(object1).compareTo(Integer.valueOf(object2)); } }); } } Switch snakeCharmer = (Switch) findViewById(R.id.snake_charmer_switch); if (!Helpers.doesFileExist(SNAKE_CHARMER_MAX_FREQ)) { LinearLayout cardSnakeCharmer = (LinearLayout) findViewById(R.id.card_snake_charmer); cardSnakeCharmer.setVisibility(View.GONE); } else { if (Helpers.doesFileExist(SNAKE_CHARMER_VERSION)) { TextView snakeTitle = (TextView) findViewById(R.id.snake_charmer); String snakeVersion = CPUHelper.readOneLineNotRoot(SNAKE_CHARMER_VERSION); snakeVersion = snakeVersion.replaceAll("version: ", "v"); snakeTitle.setText(snakeTitle.getText() + " " + snakeVersion); if (snakeVersion.equals("v1.2")) { TextView snakeDesc = (TextView) findViewById(R.id.snake_charmer_text); snakeDesc.setText(snakeDesc.getText() + "\n" + getString(R.string.snake_charmer_built_in)); snakeCharmer.setEnabled(false); } } if (bootPrefs.getBoolean("SNAKE_CHARMER", true)) { snakeCharmer.setChecked(true); snakeCharmerEnabled = true; } snakeCharmer.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isOn) { snakeCharmerEnabled = isOn; } }); } int frequenciesNum = availableFrequencies.length - 1; Switch thermalControl = (Switch) findViewById(R.id.msm_thermal_switch); if (Helpers.doesFileExist(MSM_THERMAL)) { String thermal = CPUHelper.readOneLineNotRoot(MSM_THERMAL); if (thermal.equals("Y")) thermalControl.setChecked(true); else thermalControl.setChecked(false); thermalControl.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) Helpers.CMDProcessorWrapper.runSuCommand("echo Y > " + MSM_THERMAL); else Helpers.CMDProcessorWrapper.runSuCommand("echo N > " + MSM_THERMAL); bootPrefs.edit().putBoolean("MSM_THERMAL", isChecked).commit(); } }); } thermalControl.setChecked(bootPrefs.getBoolean("MSM_THERMAL", true)); perCoreGovernor = (Switch) findViewById(R.id.per_core_governors_switch); perCoreGovernor.setChecked(bootPrefs.getBoolean("PER_CORE_GOV", true)); if (perCoreGovernor.isChecked()) { findViewById(R.id.card_general_governor).setVisibility(View.GONE); findViewById(R.id.card_per_core_governors).setVisibility(View.VISIBLE); } else { findViewById(R.id.card_per_core_governors).setVisibility(View.GONE); findViewById(R.id.card_general_governor).setVisibility(View.VISIBLE); } perCoreGovernor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) { if (isChecked) { findViewById(R.id.card_general_governor).setVisibility(View.GONE); findViewById(R.id.card_per_core_governors).setVisibility(View.VISIBLE); handleGovernors(); } else { findViewById(R.id.card_per_core_governors).setVisibility(View.GONE); findViewById(R.id.card_general_governor).setVisibility(View.VISIBLE); handleGovernors(); } bootPrefs.edit().putBoolean("PER_CORE_GOV", isChecked).commit(); } }); String currentIo = ""; if (Helpers.doesFileExist(IO_SCHEDULER)) currentIo = CPUHelper.getIOScheduler(); String currentTcp = ""; if (Helpers.doesFileExist(CURR_TCP_ALGORITHM)) currentTcp = Helpers.getCurrentTcpAlgorithm(); String curMaxSpeed = "NaN"; if (Helpers.doesFileExist(MAX_FREQ_ALL_CORES)) curMaxSpeed = CPUHelper.readOneLineNotRoot(MAX_FREQ_ALL_CORES); else if (Helpers.doesFileExist(MAX_FREQ)) curMaxSpeed = CPUHelper.readOneLineNotRoot(MAX_FREQ); String curMinSpeed = "NaN"; if (Helpers.doesFileExist(MIN_FREQ_ALL_CORES)) curMinSpeed = CPUHelper.readOneLineNotRoot(MIN_FREQ_ALL_CORES); else if (Helpers.doesFileExist(MIN_FREQ)) curMinSpeed = CPUHelper.readOneLineNotRoot(MIN_FREQ); if (mIsTegra3) { String curTegraMaxSpeed = "NaN"; if (Helpers.doesFileExist(TEGRA_MAX_FREQ)) { curTegraMaxSpeed = CPUHelper.readOneLineNotRoot(TEGRA_MAX_FREQ); int curTegraMax = 0; try { curTegraMax = Integer.parseInt(curTegraMaxSpeed); if (curTegraMax > 0) { curMaxSpeed = Integer.toString(curTegraMax); } } catch (NumberFormatException ex) { curTegraMax = 0; } } } if (Helpers.doesFileExist(NUM_OF_CPUS)) mNumOfCpus = Helpers.getNumOfCpus(); mCurFreq = (TextView) findViewById(R.id.currspeed); mMaxSlider = (SeekBar) findViewById(R.id.max_slider); mMaxSlider.setMax(frequenciesNum); mMaxSpeedText = (TextView) findViewById(R.id.max_speed_text); mMaxSpeedText.setText(toMHz(curMaxSpeed)); mMaxSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMaxSpeed)); mMaxSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) setMaxSpeed(seekBar, progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { startSupportActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { MenuInflater inflater = actionMode.getMenuInflater(); inflater.inflate(R.menu.contextual_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.apply: if (mMaxFreqSetting != null && !mMaxFreqSetting.isEmpty()) { bootPrefs.edit().putString("CPU_MAX_FREQ", mMaxFreqSetting).commit(); for (int i = 0; i < mNumOfCpus; i++) Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + mMaxFreqSetting + " > " + MAX_FREQ.replace("cpu0", "cpu" + i)); if (snakeCharmerEnabled) Helpers.CMDProcessorWrapper.runSuCommand( "busybox echo " + mMaxFreqSetting + " > " + SNAKE_CHARMER_MAX_FREQ); } if (mIsTegra3) { if (mMaxFreqSetting != null && !mMaxFreqSetting.isEmpty()) Helpers.CMDProcessorWrapper.runSuCommand( "busybox echo " + mMaxFreqSetting + " > " + TEGRA_MAX_FREQ); if (snakeCharmerEnabled) Helpers.CMDProcessorWrapper.runSuCommand( "busybox echo " + mMaxFreqSetting + " > " + SNAKE_CHARMER_MAX_FREQ); } actionMode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); } }); mMinSlider = (SeekBar) findViewById(R.id.min_slider); mMinSlider.setMax(frequenciesNum); mMinSpeedText = (TextView) findViewById(R.id.min_speed_text); mMinSpeedText.setText(toMHz(curMinSpeed)); mMinSlider.setProgress(Arrays.asList(availableFrequencies).indexOf(curMinSpeed)); mMinSlider.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { if (fromUser) setMinSpeed(seekBar, progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { startSupportActionMode(new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode actionMode, Menu menu) { MenuInflater inflater = actionMode.getMenuInflater(); inflater.inflate(R.menu.contextual_menu, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode actionMode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode actionMode, MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.apply: if (mMinFreqSetting != null && !mMinFreqSetting.isEmpty()) { bootPrefs.edit().putString("CPU_MIN_FREQ", mMinFreqSetting).commit(); for (int i = 0; i < mNumOfCpus; i++) Helpers.CMDProcessorWrapper.runSuCommand("busybox echo " + mMinFreqSetting + " > " + MIN_FREQ.replace("cpu0", "cpu" + i)); } actionMode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode actionMode) { } }); } }); handleGovernors(); /** TCP Congestion Spinner */ Spinner mTcp = (Spinner) findViewById(R.id.tcp); ArrayAdapter<CharSequence> tcpAdapter = new ArrayAdapter<CharSequence>(this, R.layout.spinner_row); tcpAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); ArrayList<String> algorithms = Helpers.getTcpAlgorithms(); for (String algorithm : algorithms) tcpAdapter.add(algorithm); mTcp.setAdapter(tcpAdapter); mTcp.setSelection(algorithms.indexOf(currentTcp)); mTcp.setOnItemSelectedListener(new TCPListener()); onlineCoresPolling(); }
From source file:no.barentswatch.fiskinfo.BaseActivity.java
private static ArrayAdapter<String> createAndInitializeHintAdapter(int rPathToArray, String hint, Context context) {//from w w w .ja v a 2s. c om ArrayAdapter<String> adapter = new ArrayAdapter<String>(context, R.layout.spinner_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. } }; for (String field : context.getResources().getStringArray(rPathToArray)) { adapter.add(field); } // HACK WARNING: Adding last entry so we can display spinner // hint adapter.add(hint); adapter.setDropDownViewResource(R.layout.spinner_item); return adapter; }
From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpAirPlane.java
private void setLister() { timePicker = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { }/*from w w w.ja v a 2 s . c o m*/ }; timerPicker.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new TimePickerDialog(getActivity(), timePicker, 24, 59, true).show(); } }); departure.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.DEPARTURE_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.DEPARTURE_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.STOP_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_GPS); page.putExtras(flag); startActivityForResult(page, Constants.STOP_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); destination.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.DESTINATION_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_GPS); page.putExtras(flag); startActivityForResult(page, Constants.DESTINATION_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); getDataFromDB(); linearLayout_spec.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // custom dialog final Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.client_take_ride_selectspec_requirement); dialog.setTitle(getString(R.string.txt_take_spec)); Button cancel = (Button) dialog.findViewById(R.id.button_category_cancel); Button ok = (Button) dialog.findViewById(R.id.button_category_ok); //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // set the custom dialog components - text, image and button ListView requirement = (ListView) dialog.findViewById(R.id.listViewDialog); requirement.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ClientTakeRideSelectSpecListItem item = mCommentListData.get(position); item.check = !item.check; mCommentListData.set(position, item); listViewAdapter.notifyDataSetChanged(); } }); if (listViewAdapter == null) { listViewAdapter = new ClientTakeRideSelectSpecListItemAdapter(getActivity(), 0, mCommentListData); } requirement.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); dialog.show(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); String require; ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String require = ""; for (ClientTakeRideSelectSpecListItem item : mCommentListData) { if (item.check) { spec_list.add(item); require += item.book_title + ","; } } if (!require.isEmpty()) require = require.substring(0, require.length() - 1); spec_value.setText(require); dialog.cancel(); } }); } }); spec.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // custom dialog final Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.client_take_ride_selectspec_requirement); dialog.setTitle(getString(R.string.txt_take_spec)); Button cancel = (Button) dialog.findViewById(R.id.button_category_ok); //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // set the custom dialog components - text, image and button ListView requirement = (ListView) dialog.findViewById(R.id.listViewDialog); getDataFromDB(); listViewAdapter = new ClientTakeRideSelectSpecListItemAdapter(getActivity(), 0, mCommentListData); requirement.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); dialog.show(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); } }); spinner_airport_location_destination.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { currentLocation = tainStationList.get(position); destination_detail = new LocationAddress(); destination_detail.setLongitude(Double.parseDouble(currentLocation.getLng())); destination_detail.setLatitude(Double.parseDouble(currentLocation.getLat())); destination_detail.setAddress(currentLocation.getStreetAddress().substring(3, currentLocation.getStreetAddress().length())); destination_detail.setLocation(currentLocation.getLocation()); String zipCode = (getTrainStationZip(currentLocation.getLocation())); destination_detail.setZipCode(zipCode); destination_detail.setCountryName("Taiwan"); destination_detail.setLocality(currentLocation.getStreetAddress()); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); spinner_airport_location_departure.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { currentLocation = tainStationList.get(position); departure_detail = new LocationAddress(); departure_detail.setLongitude(Double.parseDouble(currentLocation.getLng())); departure_detail.setLatitude(Double.parseDouble(currentLocation.getLat())); departure_detail.setAddress(currentLocation.getStreetAddress().substring(3, currentLocation.getStreetAddress().length())); departure_detail.setLocation(currentLocation.getLocation()); //departure_detail.setZipCode(currentLocation.getStreetAddress().substring(0,3)); String zipCode = (getTrainStationZip(currentLocation.getLocation())); departure_detail.setZipCode(zipCode); departure_detail.setCountryName("Taiwan"); departure_detail.setLocality(currentLocation.getStreetAddress()); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); }
From source file:com.example.yudiandrean.socioblood.Register.java
/** * Called when the activity is first created. *//*from w w w . ja va 2s . co m*/ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.register); /** * Defining all layout items **/ inputFirstName = (EditText) findViewById(R.id.firstname); inputLastName = (EditText) findViewById(R.id.lastname); inputUsername = (EditText) findViewById(R.id.username); inputEmail = (EditText) findViewById(R.id.email); inputPassword = (EditText) findViewById(R.id.password); btnRegister = (Button) findViewById(R.id.register); registerErrorMsg = (TextView) findViewById(R.id.register_error); //Blood type spinner inputBloodType = (Spinner) findViewById(R.id.bloodtype_spinner); ArrayAdapter<String> bloodadapter = new ArrayAdapter<String>(Register.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("Blood Type"); inputBloodType.setAdapter(bloodadapter); inputBloodType.setSelection(bloodadapter.getCount()); //display hint //Rhesus spinner inputRhesus = (Spinner) findViewById(R.id.rhesus_spinner); ArrayAdapter<String> rhesusadapter = new ArrayAdapter<String>(Register.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. } }; rhesusadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); rhesusadapter.add("+"); rhesusadapter.add("-"); rhesusadapter.add("Rhesus"); inputRhesus.setAdapter(rhesusadapter); inputRhesus.setSelection(rhesusadapter.getCount()); //display hint inputGender = (Spinner) findViewById(R.id.gender_spinner); ArrayAdapter<String> genderadapter = new ArrayAdapter<String>(Register.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. } }; genderadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); genderadapter.add("Male"); genderadapter.add("Female"); genderadapter.add("Gender"); inputGender.setAdapter(genderadapter); inputGender.setSelection(genderadapter.getCount()); //display hint /** * Gets spinner value */ // Session manager 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(Register.this, UserPanel.class); startActivity(intent); finish(); } /** * Button which Switches back to the login screen on clicked **/ login = (Button) findViewById(R.id.bktologin); login.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent myIntent = new Intent(view.getContext(), LoginActivity.class); startActivityForResult(myIntent, 0); finish(); } }); /** * Register Button click event. * A Toast is set to alert when the fields are empty. * Another toast is set to alert Username must be 5 characters. **/ btnRegister.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if ((!inputUsername.getText().toString().equals("")) && (!inputPassword.getText().toString().equals("")) && (!inputFirstName.getText().toString().equals("")) && (!inputLastName.getText().toString().equals("")) && (!inputEmail.getText().toString().equals("")) && (!inputBloodType.getSelectedItem().toString().equals("")) && (!inputRhesus.getSelectedItem().toString().equals("")) && (!inputGender.getSelectedItem().toString().equals(""))) { if (inputUsername.getText().toString().length() > 4) { NetAsync(view); } else { Toast.makeText(getApplicationContext(), "Username must be a minimum of 5 characters", Toast.LENGTH_SHORT).show(); } } else { Toast.makeText(getApplicationContext(), "One or more fields are empty", Toast.LENGTH_SHORT) .show(); } } }); }
From source file:com.google.example.eightbitartist.DrawingActivity.java
/** * Set the list of words to display for guessing. *//* w w w. j a va 2 s . c om*/ private void resetWords(List<String> words) { ListView list = (ListView) findViewById(R.id.listView); ArrayAdapter<String> adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); for (String st : words) { adapter.add(st); } list.setAdapter(adapter); }
From source file:org.akvo.caddisfly.ui.activity.MainActivity.java
@Override public void onLoadCalibration(final Handler.Callback callback) { final Context context = this; final MainApp mainApp = (MainApp) this.getApplicationContext(); try {// ww w. j a v a 2s.c om AlertDialog.Builder builderSingle = new AlertDialog.Builder(context); builderSingle.setIcon(R.drawable.ic_launcher); builderSingle.setTitle(R.string.loadCalibration); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(context, android.R.layout.select_dialog_singlechoice); File external = Environment.getExternalStorageDirectory(); final String folderName = Config.CALIBRATE_FOLDER_NAME; String path = external.getPath() + folderName; File folder = new File(path); if (folder.exists()) { final File[] listFiles = folder.listFiles(); for (File listFile : listFiles) { arrayAdapter.add(listFile.getName()); } builderSingle.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String fileName = listFiles[which].getName(); final ArrayList<Integer> swatchList = new ArrayList<Integer>(); final ArrayList<String> rgbList = FileUtils.loadFromFile(fileName); if (rgbList != null) { for (String rgb : rgbList) { swatchList.add(ColorUtils.getColorFromRgb(rgb)); } (new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { mainApp.saveCalibratedSwatches(mainApp.currentTestInfo.getCode(), swatchList); mainApp.setSwatches(mainApp.currentTestInfo.getCode()); SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(context); SharedPreferences.Editor editor = sharedPreferences.edit(); for (int i = 0; i < mainApp.rangeIntervals.size(); i++) { int index = i * mainApp.rangeIncrementStep; ColorUtils.autoGenerateColors(index, mainApp.currentTestInfo.getCode(), mainApp.colorList, mainApp.rangeIncrementStep, editor, 0); } editor.apply(); return null; } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); callback.handleMessage(null); } }).execute(); } } }); final AlertDialog alert = builderSingle.create(); alert.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { final ListView listView = alert.getListView(); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) { final int position = i; AlertUtils.askQuestion(context, R.string.delete, R.string.selectedWillBeDeleted, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialogInterface, int i) { String fileName = listFiles[position].getName(); FileUtils.deleteFile(folderName, fileName); ArrayAdapter listAdapter = (ArrayAdapter) listView.getAdapter(); listAdapter.remove(listAdapter.getItem(position)); } }); return true; } }); } }); alert.show(); } else { AlertUtils.showMessage(context, R.string.notFound, R.string.noSavedCalibrations); } } catch (ActivityNotFoundException e) { AlertUtils.showMessage(context, R.string.error, R.string.updateRequired); } callback.handleMessage(null); }
From source file:com.nextgis.maplibui.formcontrol.Combobox.java
@Override public void init(JSONObject element, List<Field> fields, Bundle savedState, Cursor featureCursor, SharedPreferences preferences) throws JSONException { JSONObject attributes = element.getJSONObject(JSON_ATTRIBUTES_KEY); mFieldName = attributes.getString(JSON_FIELD_NAME_KEY); mIsShowLast = ControlHelper.isSaveLastValue(attributes); setEnabled(ControlHelper.isEnabled(fields, mFieldName)); String lastValue = null;//from w w w.j av a 2s . com if (ControlHelper.hasKey(savedState, mFieldName)) lastValue = savedState.getString(ControlHelper.getSavedStateKey(mFieldName)); else if (null != featureCursor) { int column = featureCursor.getColumnIndex(mFieldName); if (column >= 0) lastValue = featureCursor.getString(column); } else if (mIsShowLast) lastValue = preferences.getString(mFieldName, null); int defaultPosition = 0; int lastValuePosition = -1; mAliasValueMap = new HashMap<>(); ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<>(getContext(), R.layout.formtemplate_spinner); setAdapter(spinnerArrayAdapter); if (attributes.has(ConstantsUI.JSON_NGW_ID_KEY) && attributes.getLong(ConstantsUI.JSON_NGW_ID_KEY) != -1) { MapContentProviderHelper map = (MapContentProviderHelper) MapBase.getInstance(); if (null == map) throw new IllegalArgumentException("The map should extends MapContentProviderHelper or inherited"); String account = element.optString(SyncStateContract.Columns.ACCOUNT_NAME); long id = attributes.getLong(JSON_NGW_ID_KEY); for (int i = 0; i < map.getLayerCount(); i++) { if (map.getLayer(i) instanceof NGWLookupTable) { NGWLookupTable table = (NGWLookupTable) map.getLayer(i); if (table.getRemoteId() != id || !table.getAccountName().equals(account)) continue; int j = 0; for (Map.Entry<String, String> entry : table.getData().entrySet()) { mAliasValueMap.put(entry.getValue(), entry.getKey()); if (null != lastValue && lastValue.equals(entry.getKey())) lastValuePosition = j; spinnerArrayAdapter.add(entry.getValue()); j++; } break; } } } else { JSONArray values = attributes.optJSONArray(JSON_VALUES_KEY); if (values != null) { for (int j = 0; j < values.length(); j++) { JSONObject keyValue = values.getJSONObject(j); String value = keyValue.getString(JSON_VALUE_NAME_KEY); String value_alias = keyValue.getString(JSON_VALUE_ALIAS_KEY); if (keyValue.has(JSON_DEFAULT_KEY) && keyValue.getBoolean(JSON_DEFAULT_KEY)) defaultPosition = j; if (null != lastValue && lastValue.equals(value)) lastValuePosition = j; mAliasValueMap.put(value_alias, value); spinnerArrayAdapter.add(value_alias); } } } setSelection(lastValuePosition >= 0 ? lastValuePosition : defaultPosition); // The drop down view spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); float minHeight = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 14, getResources().getDisplayMetrics()); setPadding(0, (int) minHeight, 0, (int) minHeight); }
From source file:tw.com.geminihsu.app01.fragment.Fragment_PickUpTrain.java
private void setLister() { calendar = Calendar.getInstance(); timePicker = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { }/*from www . ja va 2 s .c o m*/ }; timerPicker.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new TimePickerDialog(getActivity(), timePicker, 24, 59, true).show(); } }); datePicker = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) { date.setText(dayOfMonth + "/" + (month + 1) + "/" + year); } }; btn_datePicker.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new DatePickerDialog(getActivity(), datePicker, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)).show(); } }); radioGroup_orderTimetype.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == reservation.getId()) { linearLayout_date_picker.setVisibility(View.VISIBLE); linearLayout_time_picker.setVisibility(View.GONE); } else { linearLayout_date_picker.setVisibility(View.GONE); linearLayout_time_picker.setVisibility(View.VISIBLE); } } }); radiogroup_destination_station.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == thsrStation.getId()) { getLocationFromDB("?"); } else { getLocationFromDB("?"); } } }); radiogroup_leave_location.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == departure_thsr_train.getId()) { getLocationFromDB("?"); } else { getLocationFromDB("?"); } } }); departure.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.DEPARTURE_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.DEPARTURE_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.DEPARTURE_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.STOP_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.STOP_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.STOP_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); destination.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder builderSingle = new AlertDialog.Builder(getActivity()); final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.select_dialog_item); arrayAdapter.add(getString(R.string.pop_map_option1)); arrayAdapter.add(getString(R.string.pop_map_option2)); builderSingle.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String strName = arrayAdapter.getItem(which); switch (which) { case 0: Intent map = new Intent(getActivity(), OrderMapActivity.class); Bundle b = new Bundle(); b.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_GPS); map.putExtras(b); startActivityForResult(map, Constants.DESTINATION_QUERY_GPS); break; case 1: Intent page = new Intent(getActivity(), BookmarksMapListActivity.class); Bundle flag = new Bundle(); flag.putInt(Constants.ARG_POSITION, Constants.DESTINATION_QUERY_BOOKMARK); page.putExtras(flag); startActivityForResult(page, Constants.DESTINATION_QUERY_BOOKMARK); break; } } }); builderSingle.show(); } }); getDataFromDB(); linearLayout_spec.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // custom dialog final Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.client_take_ride_selectspec_requirement); dialog.setTitle(getString(R.string.txt_take_spec)); Button cancel = (Button) dialog.findViewById(R.id.button_category_cancel); Button ok = (Button) dialog.findViewById(R.id.button_category_ok); //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // set the custom dialog components - text, image and button ListView requirement = (ListView) dialog.findViewById(R.id.listViewDialog); requirement.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View v, int position, long id) { ClientTakeRideSelectSpecListItem item = mCommentListData.get(position); item.check = !item.check; mCommentListData.set(position, item); listViewAdapter.notifyDataSetChanged(); } }); if (listViewAdapter == null) { listViewAdapter = new ClientTakeRideSelectSpecListItemAdapter(getActivity(), 0, mCommentListData); } requirement.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); dialog.show(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); String require; ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String require = ""; for (ClientTakeRideSelectSpecListItem item : mCommentListData) { if (item.check) { spec_list.add(item); require += item.book_title + ","; } } if (!require.isEmpty()) require = require.substring(0, require.length() - 1); spec_value.setText(require); dialog.cancel(); } }); } }); spec.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // custom dialog final Dialog dialog = new Dialog(getActivity()); dialog.setContentView(R.layout.client_take_ride_selectspec_requirement); dialog.setTitle(getString(R.string.txt_take_spec)); Button cancel = (Button) dialog.findViewById(R.id.button_category_ok); //dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // set the custom dialog components - text, image and button ListView requirement = (ListView) dialog.findViewById(R.id.listViewDialog); getDataFromDB(); listViewAdapter = new ClientTakeRideSelectSpecListItemAdapter(getActivity(), 0, mCommentListData); requirement.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); dialog.show(); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); } }); } }); spinner_go_location.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { currentLocation = tainStationList.get(position); destination_detail = new LocationAddress(); destination_detail.setLongitude(Double.parseDouble(currentLocation.getLng())); destination_detail.setLatitude(Double.parseDouble(currentLocation.getLat())); destination_detail.setAddress(currentLocation.getStreetAddress().substring(3, currentLocation.getStreetAddress().length())); destination_detail.setLocation(currentLocation.getLocation()); String zipCpde = (getTrainStationZip(currentLocation.getLocation())); destination_detail.setZipCode(zipCpde); destination_detail.setCountryName("Taiwan"); destination_detail.setLocality(currentLocation.getStreetAddress()); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); spinner_departure.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) { currentLocation = tainStationList.get(position); departure_detail = new LocationAddress(); departure_detail.setLongitude(Double.parseDouble(currentLocation.getLng())); departure_detail.setLatitude(Double.parseDouble(currentLocation.getLat())); departure_detail.setAddress(currentLocation.getStreetAddress().substring(3, currentLocation.getStreetAddress().length())); departure_detail.setLocation(currentLocation.getLocation()); //departure_detail.setZipCode(currentLocation.getStreetAddress().substring(0,3)); String zipCode = (getTrainStationZip(currentLocation.getLocation())); departure_detail.setZipCode(zipCode); departure_detail.setCountryName("Taiwan"); departure_detail.setLocality(currentLocation.getStreetAddress()); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); }
From source file:de.mkrtchyan.recoverytools.FlashFragment.java
/** * Cards on FlashRecovery and FlashKernel Dialog */// w ww .java2s .c o m public void FlashSupportedRecovery(Card card) { final File path; final ArrayList<String> Versions; if (!mDevice.downloadUtils(mContext)) { /** * If there files be needed to flash download it and listing device specified * recovery file for example recovery-clockwork-touch-6.0.3.1-grouper.img * (read out from RECOVERY_SUMS) */ String SYSTEM = card.getData().toString(); ArrayAdapter<String> VersionsAdapter = new ArrayAdapter<>(mContext, R.layout.custom_list_item); switch (SYSTEM) { case "stock": Versions = mDevice.getStockRecoveryVersions(); path = Constants.PathToStockRecovery; for (String i : Versions) { try { String version = i.split("-")[3].replace(mDevice.getRecoveryExt(), ""); String deviceName = i.split("-")[2]; VersionsAdapter.add("Stock Recovery " + version + " (" + deviceName + ")"); } catch (ArrayIndexOutOfBoundsException e) { VersionsAdapter.add(i); } } break; case "clockwork": Versions = mDevice.getCwmRecoveryVersions(); path = Constants.PathToCWM; for (String i : Versions) { try { int startIndex; String version = ""; if (i.contains("-touch-")) { startIndex = 4; version = "Touch "; } else { startIndex = 3; } version += i.split("-")[startIndex - 1]; String device = "("; for (int splitNr = startIndex; splitNr < i.split("-").length; splitNr++) { if (!device.equals("(")) device += "-"; device += i.split("-")[splitNr].replace(mDevice.getRecoveryExt(), ""); } device += ")"; VersionsAdapter.add("ClockworkMod " + version + " " + device); } catch (ArrayIndexOutOfBoundsException e) { VersionsAdapter.add(i); } } break; case "twrp": Versions = mDevice.getTwrpRecoveryVersions(); path = Constants.PathToTWRP; for (String i : Versions) { try { if (i.contains("openrecovery")) { String device = "("; for (int splitNr = 3; splitNr < i.split("-").length; splitNr++) { if (!device.equals("(")) device += "-"; device += i.split("-")[splitNr].replace(mDevice.getRecoveryExt(), ""); } device += ")"; VersionsAdapter.add("TWRP " + i.split("-")[2] + " " + device); } else { VersionsAdapter .add("TWRP " + i.split("-")[1].replace(mDevice.getRecoveryExt(), "") + ")"); } } catch (ArrayIndexOutOfBoundsException e) { VersionsAdapter.add(i); } } break; case "philz": Versions = mDevice.getPhilzRecoveryVersions(); path = Constants.PathToPhilz; for (String i : Versions) { try { String device = "("; for (int splitNr = 1; splitNr < i.split("-").length; splitNr++) { if (!device.equals("(")) device += "-"; device += i.split("-")[splitNr].replace(mDevice.getRecoveryExt(), ""); } device += ")"; VersionsAdapter.add("PhilZ Touch " + i.split("_")[2].split("-")[0] + " " + device); } catch (ArrayIndexOutOfBoundsException e) { VersionsAdapter.add(i); } } break; default: return; } final AppCompatDialog RecoveriesDialog = new AppCompatDialog(mContext); RecoveriesDialog.setTitle(SYSTEM.toUpperCase()); ListView VersionList = new ListView(mContext); RecoveriesDialog.setContentView(VersionList); VersionList.setAdapter(VersionsAdapter); RecoveriesDialog.show(); VersionList.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { RecoveriesDialog.dismiss(); final String fileName = Versions.get(i); final File recovery = new File(path, fileName); if (!recovery.exists()) { try { URL url = new URL(Constants.RECOVERY_URL + "/" + fileName); Downloader RecoveryDownloader = new Downloader(mContext, url, recovery); RecoveryDownloader.setOnDownloadListener(new Downloader.OnDownloadListener() { @Override public void success(File file) { flashRecovery(file); } @Override public void failed(Exception e) { } }); RecoveryDownloader.setRetry(true); RecoveryDownloader.setAskBeforeDownload(true); RecoveryDownloader.setChecksumFile(RecoveryCollectionFile); RecoveryDownloader.ask(); } catch (MalformedURLException ignored) { } } else { flashRecovery(recovery); } } }); } }
From source file:org.openremote.android.console.AppSettingsActivity.java
/** * Auto discovery servers and add them in a list view. * Click a list item and make it as current server. * //from ww w. j a va2 s . com * @return the list view */ private ListView constructAutoServersView() { final ListView lv = new ListView(this); lv.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, 200)); lv.setPadding(20, 5, 5, 10); lv.setBackgroundColor(0); lv.setCacheColorHint(0); lv.setItemsCanFocus(true); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); final ArrayAdapter<String> serverListAdapter = new ArrayAdapter<String>(appSettingsView.getContext(), R.layout.server_list_item, new ArrayList<String>()); lv.setAdapter(serverListAdapter); new IPAutoDiscoveryServer() { @Override protected void onProgressUpdate(Void... values) { if (progressLayout != null) { progressLayout.setVisibility(View.VISIBLE); } } @Override protected void onPostExecute(List<String> result) { int length = result.size(); for (int i = 0; i < length; i++) { serverListAdapter.add(result.get(i)); } if (length > 0) { lv.setItemChecked(0, true); currentServer = serverListAdapter.getItem(0); AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer); } if (progressLayout != null) { progressLayout.setVisibility(View.INVISIBLE); } requestPanelList(); checkAuthentication(); requestAccess(); } }.execute((Void) null); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { currentServer = (String) parent.getItemAtPosition(position); AppSettingsModel.setCurrentServer(AppSettingsActivity.this, currentServer); requestPanelList(); checkAuthentication(); requestAccess(); } }); return lv; }