List of usage examples for android.widget ArrayAdapter ArrayAdapter
public ArrayAdapter(@NonNull Context context, @LayoutRes int resource, @NonNull List<T> objects)
From source file:org.deviceconnect.android.manager.setting.ReqResDebugActivity.java
/** * Network Service Discovery???.//ww w . j av a 2 s.c o m * @param res ?JSON */ private void parseNetworkServieDiscovery(final String res) { try { JSONObject root = new JSONObject(res); JSONArray services = root.getJSONArray(NetworkServiceDiscoveryProfile.PARAM_SERVICES); if (services == null) { return; } String[] data = new String[services.length() + 1]; data[0] = " "; // ????????? for (int i = 1; i < services.length() + 1; i++) { data[i] = services.getJSONObject(i - 1).getString(NetworkServiceDiscoveryProfile.PARAM_ID); } ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, data); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mDI.setAdapter(adapter); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.todoroo.astrid.taskrabbit.TaskRabbitActivity.java
private void setupListView() { String[] keys = getResources().getStringArray(R.array.tr_preset_types); if (adapter == null) { adapter = new ArrayAdapter<String>(this, R.layout.task_rabbit_menu_row, keys); menuList = new ListView(this); menuList.setAdapter(adapter);// w ww .ja va 2 s . c o m menuList.setCacheColorHint(Color.TRANSPARENT); menuList.setSelection(0); menuList.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { currentSelectedItem = position; displayViewsForMode(position); menuPopover.dismiss(); } }); } else { adapter = new ArrayAdapter<String>(this, R.layout.task_rabbit_menu_row, keys); menuList.setAdapter(adapter); } }
From source file:gr.scify.newsum.ui.ViewActivity.java
@Override public void run() { // take the String from the TopicActivity Bundle extras = getIntent().getExtras(); Category = extras.getString(CATEGORY_INTENT_VAR); // Make sure we have updated the data source NewSumUiActivity.setDataSource(this); // Get user sources String sUserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this); // get Topics from TopicActivity (avoid multiple server calls) TopicInfo[] tiTopics = TopicActivity.getTopics(sUserSources, Category, this); // Also get Topic Titles, to display to adapter final String[] saTopicTitles = new String[tiTopics.length]; // Also get Topic IDs final String[] saTopicIDs = new String[tiTopics.length]; // Also get Dates, in order to show in summary title final String[] saTopicDates = new String[tiTopics.length]; // DeHTML titles for (int iCnt = 0; iCnt < tiTopics.length; iCnt++) { // update Titles Array saTopicTitles[iCnt] = Html.fromHtml(tiTopics[iCnt].getTitle()).toString(); // update IDs Array saTopicIDs[iCnt] = tiTopics[iCnt].getID(); // update Date Array saTopicDates[iCnt] = tiTopics[iCnt].getPrintableDate(NewSumUiActivity.getDefaultLocale()); }// ww w .j a v a2s .c om // get the value of the TopicIDs list size (to use in swipe) saTopicIDsLength = saTopicIDs.length; final TextView title = (TextView) findViewById(R.id.title); // Fill topic spinner final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this, android.R.layout.simple_spinner_item, saTopicTitles); final TextView tx = (TextView) findViewById(R.id.textView1); // final float minm = tx.getTextSize(); // final float maxm = (minm + 24); // Get active topic int iTopicNum; // If we have returned from a pause if (iPrvSelectedItem >= 0) // use previous selection before pause iTopicNum = iPrvSelectedItem; // else else // use selection from topic page iTopicNum = extras.getInt(TOPIC_ID_INTENT_VAR); final int num = iTopicNum; // create an invisible spinner just to control the summaries of the // category (i will use it later on Swipe) final Spinner spinner = (Spinner) findViewById(R.id.spinner1); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); runOnUiThread(new Runnable() { @Override public void run() { spinner.setAdapter(adapter); // Scroll view init final ScrollView scroll = (ScrollView) findViewById(R.id.scrollView1); final String[] saTopicTitlesArg = saTopicTitles; final String[] saTopicIDsArg = saTopicIDs; final String[] SaTopicDatesArg = saTopicDates; // Add selection event spinner.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) { // Changing summary loading = true; showWaitingDialog(); // Update visibility of rating bar final RatingBar rb = (RatingBar) findViewById(R.id.ratingBar); rb.setRating(0.0f); rb.setVisibility(View.VISIBLE); final TextView rateLbl = (TextView) findViewById(R.id.rateLbl); rateLbl.setVisibility(View.VISIBLE); scroll.scrollTo(0, 0); String UserSources = Urls.getUserVisibleURLsAsString(ViewActivity.this); String[] saTopicIDs = saTopicIDsArg; // track summary views per category and topic title if (getAnalyticsPref()) { EasyTracker.getTracker().sendEvent(VIEW_SUMMARY_ACTION, Category, saTopicTitlesArg[arg2], 0l); } if (sCustomCategory.trim().length() > 0) { if (Category.equals(sCustomCategory)) { Context ctxCur = NewSumUiActivity.getAppContext(ViewActivity.this); String sCustomCategoryURL = ctxCur.getResources() .getString(R.string.custom_category_url); // Check if specific element needs to be read String sElementID = ctxCur.getResources() .getString(R.string.custom_category_elementId); // If an element needs to be selected if (sElementID.trim().length() > 0) { try { // Check if specific element needs to be read String sViewOriginalPage = ctxCur.getResources() .getString(R.string.custom_category_visit_source); // Init text by a link to the original page sText = "<p><a href='" + sCustomCategoryURL + "'>" + sViewOriginalPage + "</a></p>"; // Get document Document doc = Jsoup.connect(sCustomCategoryURL).get(); // If a table Element eCur = doc.getElementById(sElementID); if (eCur.tagName().equalsIgnoreCase("table")) { // Get table rows Elements eRows = eCur.select("tr"); // For each row StringBuffer sTextBuf = new StringBuffer(); for (Element eCurRow : eRows) { // Append content // TODO: Use HTML if possible. Now problematic (crashes when we click on link) sTextBuf.append("<p>" + eCurRow.text() + "</p>"); } // Return as string sText = sText + sTextBuf.toString(); } else // else get text sText = eCur.text(); } catch (IOException e) { // Show unavailable text sText = ctxCur.getResources() .getString(R.string.custom_category_unavailable); e.printStackTrace(); } } else sText = Utils.getFromHttp(sCustomCategoryURL, false); } } else { // call getSummary with (sTopicID, sUserSources). Use "All" for // all Sources String[] Summary = NewSumServiceClient.getSummary(saTopicIDs[arg2], UserSources); // check if Summary exists, otherwise display message if (Summary.length == 0) { // DONE APPLICATION HANGS, DOES NOT // WORK. Updated: Probably OK nothingFound = true; AlertDialog.Builder al = new AlertDialog.Builder(ViewActivity.this); al.setMessage(R.string.shouldReloadSummaries); al.setNeutralButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { // Reset cache CacheController.clearCache(); // Restart main activity startActivity(new Intent(getApplicationContext(), NewSumUiActivity.class) .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)); } }); al.setCancelable(false); al.show(); // Return to home activity loading = false; return; } // Generate Summary text for normal categories sText = generateSummaryText(Summary, ViewActivity.this); pText = generatesummarypost(Summary, ViewActivity.this); } // Update HTML tx.setText(Html.fromHtml(sText)); // Allow links to be followed into browser tx.setMovementMethod(LinkMovementMethod.getInstance()); // Also Add Date to Topic Title inside Summary title.setText(saTopicTitlesArg[arg2] + " : " + SaTopicDatesArg[arg2]); // Update size updateTextSize(); // Update visited topics TopicActivity.addVisitedTopicID(saTopicIDs[arg2]); // Done loading = false; closeWaitingDialog(); } @Override public void onNothingSelected(AdapterView<?> arg0) { } }); runOnUiThread(new Runnable() { @Override public void run() { // Get active topic spinner.setSelection(num); } }); } }); runOnUiThread(new Runnable() { @Override public void run() { showHelpDialog(); } }); closeWaitingDialog(); }
From source file:com.housekeeper.ar.healthhousekeeper.RegisterActivity.java
private void setSpinner() { Log.i(TAG, "namePros:" + namePros); // ArrayAdapter<String> proAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,namePros){ // @Override // public View getDropDownView(int position, View convertView, ViewGroup parent) { // LayoutInflater inflater=(LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); // View view = inflater.inflate(R.layout.spinner_item_layout, // null); // TextView label = (TextView) view // .findViewById(R.id.spinner_item_label); //// w ww . j av a 2 s .c o m // label.setText(namePros[position]); // // // return view; // //return super.getDropDownView(position, convertView, parent); // } // }; // // //? // proAdapter.setDropDownViewResource(R.layout.spinner_item_layout); //// proAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // pro.setAdapter(proAdapter); // pro.setOnItemSelectedListener(new OnItemSelectedListener() { // // @Override // public void onItemSelected(AdapterView<?> parent, View view, // int position, long id) { // // TODO Auto-generated method stub // proStr = parent.getItemAtPosition(position).toString(); // Log.v(TAG, "selcet proStr:" + proStr); // if (proStr.equals(namePros[position])) { // idJobTitlesInt = idJobTitles[position]; // } // } // // @Override // public void onNothingSelected(AdapterView<?> arg0) { // // TODO Auto-generated method stub // // } // // }); // // pro.setOnTouchListener(new View.OnTouchListener() { // @Override // public boolean onTouch(View view, MotionEvent motionEvent) { // // Log.i(TAG, "year touch "); // closeSoftKeyboard(); // return false; // } // }); ArrayAdapter<String> shengAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item, nameProvinces) { @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.spinner_item_layout, null); TextView label = (TextView) view.findViewById(R.id.spinner_item_label); label.setText(nameProvinces[position]); return view; //return super.getDropDownView(position, convertView, parent); } }; //? shengAdapter.setDropDownViewResource(R.layout.spinner_item_layout); sheng.setAdapter(shengAdapter); sheng.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> shengparent, View shengview, int shengposition, long shengid) { // TODO Auto-generated method stub myApp.setShengposition(shengposition); shengStr = shengparent.getItemAtPosition(shengposition).toString(); Log.v(TAG, "shengStr:" + shengStr); if (!shengStr.equals("") && shengStr.equals(nameProvinces[shengposition])) { Log.v(TAG, "position:" + shengposition); for (int i = 0; i < joProvinces.length; i++) { try { if (shengStr.equals(joProvinces[i].getString("name"))) { jaCities = joProvinces[i].getJSONArray("cities"); joCities = new JSONObject[jaCities.length()]; nameCities = new String[joCities.length]; for (int j = 0; j < jaCities.length(); j++) { joCities[j] = jaCities.getJSONObject(j); nameCities[j] = joCities[j].getString("name"); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } sheng.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { Log.i(TAG, "year touch "); closeSoftKeyboard(); return false; } }); shiAdapter = new ArrayAdapter<String>(RegisterActivity.this, R.layout.spinner_item, nameCities) { @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.spinner_item_layout, null); TextView label = (TextView) view.findViewById(R.id.spinner_item_label); label.setText(nameCities[position]); return view; //return super.getDropDownView(position, convertView, parent); } }; //? shiAdapter.setDropDownViewResource(R.layout.spinner_item_layout); // shiAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); shi.setAdapter(shiAdapter); shi.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> shiparent, View shiview, int shiposition, long shiid) { // TODO Auto-generated method stub shiStr = shiparent.getItemAtPosition(shiposition).toString(); Log.v(TAG, "shiStr:" + shiStr); if (!shiStr.equals("") && shiStr.equals(nameCities[shiposition])) { for (int i = 0; i < joCities.length; i++) { try { if (shiStr.equals(joCities[i].getString("name"))) { jaHospitals = joCities[i].getJSONArray("hospitals"); joHospitals = new JSONObject[jaHospitals.length()]; nameHospitals = new String[joHospitals.length]; for (int j = 0; j < jaHospitals.length(); j++) { joHospitals[j] = jaHospitals.getJSONObject(j); nameHospitals[j] = joHospitals[j].getString("name"); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } shi.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { Log.i(TAG, "year touch "); closeSoftKeyboard(); return false; } }); hospitalAdapter = new ArrayAdapter<String>(RegisterActivity.this, R.layout.spinner_item, nameHospitals) { @Override public View getDropDownView(int position, View convertView, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.spinner_item_layout, null); TextView label = (TextView) view.findViewById(R.id.spinner_item_label); label.setText(nameHospitals[position]); return view; //return super.getDropDownView(position, convertView, parent); } }; //? hospitalAdapter.setDropDownViewResource(R.layout.spinner_item_layout); yy.setAdapter(hospitalAdapter); yy.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> yyparent, View yyview, int yyposition, long yyid) { // TODO Auto-generated method stub yyStr = yyparent.getItemAtPosition(yyposition).toString(); if (!yyStr.equals("") && yyStr.equals(nameHospitals[yyposition])) { for (int i = 0; i < joHospitals.length; i++) { try { if (yyStr.equals(joHospitals[i].getString("name"))) { jaDepartments = joHospitals[i].getJSONArray("departments"); joDepartments = new JSONObject[jaDepartments.length()]; nameDepartments = new String[joDepartments.length]; idDepartments = new int[joDepartments.length]; for (int j = 0; j < jaDepartments.length(); j++) { joDepartments[j] = jaDepartments.getJSONObject(j); nameDepartments[j] = joDepartments[j].getString("name"); idDepartments[j] = joDepartments[j].getInt("id"); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } yy.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent motionEvent) { Log.i(TAG, "year touch "); closeSoftKeyboard(); return false; } }); // departmentAdapter = new ArrayAdapter<String>(RegisterActivity.this, android.R.layout.simple_spinner_item, nameDepartments) { // @Override // public View getDropDownView(int position, View convertView, ViewGroup parent) { // LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); // View view = inflater.inflate(R.layout.spinner_item_layout, // null); // TextView label = (TextView) view // .findViewById(R.id.spinner_item_label); // // label.setText(nameDepartments[position]); // // // return view; // //return super.getDropDownView(position, convertView, parent); // } // }; //? // departmentAdapter.setDropDownViewResource(R.layout.spinner_item_layout); // ks.setAdapter(departmentAdapter); // ks.setOnItemSelectedListener(new OnItemSelectedListener() { // // @Override // public void onItemSelected( // AdapterView<?> ksparent, View ksview, // int ksposition, long ksid) { // // TODO Auto-generated method stub // ksStr = ksparent.getItemAtPosition(ksposition).toString(); // if (ksStr.equals(nameDepartments[ksposition])) { // try { // idDepartmentInt = idDepartments[ksposition]; // joDepartmentType = joDepartments[ksposition].getJSONObject("departmentType"); // departmentTypeTv.setText(joDepartmentType.getString("name")); // } catch (JSONException e) { // // TODO Auto-generated catch block // // e.printStackTrace(); // } // } // } // // @Override // public void onNothingSelected( // AdapterView<?> arg0) { // // TODO Auto-generated method stub // // } // }); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); // ks.setOnTouchListener(new View.OnTouchListener() { // @Override // public boolean onTouch(View view, MotionEvent motionEvent) { // // Log.i(TAG, "year touch "); // closeSoftKeyboard(); // return false; // } // }); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); year.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub yearStr = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); month.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub monthStr = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); day.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub dayStr = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); sex.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub sexStr = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> arg0) { // TODO Auto-generated method stub } }); }
From source file:com.ts.mobilelab.goggles4u.PrescriptionAddActivity.java
private ArrayAdapter<String> getData(String[] array) { //ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_row, array); // array.ad/*from w ww . j a v a 2 s . c o m*/ ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_row, array); return adapter; }
From source file:com.mifos.mifosxdroid.online.LoanAccountFragment.java
private void inflateLoanOfficerSpinner() { showProgress(true);/*w w w .j av a 2 s . c o m*/ App.apiManager.getLoansAccountTemplate(clientId, productId, new Callback<Response>() { @Override public void success(final Response result, Response response) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (getActivity() == null) return; Log.d(LOG_TAG, ""); final List<FieldOfficerOptions> loanOfficer = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> loanOfficerNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try { reader = new BufferedReader(new InputStreamReader(result.getBody().in())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("loanOfficerOptions")) { JSONArray loanOfficers = obj.getJSONArray("loanOfficerOptions"); for (int i = 0; i < loanOfficers.length(); i++) { JSONObject fieldOfficerObject = loanOfficers.getJSONObject(i); FieldOfficerOptions officer = new FieldOfficerOptions(); officer.setId(fieldOfficerObject.optInt("id")); officer.setDisplayName(fieldOfficerObject.optString("displayName")); loanOfficer.add(officer); loanOfficerNames.add(fieldOfficerObject.optString("displayName")); loanOfficerNameIdHashMap.put(officer.getDisplayName(), officer.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> loanOfficerNameAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, loanOfficerNames); loanOfficerNameAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_loan_officer.setAdapter(loanOfficerNameAdapter); sp_loan_officer.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { loanOfficerId = loanOfficerNameIdHashMap.get(loanOfficerNames.get(i)); Log.d("loanOfficer " + loanOfficerNames.get(i), String.valueOf(loanOfficerId)); if (loanOfficerId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_loan_officer), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); showProgress(false); } @Override public void failure(RetrofitError retrofitError) { Log.d(LOG_TAG, retrofitError.getLocalizedMessage()); showProgress(false); } }); }
From source file:androidVNC.VncCanvasActivity.java
private void selectColorModel() { // Stop repainting the desktop // because the display is composited! vncCanvas.disableRepaints();/*from w ww. j a va 2 s . c o m*/ String[] choices = new String[COLORMODEL.values().length]; int currentSelection = -1; for (int i = 0; i < choices.length; i++) { COLORMODEL cm = COLORMODEL.values()[i]; choices[i] = cm.toString(); if (vncCanvas.isColorModel(cm)) currentSelection = i; } final Dialog dialog = new Dialog(this); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); ListView list = new ListView(this); list.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_checked, choices)); list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); list.setItemChecked(currentSelection, true); list.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { dialog.dismiss(); COLORMODEL cm = COLORMODEL.values()[arg2]; vncCanvas.setColorModel(cm); connection.setColorModel(cm.nameString()); connection.save(database.getWritableDatabase()); //Toast.makeText(VncCanvasActivity.this,"Updating Color Model to " + cm.toString(), Toast.LENGTH_SHORT).show(); } }); dialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface arg0) { Log.i(TAG, "Color Model Selector dismissed"); // Restore desktop repaints vncCanvas.enableRepaints(); } }); dialog.setContentView(list); dialog.show(); }
From source file:com.mdlive.sav.MDLiveSearchProvider.java
/** * Instantiating array adapter to populate the listView * The layout android.R.layout.simple_list_item_single_choice creates radio button for each listview item * * @param list : Dependent users array list *///from w w w . ja v a 2s . c om private void showListViewDialog(final ArrayList<String> list, final TextView selectedText, final String key, final ArrayList<HashMap<String, String>> typeList) { /*We need to get the instance of the LayoutInflater*/ final AlertDialog.Builder alertDialog = new AlertDialog.Builder(MDLiveSearchProvider.this); LayoutInflater inflater = getLayoutInflater(); View convertView = inflater.inflate(R.layout.mdlive_screen_popup, null); alertDialog.setView(convertView); ListView lv = (ListView) convertView.findViewById(R.id.popupListview); ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list); lv.setAdapter(adapter); lv.setChoiceMode(ListView.CHOICE_MODE_SINGLE); final AlertDialog dialog = alertDialog.create(); dialog.show(); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String SelectedText = list.get(position); HashMap<String, String> localMap = typeList.get(position); for (Map.Entry entry : localMap.entrySet()) { if (SelectedText.equals(entry.getValue().toString())) { postParams.put(key, entry.getKey().toString()); break; //breaking because its one to one map } } specialityBasedOnProvider(SelectedText, key); String oldChoice = selectedText.getText().toString(); selectedText.setText(SelectedText); dialog.dismiss(); // if user selects a different Provider type, then reload this screen if (!oldChoice.equals(SelectedText)) { SharedPreferences sharedpreferences = getSharedPreferences( PreferenceConstants.MDLIVE_USER_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sharedpreferences.edit(); editor.putString(PreferenceConstants.PROVIDER_MODE, SelectedText); int providerType = MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText) == null ? MDLiveConfig.UNMAPPED : MDLiveConfig.PROVIDERTYPE_MAP.get(SelectedText); if (providerType == MDLiveConfig.UNMAPPED) editor.putString(PreferenceConstants.PROVIDERTYPE_ID, ""); else editor.putString(PreferenceConstants.PROVIDERTYPE_ID, String.valueOf(providerType)); editor.commit(); // now reload the screen //recreate(); } } }); }
From source file:com.ezac.gliderlogs.FlightOverviewActivity.java
public void DoFlightMember() { // get member_list.xml view LayoutInflater li = LayoutInflater.from(context); membersView = li.inflate(R.layout.member_list, null); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); // set member_list.xml to alertdialog builder alertDialogBuilder.setView(membersView); ///* w w w . jav a2 s .co m*/ Button mMember_Btn; final EditText mDetailInfo; Button mGlider_Btn; // set dialog message alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { String fRegi = (String) mGliderSpin.getSelectedItem(); String fPilo = (String) mMemberSpin.getSelectedItem(); if (!fPilo.equals("") && !fRegi.equals("")) { String fRegiPilo = ""; for (int i = 0; i < mGliderSpin.getCount(); i++) { String s = (String) mGliderSpin.getItemAtPosition(i); if (s.equalsIgnoreCase(fRegi)) { fRegiPilo = GliderList.get(i); } } for (int i = 0; i < mMemberSpin.getCount(); i++) { String s = (String) mMemberSpin.getItemAtPosition(i); if (s.equalsIgnoreCase(fPilo)) { fRegiPilo = fRegiPilo + ":" + MemberIndexList.get(i); } } DoFlightFilter(7, fRegiPilo); OptionSelect(R.id.action_my, R.id.action_all, R.id.action_open, R.id.action_ready, R.id.action_45min); } else if (!fRegi.equals("")) { for (int i = 0; i < mGliderSpin.getCount(); i++) { String s = (String) mGliderSpin.getItemAtPosition(i); if (s.equalsIgnoreCase(fRegi)) { // set filter criteria for selected member DoFlightFilter(6, GliderList.get(i)); OptionSelect(R.id.action_my, R.id.action_all, R.id.action_open, R.id.action_ready, R.id.action_45min); } } } else if (!fPilo.equals("")) { for (int i = 0; i < mMemberSpin.getCount(); i++) { String s = (String) mMemberSpin.getItemAtPosition(i); if (s.equalsIgnoreCase(fPilo)) { // set filter criteria for selected member DoFlightFilter(5, MemberIndexList.get(i)); OptionSelect(R.id.action_my, R.id.action_all, R.id.action_open, R.id.action_ready, R.id.action_45min); } } } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { DoFlightFilter(4, ""); OptionSelect(R.id.action_all, R.id.action_my, R.id.action_open, R.id.action_ready, R.id.action_45min); dialog.cancel(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); // get reference to and fill spinner with members mMemberSpin = (Spinner) membersView.findViewById(R.id.flight_member); ArrayAdapter<String> dataAdapter_1 = new ArrayAdapter<String>(FlightOverviewActivity.this, android.R.layout.simple_spinner_item, MemberList); dataAdapter_1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mMemberSpin.setAdapter(dataAdapter_1); // get reference to and fill spinner with gliders mGliderSpin = (Spinner) membersView.findViewById(R.id.flight_glider); ArrayAdapter<String> dataAdapter_2 = new ArrayAdapter<String>(FlightOverviewActivity.this, android.R.layout.simple_spinner_item, GliderList); dataAdapter_2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); mGliderSpin.setAdapter(dataAdapter_2); mDetailInfo = (EditText) membersView.findViewById(R.id.editText1); // make field read only mDetailInfo.setClickable(false); mDetailInfo.setFocusable(false); mGlider_Btn = (Button) membersView.findViewById(R.id.flight_glider_detail); mGlider_Btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String fRegi = (String) mGliderSpin.getSelectedItem(); if (fRegi.equals(null) || fRegi.equals("")) { mDetailInfo.setText("Geen Registratie selectie gevonden,\nmaak een keuze !"); } else { String fRegiPilo = ""; for (int i = 0; i < mGliderSpin.getCount(); i++) { String s = (String) mGliderSpin.getItemAtPosition(i); if (s.equalsIgnoreCase(fRegi)) { fRegiPilo = GliderList.get(i); } } mDetailInfo.setText(getDetailInfo(FlightsContentProvider.CONTENT_URI_GLIDER, fRegiPilo, 0)); } } }); mMember_Btn = (Button) membersView.findViewById(R.id.flight_member_detail); mMember_Btn.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { String fPilo = (String) mMemberSpin.getSelectedItem(); if (fPilo.equals(null) || fPilo.equals("")) { mDetailInfo.setText("Geen Naam selectie gevonden,\nmaak een keuze !"); } else { String fRegiPilo = ""; for (int i = 0; i < mMemberSpin.getCount(); i++) { String s = (String) mMemberSpin.getItemAtPosition(i); if (s.equalsIgnoreCase(fPilo)) { fRegiPilo = MemberIndexList.get(i); } } mDetailInfo.setText(getDetailInfo(FlightsContentProvider.CONTENT_URI_MEMBER, fRegiPilo, 1)); } } }); alertDialog.show(); }
From source file:com.mifos.mifosxdroid.online.LoanAccountFragment.java
private void inflateInterestTypeMethodSpinner() { showProgress(true);//from ww w . j a va 2s . c o m App.apiManager.getLoansAccountTemplate(clientId, productId, new Callback<Response>() { @Override public void success(final Response result, Response response) { /* Activity is null - Fragment has been detached; no need to do anything. */ if (getActivity() == null) return; Log.d(LOG_TAG, ""); final List<InterestType> interestType = new ArrayList<>(); // you can use this array to populate your spinner final ArrayList<String> interestTypeNames = new ArrayList<String>(); //Try to get response body BufferedReader reader = null; StringBuilder sb = new StringBuilder(); try { reader = new BufferedReader(new InputStreamReader(result.getBody().in())); String line; while ((line = reader.readLine()) != null) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); if (obj.has("interestTypeOptions")) { JSONArray interestTypes = obj.getJSONArray("interestTypeOptions"); for (int i = 0; i < interestTypes.length(); i++) { JSONObject interestTypeObject = interestTypes.getJSONObject(i); InterestType interest = new InterestType(); interest.setId(interestTypeObject.optInt("id")); interest.setValue(interestTypeObject.optString("value")); interestType.add(interest); interestTypeNames.add(interestTypeObject.optString("value")); interestTypeIdHashMap.put(interest.getValue(), interest.getId()); } } String stringResult = sb.toString(); } catch (Exception e) { Log.e(LOG_TAG, "", e); } final ArrayAdapter<String> interestTypeMethodAdapter = new ArrayAdapter<>(getActivity(), layout.simple_spinner_item, interestTypeNames); interestTypeMethodAdapter.setDropDownViewResource(layout.simple_spinner_dropdown_item); sp_interest_type.setAdapter(interestTypeMethodAdapter); sp_interest_type.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { interestTypeId = interestTypeIdHashMap.get(interestTypeNames.get(i)); Log.d("interestType " + interestTypeNames.get(i), String.valueOf(interestTypeId)); if (interestTypeId != -1) { } else { Toast.makeText(getActivity(), getString(R.string.error_select_interest_type), Toast.LENGTH_SHORT).show(); } } @Override public void onNothingSelected(AdapterView<?> parent) { } }); showProgress(false); } @Override public void failure(RetrofitError retrofitError) { Log.d(LOG_TAG, retrofitError.getLocalizedMessage()); showProgress(false); } }); }