2017-10-31 3 views
1

を含め使用している場合:キーボードの横のボタン私は、次の質問をしようとした/見てきましたが、私のは同じではありませんタグ


まず、私が持っていますa CardViewここで私はEditTextを持っています。

<RelativeLayout 
    android:id="@+id/topCard" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/myCard" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"   
     android:clickable="false" 
     android:foreground="?android:attr/selectableItemBackground" 
     android:orientation="horizontal" 
     app:cardCornerRadius="5dp" 
     app:cardElevation="3dp" 
     app:cardPreventCornerOverlap="false" 
     app:cardUseCompatPadding="true"> 

     <RelativeLayout 
      android:layout_width="5dp" 
      android:layout_height="match_parent" 
      android:background="#26c2ef"> 

     </RelativeLayout> 


     <RelativeLayout 
      android:id="@+id/cardTopTitle" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:layout_marginBottom="10dp" 
      android:layout_marginTop="5dp"> 


      <TextView 
       android:id="@+id/lessonTitleHeading" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="10dp" 
       android:layout_marginStart="10dp" 
       android:layout_marginTop="10dp" 
       android:text="Please provide a name:" 
       android:textColor="#000000" 
       android:textSize="18sp" /> 

      <ImageView 
       android:id="@+id/horiLine" 
       android:layout_width="match_parent" 
       android:layout_height="1dp" 
       android:layout_below="@+id/lessonTitleHeading" 
       android:layout_marginEnd="10dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginStart="10dp" 
       android:background="#60000000" /> 

      <EditText 
       android:id="@+id/noteEditText" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="@+id/horiLine" 
       android:layout_marginEnd="10dp" 
       android:layout_marginLeft="10dp" 
       android:layout_marginRight="10dp" 
       android:layout_marginStart="10dp" 
       android:layout_marginTop="5dp" 
       android:background="@android:color/transparent" 
       android:hint="Enter name here..." 
       android:imeOptions="actionNext" /> 


     </RelativeLayout> 


    </android.support.v7.widget.CardView> 


</RelativeLayout> 

私は、このようincludeを使用して別の中でこのレイアウトを膨らま:

<include 
    android:id="@+id/lessonTitle" 
    layout="@layout/activity_notes_layout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    /> 

と私のActivityクラスで、私は次のようにします。

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_add_leason); 

    View tvOne = findViewById(R.id.tvOne); 
    View tvTwo = findViewById(R.id.tvTwo); 
    View tvThree = findViewById(R.id.tvThree); 
    View tvFour = findViewById(R.id.tvFour); 

    final TextView tvOne = (TextView)vLessonTitle.findViewById(R.id.lessonTitleHeading); 
    final EditText etOne = (EditText) vLessonTitle.findViewById(R.id.noteEditText); 

    TextView tvTwo = (TextView)vlessonProbStu.findViewById(R.id.lessonTitleHeading); 
    final EditText etTwo = (EditText) vlessonProbStu.findViewById(R.id.noteEditText); 

    TextView tvThree = (TextView)vLessonWorkedOn.findViewById(R.id.lessonTitleHeading); 
    final EditText etThree = (EditText) vLessonWorkedOn.findViewById(R.id.noteEditText); 

    TextView tvFour = (TextView)vlessonWhatStudShouldWorkOn.findViewById(R.id.lessonTitleHeading); 
    final EditText etFour = (EditText)vlessonWhatStudShouldWorkOn.findViewById(R.id.noteEditText); 

    tvOne.setText("This is the first CardView:"); 
    etOne.setHint("Enter Title Here..."); 

    tvTwo.setText("This is the second CardView:"); 
    etTwo.setHint("Enter Text Here..."); 

    tvThree.setText("This is the third CardView:"); 
    etThree.setHint("Enter Text Here..."); 

    tvFour.setText("This is the fourth CardView:"); 
    etFour.setHint("Enter Text Here..."); 

    //I tried this, but it didn't work... 
    etOne.setOnKeyListener(new View.OnKeyListener() { 

     public boolean onKey(View v, int keyCode, KeyEvent event) { 
      // If the event is a key-down event on the "enter" button 
      if ((event.getAction() == KeyEvent.ACTION_DOWN) && 
        (keyCode == KeyEvent.KEYCODE_ENTER)) 
      { 
       // Perform action on Enter key press 
       etLessonTitle.clearFocus(); 
       etLessonProbStu.requestFocus(); 
       return true; 
      } 
      return false; 
     } 
    }); 

} 

をレイアウトは次のようになります。

FinalLayout

このpoinではt CardViewの束がEditTextであり、上記のようにお互いの下にあります。キーボードの次のボタンを使用して次のCardsViewEditTextに移動します。あなたは上記の私のActivityクラスを見ている場合

は、私は次のEditText上、現在のEditTextrequestFocusからsetOnKeyListenerclearFocusを使用してみましたが、それは動作しませんでした。

どのように私はこれを達成することができますか?

+1

** 'アンドロイド設定しようとすると、あなたのEditextandroid:inputType=""を設定する必要があり、これを試してください:あなたの**' EditextにinputType = "テキスト" '**を'** –

+1

@NileshRathod LOL、ありがとう、もし私が受け入れるなら答えます。 – ClassA

答えて

1

あなたはandroid:imeOptions="actionNext"

<EditText 
    android:id="@+id/noteEditText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/horiLine" 
    android:layout_marginEnd="10dp" 
    android:layout_marginLeft="10dp" 
    android:layout_marginRight="10dp" 
    android:layout_marginStart="10dp" 
    android:layout_marginTop="5dp" 
    android:background="@android:color/transparent" 
    android:hint="Enter name here..." 
    android:inputType="text" // specifies your input type here 
    android:imeOptions="actionNext" /> 
+1

私は10分で受け入れることができます、どうもありがとうございます。 – ClassA

+0

@ClassAコードを楽しむのを喜んで承ります –

+0

私はもう1つの質問があります、それは気にしません..戻るボタンと次のボタンの両方が利用可能ですか? – ClassA

関連する問題