Added enter send message and login for andriod feilds

This commit is contained in:
Alex
2026-04-04 16:54:29 -06:00
parent 1043ac096f
commit 313ec4a57b
4 changed files with 23 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ package com.example.petstoremobile.activities;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.view.inputmethod.EditorInfo;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView; import android.widget.TextView;
@@ -69,6 +70,15 @@ public class MainActivity extends AppCompatActivity {
//clear login status //clear login status
tvLoginStatus.setText(""); tvLoginStatus.setText("");
// Set editor action listener for password field to login on when enter is pressed
etPassword.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_DONE || actionId == EditorInfo.IME_NULL) {
btnLogin.performClick();
return true;
}
return false;
});
//Set click listener for login button //Set click listener for login button
btnLogin.setOnClickListener(v -> { btnLogin.setOnClickListener(v -> {
//Get username and password from text fields //Get username and password from text fields

View File

@@ -8,6 +8,7 @@ import android.os.Bundle;
import android.provider.OpenableColumns; import android.provider.OpenableColumns;
import android.util.Log; import android.util.Log;
import android.view.*; import android.view.*;
import android.view.inputmethod.EditorInfo;
import android.widget.*; import android.widget.*;
import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts; import androidx.activity.result.contract.ActivityResultContracts;
@@ -121,6 +122,16 @@ public class ChatFragment extends Fragment implements ChatAdapter.OnChatClickLis
ImageButton hamburger = view.findViewById(R.id.btnHamburger); ImageButton hamburger = view.findViewById(R.id.btnHamburger);
hamburger.setOnClickListener(v -> drawerLayout.openDrawer(GravityCompat.START)); hamburger.setOnClickListener(v -> drawerLayout.openDrawer(GravityCompat.START));
// Set editor action listener for message field to send when enter is pressed
etMessage.setOnEditorActionListener((v, actionId, event) -> {
if (actionId == EditorInfo.IME_ACTION_SEND || actionId == EditorInfo.IME_NULL) {
btnSend.performClick();
return true;
}
return false;
});
//When the send button is clicked check if there is an attachment and send using the correct helper function //When the send button is clicked check if there is an attachment and send using the correct helper function
btnSend.setOnClickListener(v -> { btnSend.setOnClickListener(v -> {
if (pendingAttachmentUri != null) { if (pendingAttachmentUri != null) {

View File

@@ -96,6 +96,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:hint="Enter password" android:hint="Enter password"
android:inputType="textPassword" android:inputType="textPassword"
android:imeOptions="actionDone"
android:layout_marginBottom="24dp" android:layout_marginBottom="24dp"
android:textColor="@color/text_dark"/> android:textColor="@color/text_dark"/>

View File

@@ -109,6 +109,7 @@
android:layout_weight="1" android:layout_weight="1"
android:hint="Type a message..." android:hint="Type a message..."
android:inputType="text" android:inputType="text"
android:imeOptions="actionSend"
android:layout_marginEnd="8dp" android:layout_marginEnd="8dp"
android:textColor="@color/text_dark"/> android:textColor="@color/text_dark"/>