2016-03-02 48 views
5

我正在使用materialdatetime选择器来创建表单。如果我使用的是TextView,但它运行良好,但我想为它使用EditText,我正在上传图像,您可以看到如果我使用EditText的外观以及是否使用TextView的外观。但是使用EditText我需要点击两次以打开DatePicker。首先点击它的行为就像一个可编辑的文本框。如何使用EditText代替TextView并在单击中打开datePicker?

<!-- Adding Payment Method progress --> 
    <ProgressBar 
     android:id="@+id/payment_method_progress" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="8dp" 
     android:visibility="gone" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/adding_payment_method_heading" 
     android:textSize="@dimen/activity_heading" 
     android:elevation="0dp" 
     android:layout_marginBottom="@dimen/activity_vertical_margin" 
     /> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/adding_payment_method_description" 
     android:textSize="@dimen/activity_description" 
     android:elevation="0dp" 
     android:layout_marginBottom="@dimen/activity_vertical_margin" 
     /> 

    <ScrollView 
     android:id="@+id/adding_payment_method_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 

     <LinearLayout 
      android:id="@+id/adding_payment_method_layout" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:orientation="vertical"> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/layout_user_id" 
       > 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/enter_user_name" 
        android:inputType="text" 
        android:maxLines="1" 
        android:singleLine="true" 
        android:id="@+id/user_id" /> 
      </android.support.design.widget.TextInputLayout> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="horizontal"> 

       <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="left" 
        android:layout_weight="1" 
        android:text="Select Payment Methods" /> 

       <Spinner 
        android:id="@+id/payment_methods" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:layout_gravity="right" 
        android:layout_weight="1" /> 
      </LinearLayout> 
      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:orientation="vertical" 
       android:id="@+id/check_chosen" 
       > 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/layout_amount" 
       > 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/amount" 
        android:inputType="numberDecimal" 
        android:maxLines="1" 
        android:singleLine="true" 
        android:id="@+id/amount" /> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/layout_check_number" 
       > 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/check_number" 
        android:inputType="number" 
        android:maxLines="1" 
        android:singleLine="true" 
        android:id="@+id/check_number" /> 
      </android.support.design.widget.TextInputLayout> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/layout_bank_name" 
       > 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/bank_name" 
        android:inputType="text" 
        android:maxLines="1" 
        android:singleLine="true" 
        android:id="@+id/bank_name" /> 
      </android.support.design.widget.TextInputLayout> 


       <android.support.design.widget.TextInputLayout 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/date_of_check" 
        android:layout_weight="1" 
        > 
        <EditText 
         android:layout_width="match_parent" 
         android:layout_height="wrap_content" 
         android:id="@+id/check_date" 
         android:hint="Date" 
         android:inputType="date" /> 
       </android.support.design.widget.TextInputLayout> 
      </LinearLayout> 

      <android.support.design.widget.TextInputLayout 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/layout_payment_info" 
       > 

       <EditText 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:hint="@string/payment_info" 
        android:inputType="text" 
        android:maxLines="1" 
        android:singleLine="true" 
        android:id="@+id/payment_info" /> 
      </android.support.design.widget.TextInputLayout> 

       <TextView 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:id="@+id/payment_date" 
        android:hint="@string/payment_date" 
        android:inputType="date" /> 

      <Button 
       android:id="@+id/add_payment_method_action" 
       style="?android:textAppearanceSmall" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="16dp" 
       android:text="@string/submit" 
       android:onClick="testSubmit" 
       android:textStyle="bold" /> 


    </LinearLayout> 
    </ScrollView> 
</LinearLayout> 

enter image description here

请让我知道,如果我需要在这里发布的Java代码。

+0

让你的EditText点击虚假和的onclick设置监听到它。这会帮助你。试着让我知道 –

+0

刚编辑它并添加'android:focusableInTouchMode =“false”'让我测试一下,之后我也会用你的建议,非常感谢你回复我。 –

+0

@RakshitNawani'android:focusableInTouchMode =“false”'解决了我的问题。 –

回答

8

android:focusable="false" 
android:focusableInTouchMode="false" 

在编辑文本

+0

好的,我没有使用'android:focusable =“false”'并且在你的回答编辑并添加'android:focusableInTouchMode =“false”'之前它运行正常,反正非常感谢你。请你让我知道,如果我的xml是错误的,因为我对android过于陌生,不知道,如果我以正确的方式做。 –

+0

其他一切看起来都不错,除了id为check_chosen的linearlayout。您可以消除这种情况,因为父级布局已经具有垂直方向。 –

+0

非常感谢你Ankit :) –

3

可以使用的EditText来实现您的要求。首先做这样

EditText edTxt; 
edTxt = (TextView) row.findViewById(R.id.acti_edtTxt_date); 

您也可以从代码这样做是为了隐藏编辑这样

edTxt.setClickable(false); 

立即申请OnClickListener这个edTxt和开放的DatePicker或你想要什么。

请注意,setClickable在XML文件= “假”,你是 定义你的EditText

<EditText ... 
    android:clickable="false" 
    android:cursorVisible="false" 
    android:focusable="false" 
    android:focusableInTouchMode="false"> 

1

您可以通过它focusable false实现它。

<EditText ... 
    android:cursorVisible="false" 
    android:focusable="false" 
    android:focusableInTouchMode="false"> 
0

在你编辑短信试试这个

android:editable="false" 
android:enabled="true" 
+0

对不起,但是对于你的解决方案我得到了'错误:(182)否在'android''包中找到属性'endabled'的资源标识符,任何你能看到的方式,我已经解决了我的问题,我希望这也能对你有所帮助。 –

+0

ohh ...对不起我的错误..其实它适用于com.wrapp.floatlabelededittext.FloatLabeledEditText – PpL

+1

你可以编辑你的答案,并描述它的工作情况和回答这个问题,我还没有投票给你,不用担心。 :) –

0

把线下方在编辑文本:

android:editable="false" 
android:focusableInTouchMode="false" 
相关问题