0

TextInputLayout 안에 Edittext가 있습니다. 나는이 textinputlayout 클릭 한 다음 calender 또한 open.but 경우 부동 레이블을 상태를 변경하고 편집 단추를 클릭하면 다음 calender opening.but 나는 그것을 할 싶지 않아 할 싶어요. 사용자가 TextInputLayout을 처음 클릭 할 때 플로팅 레이블이 변경되고 달력도 it.can에서 열리면 누구에게 어떻게 할 수 있는지 알려주시겠습니까 ?? 플로팅 레이블이 TextInputLayout에서 상태를 변경할 때 작업을 수행하는 방법은 무엇입니까?

내 XML입니다 : -

<android.support.design.widget.TextInputLayout 
        android:id="@+id/til_dob" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent" 
        android:layout_margin="@dimen/_10sdp" 
        android:clickable="true" 
        android:textColorHint="@color/colorBlack"> 

        <EditText 
         android:id="@+id/DateOfBirth" 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:hint="@string/date" 
         android:inputType="none" 
         android:maxLines="1" 
         android:singleLine="true" 
         android:textSize="15sp" /> 
       </android.support.design.widget.TextInputLayout> 

그리고 이것은 글고 치기에 클릭 리스너에 내입니다 : -

당신은 TextInputLayout이를 위해 클릭했을 때 반응하는 OnFocusChangeListener를 사용해야합니다
@Override 
    public void onClick(View view) { 
     switch (view.getId()) { 

      case R.id.DateOfBirth: 

       new DatePickerDialog(getContext(), date, myCalendar 
         .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), 
         myCalendar.get(Calendar.DAY_OF_MONTH)).show(); 

       break; 

     } 
    } 

답변

0

처음으로 (TextInputLayout 내부의 EditText가 포커스를 얻음을 의미)

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
    @Override public void onFocusChange(View v, boolean hasFocus) { 
    //Open the calendar 
    new DatePickerDialog(getContext(), date, myCalendar 
        .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), 
        myCalendar.get(Calendar.DAY_OF_MONTH)).show(); 
    } 
}); 

T 그는 "람다 버전"이 될 것입니다 :

editText.setOnFocusChangeListener((v, hasFocus) -> 
    new DatePickerDialog(getContext(), date, myCalendar 
        .get(Calendar.YEAR), myCalendar.get(Calendar.MONTH), 
        myCalendar.get(Calendar.DAY_OF_MONTH)).show()); 
+0

당신 말이 맞아요. 하지만 이전 조각으로 이동하면 edittext의 초점이 다시 변경됩니다. 그러면 캘린더 팝업이 다시 표시됩니다. 어떻게 해결할 수 있을까요? – LoveAndroid