Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EActivity extends Fragment {
- ArrayList<Countries> countries;
- JSONArray countryArray;
- Spinner e_country;
- @Nullable
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
- MainActivity.fragmentName="eR";
- final View v= inflater.inflate(R.layout.activity_e,null);
- e_country=(Spinner)v.findViewById(R.id.txtECountry);
- progressDialog=new ProgressDialog(v.getContext());
- getCountry(v);
- return v;
- }
- void getCountry(final View view){
- progressDialog.setMessage("Loading, Please wait...");
- progressDialog.setIndeterminate(true);
- progressDialog.show();
- JsonObjectRequest objectRequest=new JsonObjectRequest(Request.Method.GET, ApiLinks.countryPoint, null,
- new Response.Listener<JSONObject>() {
- @Override
- public void onResponse(JSONObject response) {
- try {
- String status = response.getString("status");
- if(status.equals("success")){
- countryArray=response.getJSONArray("country");
- countries=new ArrayList<Countries>();
- for(int i=0;i<countryArray.length();i++){
- JSONObject object=countryArray.getJSONObject(i);
- Countries country=new Countries();
- country.setId(object.getInt("id"));
- country.setName(object.getString("country"));
- countries.add(country);
- }
- ArrayAdapter<Countries> adapter=new ArrayAdapter<Countries>(view.getContext(),android.R.layout.simple_spinner_dropdown_item
- ,countries);
- e_country.setAdapter(adapter);
- e_country.setPrompt("-- Select Country --");
- }
- }catch(Exception e){
- Toast.makeText(view.getContext(),"Country not loaded.Please go back and try again.",Toast.LENGTH_SHORT).show();
- }
- progressDialog.cancel();
- }
- },
- new Response.ErrorListener() {
- @Override
- public void onErrorResponse(VolleyError error) {
- Toast.makeText(view.getContext(),"Country not loaded.Please go back and try again.",Toast.LENGTH_SHORT).show();
- progressDialog.cancel();
- }
- });
- AppSingleton.getInstance(view.getContext().getApplicationContext()).addToRequestQueue(objectRequest,ApiLinks.REQUEST_TAG);
- }
- <Spinner
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:id="@+id/txtECountry"
- android:layout_below="@+id/textView18"
- android:layout_alignParentLeft="true"
- android:layout_alignParentStart="true"
- android:paddingTop="10dp"
- android:paddingBottom="10dp"
- android:layout_marginTop="8dp"
- android:layout_marginBottom="8dp"
- android:background="@drawable/textbox_style"/>
Add Comment
Please, Sign In to add comment