2016-08-10 3 views
0

이 레이아웃은 텍스트 창의 이름을 변경하는 팝업 창에 사용됩니다. 그러나 편집 문구를 클릭해도 edittext는 키보드를 표시하지 않습니다. 조각에서 사용하고 있습니다. 조각에는이 팝업에서 확인을 클릭 할 때 변경 될 수있는 이름 필드가 있습니다.EditText 팝업창에서 키보드를 열 수 없음

이것은 팝업 창의 xml 파일입니다.

<RelativeLayout 

xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#fff"> 


    <LinearLayout 

    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_alignParentBottom="true" 
    android:id="@+id/name_status_btns" 
    > 

    <Button 

     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:elevation="2dp" 
     android:background="#fff" 
     android:text="CANCEL" 
     android:textSize="18sp" 
     android:textColor="#000" 
     android:id="@+id/cancel_change_name"/> 


    <TextView 

     android:layout_width="1dp" 
     android:layout_height="match_parent" 
     android:background="#b1b0b0"/> 


    <Button 

     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="OK" 
     android:textColor="#000" 
     android:textSize="18sp" 
     android:elevation="2dp" 
     android:background="#fff" 
     android:id="@+id/ok_change_name" 
     /> 


    </LinearLayout> 


<TextView 

    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="#b1b0b0" 
    android:layout_above="@id/name_status_btns" 
    android:id="@+id/name_status_horizontal_liner"/> 


    <RelativeLayout 

    android:layout_width="match_parent" 
    android:layout_height="60dp" 
    android:layout_marginTop="15dp" 
    android:layout_marginLeft="15dp" 
    android:layout_marginRight="15dp" 
    android:id="@+id/name_status_edit_field"> 


    <EditText 

     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="5" 
     android:hint="write your name here" 
     android:scrollHorizontally="true" 
     android:id="@+id/change_name" 
     android:focusable="true" 
     android:focusableInTouchMode="true"/> 


    </RelativeLayout> 



    <TextView 

    android:layout_width="match_parent" 
    android:layout_height="1dp" 
    android:background="@color/mainColor" 
    android:layout_below="@id/name_status_edit_field" 
    android:layout_marginLeft="15dp" 
    android:layout_marginRight="15dp" 

    /> 

    </RelativeLayout> 

위 XML에 대한 자바 파일입니다.

public class Name_Status extends AppCompatActivity implements View.OnClickListener { 

EditText name_change; 
RelativeLayout name_status_edit_field; 
String name; 
Button cancel_name_change , ok_name_change; 
@Override 
protected void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.name_status); 
    DisplayMetrics dm=new DisplayMetrics(); 
    getWindowManager().getDefaultDisplay().getMetrics(dm); 

    int width=dm.widthPixels; 
    int height=dm.heightPixels; 

    getWindow().setLayout((int)(width*.8),(int)(height*.3)); 
    name_change=(EditText)findViewById(R.id.change_name); 
    name_status_edit_field=(RelativeLayout)findViewById(R.id.name_status_edit_field); 
    name=name_change.getText().toString(); 
    cancel_name_change=(Button)findViewById(R.id.cancel_change_name); 
    ok_name_change=(Button)findViewById(R.id.ok_change_name); 
    ok_name_change.setOnClickListener(this); 
    name_change.setOnClickListener(this); 
    name_status_edit_field.clearFocus(); 
    name_change.setFocusable(true); 
    //name_change.update(); 
} 

@Override 
public void onClick(View v) { 
      if(v.getId()==R.id.ok_change_name) 
      {FragActivity1 obj=new FragActivity1(); 
    obj.changeName(name); 
    Intent intent=new Intent(); 
    intent.setClass(Name_Status.this , MainActivity.class); 
    startActivity(intent);} 
    if(v.getId()==R.id.change_name) 
    { 
     InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.toggleSoftInputFromWindow(name_change.getApplicationWindowToken(), InputMethodManager.SHOW_FORCED, 0); 
    } 

} 
} 
+0

제 대답을 확인하십시오. – himanshu1496

답변

1

를 참조 위해

글고

editText.setOnFocusChangeListener(new OnFocusChangeListener() { 

    @Override 
    public void onFocusChange(final View v, final boolean hasFocus) { 
     if (hasFocus && editText.isEnabled() && editText.isFocusable()) 
      editText.post(new Runnable() { 
       @Override 
       public void run() { 
        final InputMethodManager imm = (InputMethodManager) context 
          .getSystemService(Context.INPUT_METHOD_SERVICE); 
        imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 
       } 
      }); 
    } 
}); 
에 대해 다음 시도 할 수 EditText RelativeLayout에서 0dp 폭과 layout_weight 속성을 가지고, 어떤 의미가 없습니다.

중 하나 EditText의 부모가 LinearLayout또는EditText에서 layout_weight 속성을 제거하고 그것을 적절한 폭을 제공합니다

<EditText 
    android:id="@+id/change_name" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="write your name here" 
    android:scrollHorizontally="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true"/> 

다음 코드는 완전히 불필요합니다, 당신은 단지에서 제거해야합니다을 onClick() :

if(v.getId()==R.id.change_name) 
{ 
    InputMethodManager imm = (InputMethodManager) getSystemService(Context. 
     INPUT_METHOD_SERVICE); 
    imm.toggleSoftInputFromWindow(name_change.getApplicationWindowToken(), 
     InputMethodManager.SHOW_FORCED, 0); 
} 
0

EditText는을 가지고 생각하지 않습니다너비와 은 RelativeLayout 안에 있습니다. 무게는 LinearLayout 안에 있습니다. 그래서 EditText 아래에 변경 :

<EditText 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:hint="write your name here" 
    android:scrollHorizontally="true" 
    android:id="@+id/change_name" 
    android:focusable="true" 
    android:focusableInTouchMode="true"/> 

을 변경하여 EditText 그 자체로 클릭 돌볼 때문에에 OnClick :

@Override 
public void onClick(View v) { 
if(v.getId()==R.id.ok_change_name){ 
    FragActivity1 obj=new FragActivity1(); 
    obj.changeName(name); 
    Intent intent=new Intent(); 
    intent.setClass(Name_Status.this , MainActivity.class); 
    startActivity(intent); 
} 
} 

을 그리고 마지막으로 당신의 OnCreate() 방법에서 아래 줄을 제거 :

name_change.setOnClickListener(this); 

EditText은 (를) 클릭하면 키보드가 열립니다.

관련 문제