2011-01-13 27 views
1

ユーザー入力用の警告ダイアログ内に編集テキストがあります。しかし、編集テキストをクリックすると、ソフトキーボードは表示されません。アラートダイアログ内のテキスト編集Androidのソフトキーボードが表示されない

ダイアログ内に同じ編集テキストを配置すると、編集テキストがフォーカスされているときにキーボードが表示されます。

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); 
     } 
    } 
} 

答えて

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); 
     } 
    } 

} 
関連する問題