Set C
Set C
Create toolbar for menu you can use menifesti theme also:
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
IN MAINACTIVITY.JAVA
Toolbar t; //import androidx.appcompat.widget.Toolbar;
t=findViewById(R.id.toolbar);
setSupportActionBar(t);
</menu>
inflate() //method
In onOptionItemSelected()
All the stuff will go inside this method because we want to perform task when this option is get selected
Step 1:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text=" Customer Registration"
tools:layout_editor_absoluteX="43dp"
tools:layout_editor_absoluteY="31dp" />
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="" />
<EditText
android:id="@+id/mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:text="" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rg"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Male"
android:id="@+id/rb1"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Female"
android:id="@+id/rb2"/>
</RadioGroup>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/city"
android:entries="@array/city"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select iinasjdhasd"
android:textSize="20dp"
android:layout_marginTop="20dp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cloth"
android:id="@+id/cb1"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Electronic"
android:id="@+id/cb2"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Acce"
android:id="@+id/cb3"/>
<!-- <Button-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="Send"-->
<!-- android:id="@+id/btnSend"/>-->
</LinearLayout>
Step 2:
AlertDialog.Builder ab=new AlertDialog.Builder(MainActivity.this);
View view=getLayoutInflater().inflate(R.layout.alertbox,null);
ab.setView(view);
1.alert box building jevu chhe to pela ene bolava and kay activity ma banavi e kyo using
ab.setView(view);
Step 3:
AlertDialog a=ab.create();
a.show();
EditText ed=view.findViewById(R.id.name);
EditText Con=view.findViewById(R.id.mobile);
RadioGroup rg=view.findViewById(R.id.rg);
RadioButton rb1=view.findViewById(R.id.rb1);
RadioButton rb2=view.findViewById(R.id.rb2);
Spinner sp=view.findViewById(R.id.city);
CheckBox c1=view.findViewById(R.id.cb1);
CheckBox c2=view.findViewById(R.id.cb2);
CheckBox c3=view.findViewById(R.id.cb3);
String name=ed.getText().toString();
String num=Con.getText().toString();
String gen=new String();
if (rb1.isChecked())
{
gen="Male";
}else if (rb2.isChecked())
{
gen="Female";
}
String city=sp.getSelectedItem().toString();
StringBuilder interests = new StringBuilder();
if (c1.isChecked()) interests.append(c1.getText().toString());
if (c2.isChecked()) interests.append(c2.getText().toString());
if (c3.isChecked()) interests.append(c3.getText().toString());
Step 2: add one fragment control in mainactivity.XML file and add references
Step1:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".RegistrationFragment"
android:orientation="vertical"
>
<TextView android:id="@+id/Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"
android:id="@+id/btnSend"
android:visibility="gone"/>
</LinearLayout>
Me visibility gone use kari chhe atle ,TextView visible nai thay and runtime par ene visible kari desu
Step2
<fragment
android:id="@+id/RegistrationFragment"
android:name="com.example.self_creation.RegistrationFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/ProductFragment"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.088" />
Step3
This will create the instance of the fragment and then we will connect both wih
getSupportFragmentManager().findFragmentById(R.id.RegistrationFragment);
String data="Name:" + name + "\n Gender:" + gen + "\n City:" + city + "\n
Intrests:" + interests.toString();
}
});
use intent
all code of onOptionItemSelectItem alog with the positive button this may be have some changes but
above is true
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
AlertDialog.Builder ab=new AlertDialog.Builder(MainActivity.this);
View view=getLayoutInflater().inflate(R.layout.alertbox,null);
ab.setView(view);
EditText ed=view.findViewById(R.id.name);
EditText Con=view.findViewById(R.id.mobile);
RadioGroup rg=view.findViewById(R.id.rg);
RadioButton rb1=view.findViewById(R.id.rb1);
RadioButton rb2=view.findViewById(R.id.rb2);
Spinner sp=view.findViewById(R.id.city);
CheckBox c1=view.findViewById(R.id.cb1);
CheckBox c2=view.findViewById(R.id.cb2);
CheckBox c3=view.findViewById(R.id.cb3);
}
});
}
});
AlertDialog a=ab.create();
a.show();
return super.onOptionsItemSelected(item);
}
Step 1: create fragment and design for it and as before assing it in mainactivity.XML file
Step 2.: Create XML file of one list item means box banavanu chhe
Step 3.Create custome adapter
</FrameLayout>
Mainactivity.XMl
<fragment
android:id="@+id/ProductFragment"
android:name="com.example.self_creation.ProductFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="101dp" />
Step 2:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="148dp"
android:layout_height="174dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="46dp"
android:textSize="30dp"
android:text="TextView" />
<TextView
android:id="@+id/textView4"
android:layout_width="240dp"
android:layout_height="126dp"
android:textSize="20dp"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
Step 3:
Context context;
String []title;
String []description;
int[] imgPosition;
1.extends ArrayAdapter<String>
Ena parent ne extands karavano
2.Je values apde BOX(productlist.xml) ma lidha hoi ena array variables banavan
String[] title;
String[] description;
Int[] img;
Context context;
3.create constructor by showing error on Classname and press alt+enter
super class ma 3 vastu mokalo 1.context 2.BOX.XML no ref. 3.game te string no array(title)
LayoutInflater inflater=LayoutInflater.from(parent.getContext());
View view=inflater.inflate(R.layout.productlist,parent,false);
ImageView img=view.findViewById(R.id.imageView);
TextView titl=view.findViewById(R.id.textView3);
TextView descriptio=view.findViewById(R.id.textView4);
img.setImageResource(imgPosition[position]);
titl.setText(title[position]);
descriptio.setText(description[position]);
return view;
}
Ema pela Layoutinflater no object banavi View ma inflate karavo
Ema 3 peramiter 1.BOX.XML
2.parent
3.false
GridView gridView;
String[] title={"Abc","Abc","Abc","Abc","Abc"};
String[] description={"…”}
int[]
imgPos={R.drawable.image1,R.drawable.image1,R.drawable.image1,R.drawable.imag
e1,R.drawable.image1};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view=inflater.inflate(R.layout.fragment_product, container, false);
gridView=view.findViewById(R.id.gd);
ImageAdpater i=new
ImageAdpater(view.getContext(),imgPos,title,description);
gridView.setAdapter(i);
return view;
}
gridView ne findview by id kari setadapter kari nakhavnu
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
<fragment
android:id="@+id/RegistrationFragment"
android:name="com.example.self_creation.RegistrationFragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/ProductFragment"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.088" />
<fragment
android:id="@+id/ProductFragment"
android:name="com.example.self_creation.ProductFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="101dp" />
</LinearLayout>
Main.java
package com.example.self_creation;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
Toolbar t;
ImageView i;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main),
(v, insets) -> {
Insets systemBars =
insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right,
systemBars.bottom);
return insets;
});
t=findViewById(R.id.toolbar);
setSupportActionBar(t);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.threedotmenu,menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
AlertDialog.Builder ab=new AlertDialog.Builder(MainActivity.this);
View view=getLayoutInflater().inflate(R.layout.alertbox,null);
ab.setView(view);
EditText ed=view.findViewById(R.id.name);
EditText Con=view.findViewById(R.id.mobile);
RadioGroup rg=view.findViewById(R.id.rg);
RadioButton rb1=view.findViewById(R.id.rb1);
RadioButton rb2=view.findViewById(R.id.rb2);
Spinner sp=view.findViewById(R.id.city);
CheckBox c1=view.findViewById(R.id.cb1);
CheckBox c2=view.findViewById(R.id.cb2);
CheckBox c3=view.findViewById(R.id.cb3);
RegistrationFragment r=(RegistrationFragment)
getSupportFragmentManager().findFragmentById(R.id.RegistrationFragment);
r.update(name,num,gen,city,interests.toString());
String data="Name:" + name + "\n Gender:" + gen + "\n City:"
+ city + "\n Intrests:" + interests.toString();
r.btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i=new Intent(Intent.ACTION_SENDTO);
i.setData(Uri.parse("smsto:"+num));
i.putExtra("sms_body",data);
startActivity(i);
}
});
}
});
AlertDialog a=ab.create();
a.show();
return super.onOptionsItemSelected(item);
}
AlertBOx.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30dp"
android:text=" Customer Registration"
tools:layout_editor_absoluteX="43dp"
tools:layout_editor_absoluteY="31dp" />
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:text="" />
<EditText
android:id="@+id/mobile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:text="" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rg"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Male"
android:id="@+id/rb1"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Female"
android:id="@+id/rb2"/>
</RadioGroup>
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/city"
android:entries="@array/city"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select iinasjdhasd"
android:textSize="20dp"
android:layout_marginTop="20dp"
/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cloth"
android:id="@+id/cb1"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Electronic"
android:id="@+id/cb2"/>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Acce"
android:id="@+id/cb3"/>
<!-- <Button-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:text="Send"-->
<!-- android:id="@+id/btnSend"/>-->
</LinearLayout>
<TextView android:id="@+id/Contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<TextView android:id="@+id/Gender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<TextView android:id="@+id/City"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<TextView android:id="@+id/Interests"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"
android:id="@+id/btnSend"
android:visibility="gone"/>
</LinearLayout>
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public RegistrationFragment() {
// Required empty public constructor
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view=inflater.inflate(R.layout.fragment_registration, container,
false);
Name = view.findViewById(R.id.Name);
Contact = view.findViewById(R.id.Contact);
Gender = view.findViewById(R.id.Gender);
City = view.findViewById(R.id.City);
Interests = view.findViewById(R.id.Interests);
btn=view.findViewById(R.id.btnSend);
return view;
}
BOX.Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/imageView"
android:layout_width="148dp"
android:layout_height="174dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="46dp"
android:textSize="30dp"
android:text="TextView" />
<TextView
android:id="@+id/textView4"
android:layout_width="240dp"
android:layout_height="126dp"
android:textSize="20dp"
android:text="TextView" />
</LinearLayout>
</LinearLayout>
IMageAdapter.java
package com.example.self_creation;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
Context context;
String []title;
String []description;
int[] imgPosition;
public ImageAdpater(@NonNull Context context, int[] pos,String[]
title,String[] description) {
super(context, R.layout.productlist,title);
this.context=context;
this.description=description;
this.title=title;
this.imgPosition=pos;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull
ViewGroup parent) {
LayoutInflater inflater=LayoutInflater.from(parent.getContext());
View view=inflater.inflate(R.layout.productlist,parent,false);
ImageView img=view.findViewById(R.id.imageView);
TextView titl=view.findViewById(R.id.textView3);
TextView descriptio=view.findViewById(R.id.textView4);
img.setImageResource(imgPosition[position]);
titl.setText(title[position]);
descriptio.setText(description[position]);
return view;
}
}
SecondFragment.XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/ProductFragment"
tools:context=".ProductFragment">
</FrameLayout>
SecondFragment.java
package com.example.self_creation;
import android.os.Bundle;
import androidx.constraintlayout.helper.widget.Grid;
import androidx.fragment.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
GridView gridView;
String[] title={"Abc","Abc","Abc","Abc","Abc"};
String[] description={"Registration form contains information like
Customer Name, Contact No,\n" +
"Gender, City and Interested Shopping Area. On the click of
“Save” button,\n" +
"all the information should be displayed in the registration
fragment and that\n" +
"fragment contains one button namely","Registration form contains
information like Customer Name, Contact No,\n" +
"Gender, City and Interested Shopping Area. On the click of
“Save” button,\n" +
"all the information should be displayed in the registration
fragment and that\n" +
"fragment contains one button namely","Registration form contains
information like Customer Name, Contact No,\n" +
"Gender, City and Interested Shopping Area. On the click of
“Save” button,\n" +
"all the information should be displayed in the registration
fragment and that\n" +
"fragment contains one button namely","Registration form contains
information like Customer Name, Contact No,\n" +
"Gender, City and Interested Shopping Area. On the click of
“Save” button,\n" +
"all the information should be displayed in the registration
fragment and that\n" +
"fragment contains one button namely","Registration form contains
information like Customer Name, Contact No,\n" +
"Gender, City and Interested Shopping Area. On the click of
“Save” button,\n" +
"all the information should be displayed in the registration
fragment and that\n" +
"fragment contains one button namely","Registration form contains
information like Customer Name, Contact No,\n" +
"Gender, City and Interested Shopping Area. On the click of
“Save” button,\n" +
"all the information should be displayed in the registration
fragment and that\n" +
"fragment contains one button namely"};
int[]
imgPos={R.drawable.image1,R.drawable.image1,R.drawable.image1,R.drawable.imag
e1,R.drawable.image1};
public ProductFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view=inflater.inflate(R.layout.fragment_product, container,
false);
gridView=view.findViewById(R.id.gd);
ImageAdpater i=new
ImageAdpater(view.getContext(),imgPos,title,description);
gridView.setAdapter(i);
return view;
}
}