2012-11-05 138 views
0

當我動態地添加一個按鈕的幀結構被禁用。這很好。當我將EditText對象添加到相同的框架佈局時,似乎可以單擊該按鈕的功能似乎停止。的Android添加動態按鈕,點擊添加的EditText

任何人可以幫助我。這裏是我的代碼: -

FrameLayout reportLayout = (FrameLayout) findViewById(R.id.reportDetailLayout); 

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
      LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 

    Button executeButton = new Button(this); 

    executeButton.setClickable(true); 

    executeButton.setOnClickListener(handleOnClick(executeButton)); 

    EditText text1 = new EditText(this); 

    executeButton.setText("Execute"); 
    executeButton.setMinimumHeight(10); 
    executeButton.setMinimumWidth(150); 

    text1.setId(1); 
    text1.setHint("Enter Value"); 

    executeButton.setPadding(0, 0, 0, 0); 
    text1.setPadding(12, 70, 0, 0); 

    executeButton.setLayoutParams(params); 
    text1.setLayoutParams(params); 

    reportLayout.addView(executeButton); 
    reportLayout.addView(text1); 

感謝

馬丁

回答

0

您編輯文本是你的按鈕上。觸摸事件只能點擊編輯文本區域。 你改變按鈕或編輯文本的位置,我認爲這個問題將解決。

+0

我如何可以改變編輯文字的位置。那是用填充方法。 。 –

+0

例如移動的EditText'((FrameLayout.LayoutParams)text1.getLayoutParams())LEFTMARGIN = executeButton.getWidth()+ 10;'(如果getWidth()返回0你應該改變它像這樣)'((FrameLayout.LayoutParams )text1.getLayoutParams())。leftMargin = 160;'(160和+10是我的假設,你可以改變他們你想要的)。 –

0

它需要可以是Linear佈局。