Android 使用改造1.9填充纺纱机?

Android 使用改造1.9填充纺纱机?,android,spinner,retrofit,Android,Spinner,Retrofit,我正在寻找一个示例程序,它可以使用改型1.9从服务器上动态填充微调器项,但我仍然找不到任何示例可以共享,如果有任何示例与此要求相关,或者共享此方法。 这应该怎么做,因为我是新的安卓位苦苦寻找解决方案提前感谢 这是我的spinneritem类: public class MySpinnerItem { public MySpinnerItem(){ } public MySpinnerItem(String text, Integer value) {

我正在寻找一个示例程序,它可以使用
改型1.9
从服务器上动态填充
微调器
项,但我仍然找不到任何示例可以共享,如果有任何示例与此要求相关,或者共享此方法。 这应该怎么做,因为我是新的安卓位苦苦寻找解决方案提前感谢

这是我的spinneritem类:

public class MySpinnerItem {

    public MySpinnerItem(){

    }
    public MySpinnerItem(String text, Integer value) {
        Text = text;
        Value = value;
    }

    public String getText() {
        return Text;
    }

    public void setText(String text) {
        Text = text;
    }

    public Integer getValue() {
        return Value;
    }

    public void setValue(Integer value) {
        Value = value;
    }

    public String Text;
    public Integer Value;

}
这是我的微调器适配器:

package first.service.precision.servicefirst;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by 4264 on 25-11-2015.
 */
public class MySpinnerAdapter extends ArrayAdapter<MySpinnerItem> {

    private Context context;
    private List<MySpinnerItem> objects;
    public MySpinnerAdapter(Context context, int resource, List<MySpinnerItem> objects) {
        super(context, resource, objects);
        this.context = context;
        this.objects = objects;
    }

    @Override
    public void add(MySpinnerItem object) {
       this.objects.add(object);
    }


    @Override
    public int getCount() {
        return objects.size();
    }

    @Override
    public MySpinnerItem getItem(int position) {
        return objects.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        TextView label = new TextView(context);
        label.setText(objects.get(position).getText());
        return label;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        TextView label = new TextView(context);
        label.setText(objects.get(position).getText());
        return label;
    }
}
package first.service.precision.servicefirst;
导入android.content.Context;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.TextView;
导入java.util.List;
/**
*由4264于2015年11月25日创建。
*/
公共类MySpinnerAdapter扩展了ArrayAdapter{
私人语境;
私有列表对象;
公共MySpinnerAdapter(上下文上下文、int资源、列表对象){
超级(上下文、资源、对象);
this.context=上下文;
this.objects=对象;
}
@凌驾
公共void添加(MySpinnerItem对象){
this.objects.add(object);
}
@凌驾
public int getCount(){
返回objects.size();
}
@凌驾
公共MySpinnerItem getItem(int位置){
返回对象。获取(位置);
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
TextView标签=新的TextView(上下文);
label.setText(objects.get(position.getText());
退货标签;
}
@凌驾
公共视图getDropDownView(int位置、视图转换视图、视图组父视图){
TextView标签=新的TextView(上下文);
label.setText(objects.get(position.getText());
退货标签;
}
}
下面是我为微调器设置适配器的片段:

package first.service.precision.servicefirst;

/**
 * Created by 4264 on 23-11-2015.
 */

import android.app.Fragment;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;

import com.squareup.otto.Bus;

import java.util.ArrayList;
import java.util.List;

public class NewRequirements extends Fragment {
    Bus bus;
    MyListAdapter listAdapter;

    @Override

    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        List<MySpinnerItem> SbuList = new ArrayList<MySpinnerItem>();
        SbuList.add(new MySpinnerItem("Saravanan.R",1));
        SbuList.add(new MySpinnerItem("Yogeshwaran",2));
        SbuList.add(new MySpinnerItem("Sathesh",3));
        SbuList.add(new MySpinnerItem("Barath",4));
        SbuList.add(new MySpinnerItem("Deepak",5));
        SbuList.add(new MySpinnerItem("Venkat",6));
        SbuList.add(new MySpinnerItem("Meena",7));
        SbuList.add(new MySpinnerItem("Ram",8));
        SbuList.add(new MySpinnerItem("Jegan",9));

        View view = inflater.inflate(R.layout.fragment_dialog_claim, container,
                false);
        final Button btnupdate;
        btnupdate = (Button) view.findViewById(R.id.btnAdd);

        final Spinner spSbuID = (Spinner) view.findViewById(R.id.spSbuID);
        final Spinner spBuID = (Spinner) view.findViewById(R.id.spBuID);
        final Spinner spSubBuID = (Spinner) view.findViewById(R.id.spSubBuID);
        final Spinner spServiceCategoryID = (Spinner) view.findViewById(R.id.spServiceCategoryID);
        final Spinner spServiceSubCategoryID = (Spinner) view.findViewById(R.id.spServiceSubCategoryID);
        final EditText txtRequirements=(EditText)view.findViewById(R.id.txtRequirements);

        MySpinnerAdapter myadapter = new MySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple_spinner_dropdown_item,SbuList);
        spSbuID.setAdapter(myadapter);

        myadapter = new MySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple_spinner_dropdown_item,SbuList);
        spBuID.setAdapter(myadapter);

        myadapter = new MySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple_spinner_dropdown_item,SbuList);
        spSubBuID.setAdapter(myadapter);

        myadapter = new MySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple_spinner_dropdown_item,SbuList);
        spServiceCategoryID.setAdapter(myadapter);

        myadapter = new MySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple_spinner_dropdown_item,SbuList);
        spServiceSubCategoryID.setAdapter(myadapter);




        try{
            Object o;
            o = getFragmentManager().findFragmentByTag("add");
            Log.v("FIND", o.toString());
        }
        catch (Exception ex) {
            Log.v("FIND", ex.toString());
        }

     //   add.notify();

        btnupdate.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                LeadRequirementsView objLeadRequirementsView = new LeadRequirementsView();
                MySpinnerItem item;

                item = (MySpinnerItem)spSbuID.getSelectedItem();
                objLeadRequirementsView.setSbuID(item.getValue());
                objLeadRequirementsView.setSbuName(item.getText());

                item = (MySpinnerItem)spBuID.getSelectedItem();
                objLeadRequirementsView.setBuID(item.getValue());
                objLeadRequirementsView.setBuName(item.getText());

                item = (MySpinnerItem)spSubBuID.getSelectedItem();
                objLeadRequirementsView.setSubBuID(item.getValue());
                objLeadRequirementsView.setSubBuName(item.getText());

                item = (MySpinnerItem)spServiceCategoryID.getSelectedItem();
                objLeadRequirementsView.setServiceCategoryID(item.getValue());
                objLeadRequirementsView.setServiceCategoryName(item.getText());

                item = (MySpinnerItem)spServiceSubCategoryID.getSelectedItem();
                objLeadRequirementsView.setServiceSubCategoryID(item.getValue());
                objLeadRequirementsView.setServiceSubCategoryName(item.getText());

                objLeadRequirementsView.setDescription(txtRequirements.getText().toString());

                Add add;

                add = (Add)getFragmentManager().findFragmentByTag("add");
                add.updateListView(objLeadRequirementsView);
                getActivity().getFragmentManager().popBackStack();
            }

        });
        return view;
    }



}
package first.service.precision.servicefirst;
/**
*由4264于2015年11月23日创建。
*/
导入android.app.Fragment;
导入android.os.Bundle;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.Button;
导入android.widget.EditText;
导入android.widget.Spinner;
导入com.squareup.otto.Bus;
导入java.util.ArrayList;
导入java.util.List;
公共类NewRequirements扩展了片段{
公共汽车;
MyListAdapter列表适配器;
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
//TODO自动生成的方法存根
List SbuList=new ArrayList();
SbuList.add(新MySpinnerItem(“Saravanan.R”,1));
添加(新MySpinnerItem(“Yogeshwaran”,2));
添加(新MySpinnerItem(“Sathesh”,3));
SbuList.add(新MySpinnerItem(“Barath”,4));
添加(新的MySpinnerItem(“Deepak”,5));
添加(新的MySpinnerItem(“Venkat”,6));
添加(新MySpinnerItem(“Meena”,7));
添加(新的MySpinnerItem(“Ram”,8));
SbuList.add(新MySpinnerItem(“Jegan”,9));
视图=充气机。充气(R.layout.fragment\u对话框\u索赔,集装箱,
假);
最终按钮BTNUDATE;
btnupdate=(按钮)view.findviewbyd(R.id.btnAdd);
最终微调器spSbuID=(微调器)view.findviewbyd(R.id.spSbuID);
最终微调器spBuID=(微调器)view.findViewById(R.id.spBuID);
最终微调器spSubBuID=(微调器)view.findViewById(R.id.spSubBuID);
最终微调器spServiceCategoryID=(微调器)view.findViewById(R.id.spServiceCategoryID);
最终微调器spServiceSubCategoryID=(微调器)view.findViewById(R.id.spServiceSubCategoryID);
final EditText txtRequirements=(EditText)view.findViewById(R.id.txtRequirements);
MySpinnerAdapter myadapter=新的MySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple\u微调器\u下拉菜单\u项,SbuList);
spSbuID.setAdapter(myadapter);
myadapter=newmySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple\u微调器\u下拉菜单\u项,SbuList);
spBuID.setAdapter(myadapter);
myadapter=newmySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple\u微调器\u下拉菜单\u项,SbuList);
spSubBuID.setAdapter(myadapter);
myadapter=newmySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple\u微调器\u下拉菜单\u项,SbuList);
spServiceCategoryID.setAdapter(myadapter);
myadapter=newmySpinnerAdapter(getActivity().getBaseContext(),android.R.layout.simple\u微调器\u下拉菜单\u项,SbuList);
spServiceSubCategoryID.setAdapter(myadapter);
试一试{
对象o;
o=getFragmentManager().findFragmentByTag(“添加”);
Log.v(“FIND”,o.toString());
}
捕获(例外情况除外){
Log.v(“FIND”,例如toString());
}
//add.notify();
btnupdate.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
LeadRequirementsView objLeadRequirementsView=新LeadRequirementsView();
糠秕项目;
item=(MySpinnerItem)spSbuID.getSelectedItem();
objLeadRequirementsView.setSbuID(item.getValue());
objLeadRequirementsView.setSbuName(item.getText());
item=(MySpinnerItem)spBuID.getSelectedItem();
objLeadRequirementsView.setBuID(item.getValue());
objLeadRequirementsView.setBuName(item.getText());
item=(MySpinnerItem)spSubBuID.getSelectedItem();
objLeadRequirementsView.setSubBuID(item.getValue());
objLeadRequirementsView.setSubBuName(item.getText());
item=(MySpinnerItem)spServiceCategoryID.getSelectedItem();
objLeadRequir
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> adapter;
List<String> data;

