summer21 wireless

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ScrollView
        android:layout_alignParentTop="true"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            
<!--            Product Row-->

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">
                <ImageView
                    android:id="@+id/img_nurnobi"
                    android:src="@drawable/product_image"
                    android:layout_width="match_parent"
                    android:layout_height="120dp"
                    android:layout_weight="2"/>
                <LinearLayout
                    android:layout_margin="8dp"
                    android:layout_width="match_parent"
                    android:layout_weight="1"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Product Name"
                        android:textStyle="bold"
                        android:id="@+id/tv_nurnobi_pn"
                        android:textColor="@color/black"/>
                    <TextView
                        android:id="@+id/tv_nurnobi_pp"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Price : 350 taka"/>
                    <TextView
                        android:id="@+id/tv_nurnobi_pd"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:text="Description "/>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">
                        <EditText
                            android:id="@+id/edt_nurnobi_pc"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="3"
                            android:hint="1"
                            android:text="1"
                            android:inputType="number"/>
                        <Button
                            android:id="@+id/btn_nurnobi_pc"
                            android:layout_marginRight="5dp"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="2"
                            android:textSize="10sp"
                            android:text="Add to cart"/>
                        <Button

                            android:textSize="10sp"
                            android:layout_marginLeft="5dp"
                            android:layout_weight="2"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:onClick="ContactPage"
                            android:text="Contact"/>

                    </LinearLayout>

                </LinearLayout>
            </LinearLayout>


        </LinearLayout>
    </ScrollView>

    <androidx.cardview.widget.CardView
        android:layout_width="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_height="wrap_content">
        <LinearLayout
            android:layout_margin="8dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:onClick="profilePage"
                android:drawableTop="@drawable/ic_user"
                android:text="Profile"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableTop="@drawable/ic_cart"
                android:gravity="center"
                android:onClick="cartPage"
                android:text="Cart"/>
            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:drawableTop="@drawable/ic_product"
                android:gravity="center"
                android:onClick="productPage"
                android:text="Product"/>
            <TextView
                android:onClick="orderPage"
                android:drawableTop="@drawable/ic_order"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:gravity="center"
                android:text="Order"/>

        </LinearLayout>
    </androidx.cardview.widget.CardView>

</RelativeLayout>
package com.techzweb.midpractise;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


    EditText count;
    TextView prName,prPrice,prDesc;
    Button addCart;
    String name,price,ci;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        count = findViewById(R.id.edt_nurnobi_pc);
        prName = findViewById(R.id.tv_nurnobi_pn);
        prPrice = findViewById(R.id.tv_nurnobi_pp);
        prDesc = findViewById(R.id.tv_nurnobi_pd);
        addCart = findViewById(R.id.btn_nurnobi_pc);
        addCart.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                name= prName.getText().toString();
                price=prPrice.getText().toString();
                ci=count.getText().toString();


                AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
                alert.setCancelable(true);
                alert.setIcon(R.drawable.ic_cart);
                alert.setTitle("Do you want to add it on your cart ?");
               alert.setMessage("Product Name : "+name+"\n"+price+"\nItem : "+ci);

                        // Specifying a listener allows you to take an action before dismissing the dialog.
                        // The dialog is automatically dismissed when a dialog button is clicked.
                alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                               Toast.makeText(MainActivity.this,"Product Added!",Toast.LENGTH_LONG).show();
                               dialog.cancel();
                            }
                        });

                        // A null listener allows the button to dismiss the dialog and take no further action.
                alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                dialog.cancel();

                            }
                        });
                alert.show();


            }
        });
    }

/*    Bottom Navigation Change Activity*/
    public void orderPage(View view) {
        Toast.makeText(MainActivity.this,"Order Page Button Clicked",Toast.LENGTH_LONG).show();
    }

    public void productPage(View view) {
        Toast.makeText(MainActivity.this,"Product Page Button Clicked",Toast.LENGTH_LONG).show();
    }

    public void cartPage(View view) {
        Toast.makeText(MainActivity.this,"Cart Page Button Clicked",Toast.LENGTH_LONG).show();
    }

    public void profilePage(View view) {
        Toast.makeText(MainActivity.this,"Profile Page Button Clicked",Toast.LENGTH_LONG).show();
    }

    public void ContactPage(View view) {
        Toast.makeText(MainActivity.this,"Contact Button Clicked",Toast.LENGTH_LONG).show();
    }
}
Posted in URI Online Judge Solution