2011-01-13 13 views
1

Ich habe einen Text bearbeiten in einem Alarm-Dialog für einige Benutzereingaben. Aber wenn ich auf den Text klicke, wird die Soft-Tastatur nicht angezeigt.EditText in einem alertDialogue zeigt keine Softkeyboard in Android

Wenn derselbe Bearbeitungstext innerhalb eines Dialogfelds platziert wird, wird die Tastatur angezeigt, wenn der Bearbeitungstext fokussiert ist.

public class LaunchingActivity extends Activity { 

    Button addSubList = null; 
    TableLayout tabLayToDoList; 
    int textViewId = StaticContents.textViewId; 
    int edtTxtViewId = StaticContents.edtTxtViewId; 
    int ImgViewId = StaticContents.ImgViewId; 
    int relLayViewId = StaticContents.relLayViewId; 
    int count = StaticContents.count; 
    CustomDialog share; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     System.out.println(textViewId + " " + edtTxtViewId + " " + ImgViewId 
          + " " + relLayViewId); 
     addSubList = (Button) findViewById(R.id.btnAddSubItem); 
     tabLayToDoList = (TableLayout) findViewById(R.id.tabLayToDoList); 

    } 

    public void showSublistDialog() { 
     Dialog subList = new Dialog(this); 
     Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) 
      .getDefaultDisplay(); 
     int width = display.getWidth(); 
     int height = display.getHeight(); 
     System.out.println("Display Width and Height :" + "width " + width 
          + " height " + height); 
     subList.show(); 

     // rel.setLayoutParams(layoutPrams); 
    } 
    @Override 
    protected void onPostResume() { 
     addSubList.setOnClickListener(new OnClickListener() { 

       public void onClick(View arg0) { 
        count = 0; 
        share = new CustomDialog(LaunchingActivity.this); 
        share.show(); 

       } 
      }); 

     super.onPostResume(); 
    } 
    private class CustomDialog extends Dialog { 

     public CustomDialog(Context context) { 
      super(context); 
      // TODO Auto-generated constructor stub 
     } 

     RelativeLayout relLayParent; 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.addsubitem); 

      Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) 
       .getDefaultDisplay(); 
      int width = display.getWidth(); 
      int height = display.getHeight(); 

      LayoutParams params = getWindow().getAttributes(); 
      if(height>width){ 
       //potrait mode 
       params.height = height - 150; 
       params.width = width-60; 
      }else{ 
       params.height = height - 100; 
       params.width = width-100; 
      } 

      getWindow().setAttributes(
             (android.view.WindowManager.LayoutParams) params); 

      relLayParent = (RelativeLayout) findViewById(R.id.relLayParent); 
      addDesScription(relLayParent, R.id.relLaySubListContent); 
      addDesScription(relLayParent, R.id.relLaySubListContent); 

     } 

     public void addDesScription(RelativeLayout relParent, int relLayoutId) { 
      TextView txtDescription = new TextView(LaunchingActivity.this); 
      EditText edtDescription = new EditText(LaunchingActivity.this); 
      ImageView imgaddDescription = new ImageView(LaunchingActivity.this); 
      edtDescription.setInputType(262144); 
      RelativeLayout relLay = new RelativeLayout(LaunchingActivity.this); 

      textViewParams(txtDescription); 
      edttxtDescriptionParams(edtDescription); 
      imageViewParams(imgaddDescription); 

      relLaySubListDescription(relLay, relLayoutId); 
      relLay.addView(txtDescription); 
      relLay.addView(edtDescription); 

      relParent.addView(relLay); 
      if (count != 0) { 
       relLay.addView(imgaddDescription); 
      } else { 
       relLay.setVisibility(View.GONE); 
      } 
      incrementIds(); 

     } 

     public void textViewParams(TextView txtDescription) { 
      txtDescription.setText("Description:"); 
      txtDescription.setTextColor(getResources().getColor(R.color.Blue)); 
      txtDescription.setId(textViewId); 
      txtDescription.setMinLines(1); 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                       android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, 
                       android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); 
      params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); 
      params.addRule(RelativeLayout.CENTER_VERTICAL); 
      txtDescription.setLayoutParams(params); 
     } 

     public void imageViewParams(ImageView addSubListDescription) { 
      addSubListDescription 
       .setImageResource(R.drawable.add_description_icon); 
      addSubListDescription.setId(ImgViewId); 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                       android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, 
                       android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); 
      params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
      params.addRule(RelativeLayout.CENTER_VERTICAL); 
      addSubListDescription.setOnTouchListener(new OnTouchListener() { 

        public boolean onTouch(View arg0, MotionEvent arg1) { 

         addDesScription(relLayParent, relLayViewId - 1); 

         return false; 
        } 
       }); 
      addSubListDescription.setLayoutParams(params); 
     } 

     public void edttxtDescriptionParams(EditText edtDescription) { 


      edtDescription.setId(edtTxtViewId); 
      edtDescription.setMinLines(1); 
      edtDescription.setHint("Description"); 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                       android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, 
                       android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); 
      params.addRule(RelativeLayout.LEFT_OF, ImgViewId); 
      params.addRule(RelativeLayout.RIGHT_OF, textViewId); 
      params.addRule(RelativeLayout.CENTER_VERTICAL); 
      edtDescription.setLayoutParams(params); 
     } 

     public void incrementIds() { 
      ImgViewId++; 
      textViewId++; 
      edtTxtViewId++; 
      relLayViewId++; 
      count++; 

     } 

     public void relLaySubListDescription(
              RelativeLayout relLaySubListDescription, int relLayoutId) { 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                       android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, 
                       android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); 

      params.width = android.widget.RelativeLayout.LayoutParams.FILL_PARENT; 
      relLaySubListDescription.setId(relLayViewId); 
      params.addRule(RelativeLayout.BELOW, relLayoutId); 
      relLaySubListDescription.setLayoutParams(params); 
     } 
    } 
} 

