как установить значение списка счетчика первой позиции, показывающей пустое - PullRequest
0 голосов
/ 13 декабря 2018

Как установить счетчик. Значение первой позиции списка отображается пустым, я подключил адаптер и занятие: любезно решите мою проблему.

SpinnerAdapterIdtypeMaster

public class SpinnerAdapterIdtypeMaster extends ArrayAdapter {
    private Context mContext;
    private List<CMSSubMasterDB> spinnerList = new ArrayList<>();

    private MasterType type;

    public SpinnerAdapterIdtypeMaster(@NonNull Context context, List<CMSSubMasterDB> list) {
        super(context, 0, list);
        mContext = context;
        spinnerList = list;
    }

    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        return getCustomView(position, convertView, parent);
    }

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

    @Nullable
    @Override
    public CMSSubMasterDB getItem(int position) {
        return spinnerList.get(position);
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View listItem = convertView;
        if (listItem == null)
            listItem = LayoutInflater.from(mContext).inflate(R.layout.spinner_list, parent, false);

        CMSSubMasterDB currentMovie = spinnerList.get(position);


        TextView name = (TextView) listItem.findViewById(R.id.spinner);
        name.setText(currentMovie.name);


        return listItem;
    }


    public View getCustomView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        //return super.getView(position, convertView, parent);

        View listItem = convertView;
        if (listItem == null)
            listItem = LayoutInflater.from(mContext).inflate(R.layout.spinner_list, parent, false);

        TextView label = (TextView) listItem.findViewById(R.id.spinner);
        label.setText(spinnerList.get(position).name);


        return listItem;
    }
}

CreateRyotManagerFragment

public class CreateRyotManagerFragment extends Fragment {
    Spinner mIDType
    List<CMSSubMasterDB> mIdtypeMasterList;
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.layout_new_ryot, container, false);
        mIDType = view.findViewById(R.id.idtype);
        mIdtypeMasterList = AppUtils.getIDTypeMasterDb();
        SpinnerAdapterIdtypeMaster idTypeMaster = new SpinnerAdapterIdtypeMaster(getActivity().getApplicationContext(), mIdtypeMasterList);
        mIDType.setAdapter(idTypeMaster);
        return view;
    }
}

1 Ответ

0 голосов
/ 13 декабря 2018
 Try this code,
          List<CMSSubMasterDB> mIdtypeMasterList = new List<CMSSubMasterDB>;
          CMSSubMasterDB cmsdb = new CMSSubMasterDB();
          cmsdb.setName("Select value");
          mIdtypeMasterList.add(cmsdb);
          List<CMSSubMasterDB> mIdList =AppUtils.getIDTypeMasterDb();
          for (int i=0;i<mIdList.size();i++){
             mIdtypeMasterList.add(mIdList.get(i));
           }
       SpinnerAdapterIdtypeMaster idTypeMaster = new 
       SpinnerAdapterIdtypeMaster(getActivity().getApplicationContext(), 
       mIdtypeMasterList);
       mIDType.setAdapter(idTypeMaster);

 mIDType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                            @Override
                            public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
                                mgetdatacall(position);
                            }

                            @Override
                            public void onNothingSelected(AdapterView<?> adapterView) {

                            }
                        });
private void mgetdatacall(int position) {
  if(position != 0) {
    mIdList.get(position - 1).getname();
   }
  }
...