data = new ArrayList<>();
for (int i = 0; i < 20; i++)
        data.add("Data " + (i + 1));

adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, data);
spinner.setAdapter(adapter);
/**
 * reCreated by goodlife on 1/11/2016.
 */
import java.util.List;


import retrofit.Callback;
import retrofit.client.Response;
import retrofit.http.Field;
import retrofit.http.FormUrlEncoded;
import retrofit.http.GET;
import retrofit.http.POST;

/**
 * Created by Belal on 11/5/2015.
 */
public interface RetrofitInternetApi {

    //@FormUrlEncoded, we have to write this if we want to send post data to the server.
    //@POST, because we are using an HTTP Post request we have written this.
    // Inside it we have the URL of the script that will be receiving the post request.
    // Note that the URL is excluding the root URL. And we have defined the root URL  in our MainActivity.
    //@Field(“key”) String variable inside key we have to write what we have written inside $_POST[‘key’] in our script.
    // And we have to specify it for all the values we are going to send.

    //Callback<Response> callback it is also inside the retrofit library. It will receive the output from the server.

    //But this is only an interface and the method is abstract.
    //We will define the method inside fetchDepartmentName() method that is declared inside MainActivity.java.

    @GET("/getDepartmentName.php")
    public void getDepartmentName(Callback<List<DepartmentNoRealm>> response);

}
  private void fetchDepartmentName(){
//Creating a rest adapter
        RestAdapter restAdapter = new RestAdapter.Builder()
                .setEndpoint(ROOT_URL)
                .build();

        //Creating an object of our api interface
        RetrofitInternetApi retrofitInternetApi = restAdapter.create(RetrofitInternetApi.class);
            //While the app fetched data we are displaying a progress dialog
            final ProgressDialog loading = ProgressDialog.show(getActivity(), "Fetching Data", "Please wait...", false, false);



            //Defining the method
            retrofitInternetApi.getDepartmentName(new Callback<List<DepartmentNoRealm>>() {
                @Override
                public void success(List<DepartmentNoRealm> list, Response response) {
                    //Dismissing the loading progressbar
                    loading.dismiss();
                    Log.d("JSON  LIST",list.toString());
                    //Storing the data in our list
                    departmentNoRealmList = list;

                    //Calling a method to show the list
                      showListinSpinner();            }

                @Override
                public void failure(RetrofitError error) {
                    //you can handle the errors here
                }
            });
        }
