//Student Details
//Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/student_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Student Name"
android:layout_margin="16dp"/>
<EditText
android:id="@+id/student_age"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Student Age"
android:layout_below="@id/student_name"
android:layout_margin="16dp"/>
<EditText
android:id="@+id/student_grade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Student Grade"
android:layout_below="@id/student_age"
android:layout_margin="16dp"/>
<Button
android:id="@+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_below="@id/student_grade"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"/>
</RelativeLayout>
//[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
private EditText studentName;
private EditText studentAge;
private EditText studentGrade;
private Button submitButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
studentName = (EditText) findViewById([Link].student_name);
studentAge = (EditText) findViewById([Link].student_age);
studentGrade = (EditText) findViewById([Link].student_grade);
submitButton = (Button) findViewById([Link].submit_button);
[Link](new [Link]() {
@Override
public void onClick(View v) {
String name = [Link]().toString();
String age = [Link]().toString();
String grade = [Link]().toString();
String message = "Name: " + name + "\nAge: " + age + "\nGrade: " + grade;
[Link]([Link], message, Toast.LENGTH_LONG).show();
});
}
// Hello with Text Message
//Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<EditText
android:id="@+id/student_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Student Name"
android:layout_margin="16dp"/>
<Button
android:id="@+id/submit_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_below="@id/student_name"
android:layout_centerHorizontal="true"
android:layout_margin="16dp"/>
</RelativeLayout>
//[Link]
package [Link].hello2;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
private EditText studentName;
private Button submitButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
studentName = (EditText)findViewById([Link].student_name);
submitButton = (Button)findViewById([Link].submit_button);
[Link](new [Link]() {
@Override
public void onClick(View v) {
String name = [Link]().toString();
String message = "Hello" + name;
[Link]([Link], message, Toast.LENGTH_LONG).show();
});
}
//Login Details
//Activity_main.xml
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="78dp"
android:text="MyLogin Form"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="35dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="18dp"
android:layout_marginTop="39dp"
android:text="User name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20dp" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:layout_marginTop="42dp"
android:text="Password"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20dp" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView2"
android:ems="10" >
<requestFocus />
</EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:ems="10"
android:inputType="textPassword" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_centerHorizontal="true"
android:text="Login" />
</RelativeLayout>
//[Link]
package [Link].intro2;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity {
Button b;
EditText u,p;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
u=(EditText)findViewById([Link].editText1);
p=(EditText)findViewById([Link].editText2);
b=(Button)findViewById([Link].button1);
[Link](new OnClickListener() {
@Override
public void onClick(View v) {
if([Link]().toString().equals("mohan")&&([Link]().toString().equals("12345678
")))
[Link]([Link],"User name and
password are valid",Toast.LENGTH_LONG).show();
else
[Link]([Link],"User name and
password are invalid",Toast.LENGTH_LONG).show();
});
}
XML PROGRAM:
<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="19dp"
android:layout_marginTop="38dp"
android:text="Enter A:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView1"
android:layout_marginLeft="36dp"
android:layout_toRightOf="@+id/textView1"
android:ems="10"
android:inputType="number" >
<requestFocus />
</EditText>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_marginTop="25dp"
android:layout_toLeftOf="@+id/editText1"
android:text="Enter B:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/textView2"
android:layout_alignLeft="@+id/editText1"
android:ems="10"
android:inputType="number" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/button1"
android:layout_alignRight="@+id/editText2"
android:layout_marginRight="38dp"
android:text="SUB" />
<Button
android:id="@+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/button3"
android:layout_alignBottom="@+id/button3"
android:layout_alignLeft="@+id/button2"
android:text="DIV" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/button4"
android:layout_marginLeft="18dp"
android:layout_marginTop="100dp"
android:layout_toRightOf="@+id/button3"
android:text="Result"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/button3"
android:layout_below="@+id/textView2"
android:layout_marginTop="48dp"
android:text="ADD" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/button1"
android:layout_marginTop="36dp"
android:text="MUL" />
<Button
android:id="@+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/button3"
android:layout_marginTop="50dp"
android:text="MODULO DIVISION" />
</RelativeLayout>
JAVA PROGRAM:
package [Link].windowsapplication105;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText num1,num2;
Button add,sub,mul,div,mod;
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
num1=(EditText)findViewById([Link].editText1);
num2=(EditText)findViewById([Link].editText2);
result=(TextView)findViewById([Link].textView3);
add=(Button)findViewById([Link].button1);
sub=(Button)findViewById([Link].button2);
mul=(Button)findViewById([Link].button3);
div=(Button)findViewById([Link].button4);
mod=(Button)findViewById([Link].button5);
//1 ADDITION BUTTON
[Link](new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Integer
number1=[Link]([Link]().toString());
Integer
number2=[Link]([Link]().toString());
Integer sum=number1+number2;
[Link]([Link](sum));
}
});
//2 SUBTRACTION BUTTON
[Link](new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Integer
number1=[Link]([Link]().toString());
Integer number2=[Link]([Link]().toString());
Integer sub=number1-number2;
[Link]([Link](sub));
}
});
//3 MULTIPLICATION BUTTON
[Link](new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Integer
number1=[Link]([Link]().toString());
Integer
number2=[Link]([Link]().toString());
Integer mul=number1*number2;
[Link]([Link](mul));
}
});
//4 DIVISON BUTTON
[Link](new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Integer
number1=[Link]([Link]().toString());
Integer
number2=[Link]([Link]().toString());
Integer div=number1/number2;
[Link]([Link](div));
}
});
[Link](new OnClickListener() {
@Override
public void onClick(View v) {
Integer
number1=[Link]([Link]().toString());
Integer
number2=[Link]([Link]().toString());
Integer mod=number1%number2;
[Link]([Link](mod));
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is
present.
getMenuInflater().inflate([Link].
material_motion_duration_long_1,menu);
return true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="[Link]
droid"
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="105dp"
android:text="Java" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkBox1"
android:layout_below="@+id/checkBox1"
android:layout_marginTop="23dp"
android:text="Python" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/checkBox2"
android:layout_below="@+id/checkBox2"
android:layout_marginTop="30dp"
android:text="C language" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="44dp"
android:text="Choose Languages Known"
android:textAppearance="?android:attr/textAppearance
Large"
android:textSize="20dp" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/checkBox3"
android:layout_centerHorizontal="true"
android:layout_marginTop="18dp"
android:text="Ok" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/button1"
android:layout_marginTop="36dp"
android:text=""
android:textSize="20dp" />
</RelativeLayout>
// activity_main.java
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
CheckBox c1, c2, c3;
Button b;
TextView result;
StringBuffer sb;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
c1 = (CheckBox) findViewById([Link].checkBox1);
c2 = (CheckBox) findViewById([Link].checkBox2);
c3 = (CheckBox) findViewById([Link].checkBox3);
result = (TextView) findViewById([Link].textView2);
b = (Button) findViewById([Link].button1);
[Link](new OnClickListener() {
@Override
public void onClick(View v) {
sb = new StringBuffer();
[Link]("Languages Knowned: ");
if ([Link]()) {
[Link]([Link]().toString());
[Link](", ");
}
if ([Link]()) {
[Link]([Link]().toString());
[Link](", ");
}
if ([Link]()) {
[Link]([Link]().toString());
[Link](", ");
}
[Link](sb);
sb = null;
}
});
}
}
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<Button
android:id="@+id/btn_set_wallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Set Wallpaper" />
<Button
android:id="@+id/btn_change_wallpaper"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Change Wallpaper Every 30 secs" />
<ImageView
android:id="@+id/image_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private Button btnSetWallpaper, btnChangeWallpaper;
private ImageView imageView;
private WallpaperManager wallpaperManager;
private Handler handler;
private Random random;
private int[] imageResources = {[Link].flower1, [Link].flower2,
[Link].flower3};
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
btnSetWallpaper = findViewById([Link].btn_set_wallpaper);
btnChangeWallpaper = findViewById([Link].btn_change_wallpaper);
imageView = findViewById([Link].image_view);
wallpaperManager = [Link](this);
handler = new Handler();
random = new Random();
[Link](new [Link]() {
@Override
public void onClick(View v) {
setWallpaper();
}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
changeWallpaperEvery30Secs();
}
});
}
private void setWallpaper() {
Bitmap bitmap = [Link](getResources(),
imageResources[0]);
try {
[Link](bitmap);
[Link](this, "Wallpaper set", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
[Link](this, "Error setting wallpaper", Toast.LENGTH_SHORT).show();
}
}
private void changeWallpaperEvery30Secs() {
[Link](new Runnable() {
@Override
public void run() {
int randomImage = imageResources[[Link]([Link])];
Bitmap bitmap = [Link](getResources(),
randomImage);
try {
[Link](bitmap);
[Link](this, 30000); // 30 seconds
} catch (IOException e) {
[Link]([Link], "Error setting wallpaper",
Toast.LENGTH_SHORT).show();
}
}
}, 30000); // 30 seconds
}
}
[Link]
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
xmlns:tools="[Link]
<uses-permission
android:name="[Link].SET_WALLPAPER" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/[Link]">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="(link unavailable)"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/recipient_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Recipient Number"
android:inputType="phone" />
<EditText
android:id="@+id/message_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Message Body"
android:inputType="textMultiLine" />
<Button
android:id="@+id/send_sms"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send SMS" />
</LinearLayout>
Activity Code:
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private EditText recipientNumber;
private EditText messageBody;
private Button sendSms;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
recipientNumber = findViewById([Link].recipient_number);
messageBody = findViewById([Link].message_body);
sendSms = findViewById([Link].send_sms);
[Link](new [Link]() {
@Override
public void onClick(View v) {
sendSmsIntent();
}); }
private void sendSmsIntent() {
String recipient = [Link]().toString();
String message = [Link]().toString();
Intent intent = new Intent(Intent.ACTION_VIEW);
[Link]([Link]("[Link] + recipient));
[Link]("sms_body", message);
if ([Link](getPackageManager()) != null) {
startActivity(intent);
}}
[Link]:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="(link unavailable)"
package="[Link]">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity></application>
</manifest>
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
public class DatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "user_registration.db";
private static final String TABLE_NAME = "users";
private static final String COL1 = "id";
private static final String COL2 = "name";
private static final String COL3 = "email";
private static final String COL4 = "password";
public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
@Override
public void onCreate(SQLiteDatabase db) {
String createTable = "CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY
AUTOINCREMENT, " +
COL2 + " TEXT, " + COL3 + " TEXT, " + COL4 + " TEXT)";
[Link](createTable);
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
[Link]("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
public boolean addUser(String name, String email, String password) {
SQLiteDatabase db = [Link]();
ContentValues contentValues = new ContentValues();
[Link](COL2, name);
[Link](COL3, email);
[Link](COL4, password);
long result = [Link](TABLE_NAME, null, contentValues);
return result != -1;
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class RegistrationActivity extends AppCompatActivity {
private EditText nameEditText, emailEditText, passwordEditText;
private Button registerButton;
private DatabaseHelper databaseHelper;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_registration);
nameEditText = findViewById([Link].name_edit_text);
emailEditText = findViewById([Link].email_edit_text);
passwordEditText = findViewById([Link].password_edit_text);
registerButton = findViewById([Link].register_button);
databaseHelper = new DatabaseHelper(this);
[Link](new [Link]() {
@Override
public void onClick(View v) {
String name = [Link]().toString();
String email = [Link]().toString();
String password = [Link]().toString();
if ([Link]() || [Link]() || [Link]()) {
[Link]([Link], "Please fill all fields",
Toast.LENGTH_SHORT).show();
} else {
if ([Link](name, email, password)) {
[Link]([Link], "Registration successful",
Toast.LENGTH_SHORT).show();
} else {
[Link]([Link], "Registration failed",
Toast.LENGTH_SHORT).show();
});
//activity_registration.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="(link unavailable)"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">
<EditText
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:inputType="textCapWords" />
<EditText
android:id="@+id/email_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email"
android:inputType="textEmailAddress" />
<EditText
android:id="@+id/password_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/register_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Register" />
</LinearLayout>
[Link]
<uses-permission android:name="[Link].WRITE_EXTERNAL_STORAGE" />
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="24dp"
android:gravity="center"
tools:context=".MainActivity">
<!-- Optional label -->
<TextView
android:id="@+id/textLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enter text to speak:"
android:textSize="18sp"
android:layout_marginBottom="16dp"/>
<!-- EditText for user input -->
<EditText
android:id="@+id/inputText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type something..."
android:textSize="16sp"
android:inputType="textMultiLine"
android:minLines="3"
android:gravity="top|start"
android:padding="12dp"
android:background="@android:drawable/edit_text"/>
<!-- Button to trigger Text-to-Speech -->
<Button
android:id="@+id/speakButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Speak"
android:layout_marginTop="24dp"/>
</LinearLayout>
//activity_main.java
package [Link];
import static [Link].R.*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
private TextToSpeech textToSpeech;
private EditText inputText;
private Button speakButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
[Link](this);
setContentView([Link].activity_main);
inputText = findViewById([Link]);
speakButton = findViewById([Link]);
// Initialize the TextToSpeech object
textToSpeech = new TextToSpeech(this, new OnInitListener() {
@Override
public void onInit(int status) {
if (status == [Link]) {
int langResult = [Link]([Link]);
if (langResult == TextToSpeech.LANG_MISSING_DATA || langResult ==
TextToSpeech.LANG_NOT_SUPPORTED) {
[Link]([Link], "Language not supported or missing data.",
Toast.LENGTH_SHORT).show();
} else {
[Link]([Link], "Text-to-Speech Initialized",
Toast.LENGTH_SHORT).show();
} else {
[Link]([Link], "Text-to-Speech Initialization Failed",
Toast.LENGTH_SHORT).show();
}
});
// Set onClick listener for the speak button
[Link](view -> speakText());
private void speakText() {
String text = [Link]().toString();
if ([Link]()) {
[Link](this, "Please enter text to speak", Toast.LENGTH_SHORT).show();
} else {
// Use the TextToSpeech object to speak the text
[Link](text, TextToSpeech.QUEUE_FLUSH, null, null);
@Override
protected void onDestroy() {
if (textToSpeech != null) {
[Link]();
[Link]();
[Link]();