OnCickListener没有使用EditText

时间:2018-01-20 13:52:46

标签: android

点击监听器没有在android

中编辑文本
<EditText
            android:id="@+id/state_search_UPFET"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="15sp"
            android:clickable="true"
            android:cursorVisible="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:layout_below="@id/textView1"
            android:hint="@string/hintState"
            android:inputType="none"
            android:padding="12sp" />

1 个答案:

答案 0 :(得分:0)

   public class DoctorSearchFragment extends BaseFragment implements AbstractView, View.OnClickListener  {
    // TODO: Rename parameter arguments, choose names that match
    private EditText SEARCH_STATE, SEARCH_CITY, DEPARTMENT;
    private static final String ARG_PARAM1 = "param1";
    private static final String ARG_PARAM2 = "param2";
    public static DoctorSearchFragment doctorSearchFragment;

    // TODO: Rename and change types of parameters
    private String mParam1;
    private String mParam2;
    private OnFragmentInteractionListener mListener;
    private Button getDoctorButton;

    public DoctorSearchFragment() {
        // Required empty public constructor
    }


    // TODO: Rename and change types and number of parameters
    public static DoctorSearchFragment newInstance(String param1, String param2) {
        DoctorSearchFragment fragment = new DoctorSearchFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        doctorSearchFragment=this;
        setHasOptionsMenu(false);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
        AppController.getInstance().getMainActivity().getSupportActionBar().setTitle(getString(R.string.search_doctor_by));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_book_appointment, container, false);
        initializeComponents(view);
        return view;
    }

    private void initializeComponents(View view) {
        SEARCH_CITY = (EditText) view.findViewById(R.id.city_search_UPFET);
        SEARCH_STATE = (EditText) view.findViewById(R.id.state_search_UPFET);
        DEPARTMENT = (EditText) view.findViewById(R.id.dept_search_UPFET);
        getDoctorButton = (Button) view.findViewById(R.id.getDoctor) ;

        SEARCH_STATE.setOnClickListener(this);
        SEARCH_CITY.setOnClickListener(this);
        DEPARTMENT.setOnClickListener(this);
        getDoctorButton.setOnClickListener(this);
        //progressBar.setVisibility(View.VISIBLE);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        switch (id) {
            case R.id.state_search_UPFET:
                SEARCH_STATE.setError(null);
                SEARCH_STATE.setText("");
                StateListDialog stateListDialog = new StateListDialog();
                stateListDialog.setAppCompatActivity((AppCompatActivity) getActivity());
                stateListDialog.loadData();
                break;

            case R.id.city_search_UPFET:
                SEARCH_CITY.setError(null);
                SEARCH_CITY.setText("");
                CityListDialog cityListDialog = new CityListDialog();
                cityListDialog.setAppCompatActivity((AppCompatActivity) getActivity());
                cityListDialog.loadData(SEARCH_STATE.getText().toString());
                break;

            case R.id.getDoctor:
                AppController.getInstance().handleEvent(AppDefines.EVENT_ID_DOCTORSLIST);
                break;
        }
    }

    public void setState(String state) {
        Log.d("TAG", "FRAGMENT STATE " + state + " IS STATE NULL " + (SEARCH_STATE == null));
        if (SEARCH_STATE != null) SEARCH_STATE.setText(state);
        if (SEARCH_CITY != null) SEARCH_CITY.setText("");
    }

    public void setCity(String city) {
        Log.d("TAG", "FRAGMENT STATE " + city + " IS STATE NULL " + (SEARCH_CITY == null));
        if (SEARCH_CITY != null) SEARCH_CITY.setText(city);
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    @Override
    public void update() {

    }

    @Override
    public void onFragmentResume() {
        AppController.getInstance().getMainActivity().getSupportActionBar().setTitle(getString(R.string.search_doctor_by));
    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }

    public static DoctorSearchFragment getInstance() {
        return doctorSearchFragment;
    }
}