package myafya.safaricom.co.ke.myafya.model.realm;

/**
 * Created by 001557 on 1/13/2016.
 */
public class DepartmentNoRealm {
    public int departmentID;
    public String departmentName;
    public String departmentURLimage;

    public int getDepartmentID() {
        return departmentID;
    }

    public void setDepartmentID(int departmentID) {
        this.departmentID = departmentID;
    }

    public String getDepartmentName() {
        return departmentName;
    }

    public void setDepartmentName(String departmentName) {
        this.departmentName = departmentName;
    }

    public String getDepartmentURLimage() {
        return departmentURLimage;
    }

    public void setDepartmentURLimage(String departmentURLimage) {
        this.departmentURLimage = departmentURLimage;
    }
}
//Our method to show list
    private void showListinSpinner(){
        //String array to store all the book names
        String[] items = new String[departmentNoRealmList.size()];

        //Traversing through the whole list to get all the names
        for(int i=0; i<departmentNoRealmList.size(); i++){
            //Storing names to string array
            items[i] = departmentNoRealmList.get(i).getDepartmentName();
        }

        //Spinner spinner = (Spinner) findViewById(R.id.spinner1);
        ArrayAdapter<String> adapter;
        adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, items);
        //setting adapter to spinner
        spinnerDepartments.setAdapter(adapter);
        //Creating an array adapter for list view

    }
