2016-01-17 41 views
1

好的,你好! 几个小时我试图设置我的对话框有超过一个或两个EditTexts,可以编辑。 EditTexts在Dialog的空间中是可见的,但是当我想编辑它们中的任何一个的内容并且当我点击它时,这个魔术键盘不会显示出来。对话框中的多个EditText

public class Statistics extends ActionBarActivity{ 
. 
. 
. 
public void buttonClick(View view) { 

    Random r = new Random(); 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.intintmap_item_list); 
    int temp = r.nextInt(6); 
    for(int i = 0; i < temp; i++){ 
     adapter.add("data"+i); 
    } 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setTitle("title"); 
    builder.setAdapter(adapter, new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int item) { 

     } 
    }); 
    builder 
    .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
     public void onClick(DialogInterface dialog, int id) { 
      Log.d("AAAAAA", "YES"); 

     } 
    }) 
    .setNegativeButton("NO!", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        Log.d("AAAAAA","NO"); 
     } 
    }); 

    AlertDialog alert = builder.create(); 
    alert.show(); 
} 

intintmap_item_list.xml

<?xml version="1.0" encoding="utf-8"?> 


<EditText xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:inputType="number" 
    android:ems="10" 
    android:id="@+id/intintmapitemlist" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentStart="true" /> 

ANY1能帮忙吗?请?

+0

你必须设置edtname.setfocusable(真);这对我有用。 – Bhoomika

+0

不工作:(光标是可见的,它闪烁,但键盘仍然不显示。 – Raztyck

回答

0

粘贴在此buttonClick方法的结束帮:

alert.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM); 
    alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);