5666

package com.example.funlearn0566;

import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

    EditText Name,Class;

    @SuppressLint(“MissingInflatedId”)
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Name = findViewById(R.id.nameBox);
        Class = findViewById(R.id.classBox);

        GridLayout gridLayoutImages = findViewById(R.id.gridLayoutImages);

        // Add your images and text tags dynamically to gridLayoutImages

        // Example of adding an ImageView dynamically
        ImageView imageView = new ImageView(this);
        imageView.setImageResource(R.drawable.apple); // Set your image resource
        imageView.setTag(“Apple”); // Set the tag for the image
        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onImageClick((String) view.getTag());
            }
        });
        gridLayoutImages.addView(imageView);

        // Add more images and text tags similarly

    }

    public void onImageClick(String selectedTagName) {
        Intent intent = new Intent(this, MainActivity2.class);
        intent.putExtra(“selectedTagName”, selectedTagName);
        startActivityForResult(intent, 1);
    }

    // You can override onActivityResult if you want to handle results from ChildDetailsActivity
}

Scroll to Top