Attendence management grid layout and spinner (Java & xml)
Activity_main.xml Mainactivity.java package com.example.gridlayoutspinner; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.Spinner; import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { String[] attendanceOptions = {"Present", "Absent", "Late"}; EditText editTextName1, editTextName2; Spinner spinner1, spinner2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Initialize EditTexts editTextName1 = findViewById(R.id.editTextName1); editTextName2 = findViewById(R.id.editTextName2); // Initialize Spinners spinner1 = findViewById(R.id.spinner1); spinner2 = findViewById(R.id.spinner2); // Set Adapter for Spinners ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_dropdown_item, attendanceOptions); spinner1.setAdapter(adapter); spinner2.setAdapter(adapter); // Handle selection events spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { String studentName = editTextName1.getText().toString(); Toast.makeText(MainActivity.this, studentName + " is " + attendanceOptions[position], Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView parent) {} }); spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView parent, View view, int position, long id) { String studentName = editTextName2.getText().toString(); Toast.makeText(MainActivity.this, studentName + " is " + attendanceOptions[position], Toast.LENGTH_SHORT).show(); } @Override public void onNothingSelected(AdapterView parent) {} }); } }

Activity_main.xml
Mainactivity.java
package com.example.gridlayoutspinner;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
String[] attendanceOptions = {"Present", "Absent", "Late"};
EditText editTextName1, editTextName2;
Spinner spinner1, spinner2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize EditTexts
editTextName1 = findViewById(R.id.editTextName1);
editTextName2 = findViewById(R.id.editTextName2);
// Initialize Spinners
spinner1 = findViewById(R.id.spinner1);
spinner2 = findViewById(R.id.spinner2);
// Set Adapter for Spinners
ArrayAdapter adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_dropdown_item, attendanceOptions);
spinner1.setAdapter(adapter);
spinner2.setAdapter(adapter);
// Handle selection events
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
String studentName = editTextName1.getText().toString();
Toast.makeText(MainActivity.this, studentName + " is " + attendanceOptions[position], Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView> parent) {}
});
spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView> parent, View view, int position, long id) {
String studentName = editTextName2.getText().toString();
Toast.makeText(MainActivity.this, studentName + " is " + attendanceOptions[position], Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView> parent) {}
});
}
}