Antwort

0
public class LaunchingActivity extends Activity { 

    Button addSubList = null; 
    TableLayout tabLayToDoList; 
    int textViewId = StaticContents.textViewId; 
    int edtTxtViewId = StaticContents.edtTxtViewId; 
    int ImgViewId = StaticContents.ImgViewId; 
    int relLayViewId = StaticContents.relLayViewId; 
    int count = StaticContents.count; 
    CustomDialog share; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 
     System.out.println(textViewId + " " + edtTxtViewId + " " + ImgViewId 
       + " " + relLayViewId); 
     addSubList = (Button) findViewById(R.id.btnAddSubItem); 
     tabLayToDoList = (TableLayout) findViewById(R.id.tabLayToDoList); 

    } 

    public void showSublistDialog() { 
     Dialog subList = new Dialog(this); 
     Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) 
       .getDefaultDisplay(); 
     int width = display.getWidth(); 
     int height = display.getHeight(); 
     System.out.println("Display Width and Height :" + "width " + width 
       + " height " + height); 
     subList.show(); 

     // rel.setLayoutParams(layoutPrams); 
    } 
@Override 
protected void onPostResume() { 
     addSubList.setOnClickListener(new OnClickListener() { 

     public void onClick(View arg0) { 
      count = 0; 
      share = new CustomDialog(LaunchingActivity.this); 
      share.show(); 

     } 
    }); 

    super.onPostResume(); 
} 
    private class CustomDialog extends Dialog { 

     public CustomDialog(Context context) { 
      super(context); 
      // TODO Auto-generated constructor stub 
     } 

     RelativeLayout relLayParent; 

     @Override 
     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.addsubitem); 

      Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)) 
        .getDefaultDisplay(); 
      int width = display.getWidth(); 
      int height = display.getHeight(); 

      LayoutParams params = getWindow().getAttributes(); 
      if(height>width){ 
      //potrait mode 
       params.height = height - 150; 
       params.width = width-60; 
      }else{ 
       params.height = height - 100; 
       params.width = width-100; 
      } 

      getWindow().setAttributes(
        (android.view.WindowManager.LayoutParams) params); 

      relLayParent = (RelativeLayout) findViewById(R.id.relLayParent); 
      addDesScription(relLayParent, R.id.relLaySubListContent); 
      addDesScription(relLayParent, R.id.relLaySubListContent); 

     } 

     public void addDesScription(RelativeLayout relParent, int relLayoutId) { 
      TextView txtDescription = new TextView(LaunchingActivity.this); 
      EditText edtDescription = new EditText(LaunchingActivity.this); 
      ImageView imgaddDescription = new ImageView(LaunchingActivity.this); 
      edtDescription.setInputType(262144); 
      RelativeLayout relLay = new RelativeLayout(LaunchingActivity.this); 

      textViewParams(txtDescription); 
      edttxtDescriptionParams(edtDescription); 
      imageViewParams(imgaddDescription); 

      relLaySubListDescription(relLay, relLayoutId); 
      relLay.addView(txtDescription); 
      relLay.addView(edtDescription); 

      relParent.addView(relLay); 
      if (count != 0) { 
       relLay.addView(imgaddDescription); 
      } else { 
       relLay.setVisibility(View.GONE); 
      } 
      incrementIds(); 

     } 

     public void textViewParams(TextView txtDescription) { 
      txtDescription.setText("Description:"); 
      txtDescription.setTextColor(getResources().getColor(R.color.Blue)); 
      txtDescription.setId(textViewId); 
      txtDescription.setMinLines(1); 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
        android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, 
        android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); 
      params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); 
      params.addRule(RelativeLayout.CENTER_VERTICAL); 
      txtDescription.setLayoutParams(params); 
     } 

     public void imageViewParams(ImageView addSubListDescription) { 
      addSubListDescription 
        .setImageResource(R.drawable.add_description_icon); 
      addSubListDescription.setId(ImgViewId); 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
        android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, 
        android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); 
      params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 
      params.addRule(RelativeLayout.CENTER_VERTICAL); 
      addSubListDescription.setOnTouchListener(new OnTouchListener() { 

       public boolean onTouch(View arg0, MotionEvent arg1) { 

        addDesScription(relLayParent, relLayViewId - 1); 

        return false; 
       } 
      }); 
      addSubListDescription.setLayoutParams(params); 
     } 

     public void edttxtDescriptionParams(EditText edtDescription) { 


      edtDescription.setId(edtTxtViewId); 
      edtDescription.setMinLines(1); 
      edtDescription.setHint("Description"); 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
        android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, 
        android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); 
      params.addRule(RelativeLayout.LEFT_OF, ImgViewId); 
      params.addRule(RelativeLayout.RIGHT_OF, textViewId); 
      params.addRule(RelativeLayout.CENTER_VERTICAL); 
      edtDescription.setLayoutParams(params); 
     } 

     public void incrementIds() { 
      ImgViewId++; 
      textViewId++; 
      edtTxtViewId++; 
      relLayViewId++; 
      count++; 

     } 

     public void relLaySubListDescription(
       RelativeLayout relLaySubListDescription, int relLayoutId) { 
      RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
        android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT, 
        android.widget.RelativeLayout.LayoutParams.WRAP_CONTENT); 

      params.width = android.widget.RelativeLayout.LayoutParams.FILL_PARENT; 
      relLaySubListDescription.setId(relLayViewId); 
      params.addRule(RelativeLayout.BELOW, relLayoutId); 
      relLaySubListDescription.setLayoutParams(params); 
     } 
    } 

} 
Verwandte Themen