0% found this document useful (0 votes)
11 views24 pages

Set C

The document provides a detailed guide on creating a custom toolbar and menu for a registration feature in an Android application, including XML layout and Java code snippets. It explains how to implement an AlertDialog for user input, handle data submission, and display it in a fragment. Additionally, it covers creating a custom adapter for displaying a list of items in a fragment, with step-by-step instructions for each component involved.

Uploaded by

meetshimpi07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views24 pages

Set C

The document provides a detailed guide on creating a custom toolbar and menu for a registration feature in an Android application, including XML layout and Java code snippets. It explains how to implement an AlertDialog for user input, handle data submission, and display it in a fragment. Additionally, it covers creating a custom adapter for displaying a list of items in a fragment, with step-by-step instructions for each component involved.

Uploaded by

meetshimpi07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

1.

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" />

Use theme :@style.ThemeOverlay.AppCompat.Dark

IN MAINACTIVITY.JAVA
Toolbar t; //import androidx.appcompat.widget.Toolbar;
t=findViewById(R.id.toolbar);
setSupportActionBar(t);

for the Custome theme actionbar use setSupportActionBar(t);


for the tool import android.appcompat.widget.Toolbar;

2.Create menu for Registration option:

Rightclick>res>new>Derictory>name:menu>rightclick.menu>new >menu layout


file>name:threedotmenu
<menu xmlns:android="http://schemas.android.com/apk/res/android">

<item android:id="@+id/threedot" android:title="Registration"></item>

</menu>

Add items as option which you want in menu

Override 2 Methods onCreateOptionMenu and onOptionItemSelected


In onCreateOptionMenu()
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.threedotmenu,menu);
return super.onCreateOptionsMenu(menu);
}

Taking inflater to convert XML file into objects to access it;

getMenuInflater() //taking inflater driclty

inflate() //method

R.menu,threedotmenu //menu file which we want to convert

menu //referece from parent

In onOptionItemSelected()
All the stuff will go inside this method because we want to perform task when this option is get selected

Now you can see you menu

Create custom dialog box as form:

Step 1: Create layoutfile which contains alertbox form design

Step 2: Create object of alertdailog.builder and set the view by inflating

Step 3:Create AlertDailog box and show() it;

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>

Here use inputType for the validation

Step 2:
AlertDialog.Builder ab=new AlertDialog.Builder(MainActivity.this);
View view=getLayoutInflater().inflate(R.layout.alertbox,null);
ab.setView(view);

ab.setPositiveButton("save", new DialogInterface.OnClickListener() {


@Override
public void onClick(DialogInterface dialog, int which) {
}
)};

1.alert box building jevu chhe to pela ene bolava and kay activity ma banavi e kyo using

AlertDailog.Builder ab =new AlertDialog.Builder(MainActivity.this);

2.upper je xml file banavi ene objects ma conver karva

View view=getLayoutInflater().inflate(R.layout.alertbox.xml (filename),null);

3.kavi building banavani eno view builder ma set karo

ab.setView(view);
Step 3:
AlertDialog a=ab.create();
a.show();

Fatching data of alert box into variables in alertbox builder positivebtn


ab.setPositiveButton("save", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {

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());

Its in alertdialog box positive button


Show data in fragment:
Step 1: create one fragment in file drictory name RegistrationFragment design it

Step 2: add one fragment control in mainactivity.XML file and add references

Step 3: Access the contols of fragment In MainActivity.Java file

Stpe 4: on Click of positive button of alertbox ,data should be print in fragment

Step 5:on click of fragment button message should be sent;

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" />

1.id game te api devani

2.name ma suggestion pramane RegistrationFragment no use karvao

Step3

Its in positive button of alertbox:-


RegistrationFragment r=(RegistrationFragment)
getSupportFragmentManager().findFragmentById(R.id.RegistrationFragment);

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();

We concate all the data in one string

Then create one method in fragment.java file


public void update(String name){
Name.setVisibility(View.VISIBLE);
Name.setText("Name: " + name);
}

now call it under the data declaration:


r.update(data);

when this method will call it will display the data


Step 5:
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);

}
});

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);

ab.setPositiveButton("save", new DialogInterface.OnClickListener() {


@Override
public void onClick(DialogInterface dialog, int which) {
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());
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);
}

One Fragment Task is completed Good job Welcom

At the initial level it should show custome list in fragment 2

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

Step 4.acces adaper in fragment.java file of second fragment


Step 1:
<?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">

<!-- TODO: Update blank fragment layout -->


<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/gd"
/>

</FrameLayout>

You can use ListVIew as well

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:

Right Click>java folder>new >java class>name ImageAddapter


package com.example.self_creation;

public class ImageAdpater extends ArrayAdapter<String> {

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

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;
}

pela jetli value use karvana chhi ena parameter lakhavana;


jemke int[] pos,String[] title,String[] Description

super class ma 3 vastu mokalo 1.context 2.BOX.XML no ref. 3.game te string no array(title)

badha variables ne this kari ne assign kari nakhavana

4.getVIew method ne override karo


@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;
}
Ema pela Layoutinflater no object banavi View ma inflate karavo
Ema 3 peramiter 1.BOX.XML

2.parent

3.false

Ena ma aveli controls ne bind karva ImageView img=view.findViewById(R.id.imageView);


Karo

Karanke aama findview nai chale altle view mathi kari

Badhi values ne set karo and

Return view karavo super vadu kadhi ne;

Access this adapter in javafile of Second Fragment

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;

public class MainActivity extends AppCompatActivity {

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);

ab.setPositiveButton("save", new DialogInterface.OnClickListener() {


@Override
public void onClick(DialogInterface dialog, int which) {
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());

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>

registration.xml Ingnore changes


<?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"
/>

<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>

registraionFragment.java ignore changes


package com.example.self_creation;

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 class RegistrationFragment extends Fragment {

private TextView Name, Contact, Gender, City, Interests;


Button btn;

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;
}

public void update(String name, String contact, String gender, String


city, String interests){
Name.setVisibility(View.VISIBLE);
Contact.setVisibility(View.VISIBLE);
Gender.setVisibility(View.VISIBLE);
City.setVisibility(View.VISIBLE);
Interests.setVisibility(View.VISIBLE);
Name.setText("Name: " + name);
Contact.setText("Contact: " + contact);
Gender.setText("Gender: " + gender);
City.setText("City: " + city);
Interests.setText("Interests: " + interests);
btn.setVisibility(View.VISIBLE);
}
}

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;

public class ImageAdpater extends ArrayAdapter<String> {

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">

<!-- TODO: Update blank fragment layout -->


<GridView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/gd"
/>

</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;

public class ProductFragment extends Fragment {

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;
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy