2016-05-18 12 views
0

Ich habe zwei EditText s und eine CheckBox und eine Button in meinem Layout in der obigen Reihenfolge. Nach Eingabe der Werte in die EditText muss der Benutzer die Allgemeinen Geschäftsbedingungen akzeptieren, indem er auf Checkbox klickt. Ich muss den Fokus von EditText s entfernen, nachdem das Kontrollkästchen angeklickt wurde. Im Moment liegt der Fokus immer auf der zweiten EditText. Wie kann dies erreicht werden? Bitte helfen Sie. Layout-: Fokus von einem EditText in Android entfernen

<EditText 
     android:id="@+id/pm_et_customer_id" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:ems="10" 
     android:hint="@string/customer_id_hint" 
     android:fontFamily="sans-serif-light" 
     android:gravity="center" 
     android:singleLine="true" 
     android:layout_centerHorizontal="true" 
     android:inputType="phone" 
     android:textAppearance="?android:attr/textAppearanceMedium"/> 

    <RelativeLayout 
     android:id="@+id/pm_rl_mob_no_widget" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:padding="6dp" 
     android:layout_below="@id/pm_et_customer_id" 
     android:gravity="center_horizontal"> 

    <EditText 
     android:id="@+id/pm_et_dial_code" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/pm_et_msisdn" 
     android:layout_marginLeft="5dp" 
     android:ems="3" 
     android:fontFamily="sans-serif-thin" 
     android:gravity="center" 
     android:text="@string/plus_nine_one" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
    /> 

    <EditText 
     android:id="@+id/pm_et_msisdn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/pm_et_dial_code" 
     android:ems="9" 
     android:fontFamily="sans-serif-light" 
     android:gravity="center_horizontal" 
     android:hint="@string/msisdn_hint" 
     android:inputType="phone" 
     android:maxLength="14"/> 
    </RelativeLayout> 

    <Button 
     android:id="@+id/pm_bt_proceed" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/lay_t_c" 
     android:layout_centerHorizontal="true" 
     android:layout_marginLeft="20dp" 
     android:layout_marginRight="20dp" 
     android:layout_marginTop="8dp" 
     android:fontFamily="sans-serif-light" 
     android:text="@string/bt_label_proceed"/> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/pm_rl_mob_no_widget" 
     android:id="@+id/lay_t_c" 
     android:layout_marginTop="10dp" 
     android:gravity="center" 
     android:orientation="horizontal"> 
    <CheckBox 
     android:id="@+id/pm_check_t_and_c" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:fontFamily="sans-serif-thin" 
     android:textSize="14sp" 
     android:text="@string/pm_label_accept"/> 

    <TextView 
     android:id="@+id/pm_tv_t_and_c" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:layout_marginRight="4dp" 
     android:layout_marginEnd="4dp" 
     android:paddingLeft="4dp" 
     android:paddingStart="4dp" 
     android:fontFamily="sans-serif-light" 
     android:text="@string/pm_label_t_and_c" 
     android:textSize="14sp"/> 
    </LinearLayout> 

</RelativeLayout> 
+0

nur klar Ihren Fokus auf 'Prüfe Box' klicken. –

+0

@bärtiges Tier, was ist die Reihenfolge deiner Ansichten im Layout? – Dhiraj

+0

@jaydroider sein Fokus zuerst EditText –

Antwort

-1
editText.setEnabled(false); 

es auf Checkbox listner Verwenden arbeitete es für mich

+0

Wenn ich das mache, kann ich es nicht mehr bearbeiten. –

+0

vor der Bearbeitung diese Zeile editText.setEnabled (false); – Haroon

0
checkBox.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      editText.setFocusable(false); 
     } 
    }); 

oben OnClickListener box zu überprüfen.

+0

Wenn mir das gefällt, kann ich EditText nicht mehr bearbeiten. –

+1

set 'android: focusableInTouchMode =" true "' zu den meisten äußeren Layout. und rufen Sie 'editText.clearFocus();' im Kontrollkästchen OnClickListener auf. Funktioniert bei mir. –

0
checkBox.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      editText.setFocusable(false); 
     } 
    }); 

Nach Fokus zu entfernen, gehen Sie bitte ein mehr ..

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

0

onCheckedChangeListener von Check Box Verwenden Sie dies tun können. gelten diese nur auf Ihrem Activity's onCreate()

chb1 = (CheckBox) findViewById(R.id.pm_check_t_and_c); 
     chb1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { 
      @Override 
      public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
       if (chb1.isChecked()) { 
        edt1.clearFocus(); 
        InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.hideSoftInputFromWindow(edt1.getWindowToken(), 0); 
       } else { 
        edt1.requestFocus(); 
       } 

      } 
     }); 
+0

funktioniert es oder nicht? –