[
  {
    "departmentID": "1",
    "departmentName": "Enterprise Business Unit (EBU)",
    "departmentURLimage": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcSKOZmGNAA08NbHwRJrloAouWqs6r4x7BGXY4k-ULWiHuPEobHI"
  },
  {
    "departmentID": "2",
    "departmentName": "Consumer Business Unit (CBU)",
    "departmentURLimage": "https://encrypted-tbn1.gstatic.com/images?q=tbn:ANd9GcQ0IAFhZ52KiG_0ck5VbBxweZWf_MEA9eRmgHAEr6CG-rUG_a2QEQ"
  }
]
        try {
            Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(Constants.BASE_URL)
                    .addConverterFactory(GsonConverterFactory.create())
                    .build();
            APIService service = retrofit.create(APIService.class);
            Call<List<People>> call = service.getYear(user_id);
            call.enqueue(new Callback<List<People>>()
            {
                @Override
                public void onResponse(Response<List<People>> response, Retrofit retrofit) {
                    posts = response.body();
            String[] s =new String[posts.size()];
                    for(int i=0;i<posts.size();i++)
                    {
                       s[i]= posts.get(i).getYear();
                        final ArrayAdapter a = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_spinner_item, s);
                        a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                        //Setting the ArrayAdapter data on the Spinner
                        Branch.setAdapter(a);
                    }                    
                }
                @Override
                public void onFailure(Throwable t) { }
            });
        } catch (Exception e) {
            Log.d("onResponse", "There is an error");
               }

}