User can hit enter to send a comment

This commit is contained in:
Pierre 2018-05-07 17:32:56 +02:00
parent 120872a131
commit a7e812b8e5
2 changed files with 17 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.view.KeyEvent;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@ -243,6 +244,21 @@ public class PostsAdapter extends ArrayAdapter<Post>{
} }
}); });
//Make the comment input behaves like the send button when the user hit the
//enter key
input_comment.setOnKeyListener(new View.OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN
&& keyCode == KeyEvent.KEYCODE_ENTER){
sendComment(position, finalConvertView);
}
return false;
}
});
} }
} }

View File

@ -115,7 +115,7 @@
android:layout_weight="1" android:layout_weight="1"
style="@style/TextAppearance.AppCompat" style="@style/TextAppearance.AppCompat"
android:hint="@string/new_comment_hint" android:hint="@string/new_comment_hint"
android:inputType="textMultiLine" /> android:inputType="text" />
<ImageView <ImageView
android:id="@+id/comment_send_button" android:id="@+id/comment_send_button"