Payment activity xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/etCardNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Card Number"
android:inputType="number" />
<EditText
android:id="@+id/etCardHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Card Holder Name" />
<EditText
android:id="@+id/etExpiry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="MM/YY" />
<EditText
android:id="@+id/etCVV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="CVV"
android:inputType="numberPassword" />
<Button
android:id="@+id/btnPay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Pay Now"
android:layout_marginTop="20dp" />
</LinearLayout>
Payment Activity Java
package com.example.paymentapp;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class PaymentActivity extends AppCompatActivity {
EditText etCardNumber, etCardHolder, etExpiry, etCVV;
Button btnPay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_payment);
etCardNumber = findViewById(R.id.etCardNumber);
etCardHolder = findViewById(R.id.etCardHolder);
etExpiry = findViewById(R.id.etExpiry);
etCVV = findViewById(R.id.etCVV);
btnPay = findViewById(R.id.btnPay);
btnPay.setOnClickListener(v -> {
String cardNumber = etCardNumber.getText().toString().trim();
String cardHolder = etCardHolder.getText().toString().trim();
String expiry = etExpiry.getText().toString().trim();
String cvv = etCVV.getText().toString().trim();
if (cardNumber.isEmpty() || cardHolder.isEmpty()
|| expiry.isEmpty() || cvv.isEmpty()) {
Toast.makeText(this,
"Please fill all fields",
Toast.LENGTH_SHORT).show();
} else {
// Call your payment gateway API here
Toast.makeText(this,
"Payment Processing...",
Toast.LENGTH_SHORT).show();
}
});
}
}
