This name can be in any form such as this name could have two words with spaces in between
just make sure that this is unique because if someday you decide to publish your app in app store then you'll be able to use this particular project name which has this package name
com.kibo.android=company domain+application name=package name
set by default
options available
selecting project option because simpler view, that's the first option
- app
- source
- main java- contains java file where we write the java code res- contains the resources AndroidManifest.xml- version controlling etc changing theme etc.;landscape/portrait
intent-filter: let's us know, which activity should start first
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
under resources or res, we have layout and under layout we have activity_main.xml
- java file
- xml file
- a file in xml for menu
the following are for the menus, we dont need now and hence deleting
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
now we remove AppCompatActivity and make it just Activity, this throws an error and hence we just import the package or class to remove the error
- code
- design
- split
- downloading android studio
- creating a project
- application
- company domain
- package name should be taken care of
- after creating the project
- java
- res
- AndroidManifest
- Work
-
- java- we write the code under MainActivity.java
- in regular java, for execution it searches for main method and then executes the main method
- in android, for execution it goes to MainActivity and searches for onCreate method
-
- we design under activity_main.xml
-
- For giving permission, eg:memory card, internet, camera access
the virtual mobile which runs the app, that's being created by the java
- open avd manager
-
in the box that opens up, "create virtual device " is your option
-
choose the phone type
-
choose the os
-
Bam! the phone is created
-
run the java file
OOPS! error
getting back to the previous code where no editing was done and here's the code
- MainActivity.java
package com.anindamaulik.myapplication;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
- activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<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/AppTheme.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_main" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
-
output of activity_main.xml in graphical mode which also includes the phone app version
-
note: that the phone version and graphical mode in the android studio is not the same
- content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<fragment
android:id="@+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/nav_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
- note: that the phone version and graphical mode in the android studio for content_main.xml is not the same
- fragment_first.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".FirstFragment">
<TextView
android:id="@+id/textview_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Aninda Meister's palace of love"
app:layout_constraintBottom_toTopOf="@id/button_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button named edited by me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview_first" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button created and constrained by pencil"
app:layout_constraintEnd_toEndOf="@+id/textview_first"
app:layout_constraintStart_toStartOf="@+id/textview_first"
tools:layout_editor_absoluteY="310dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
- note: probably really needs to be made in here, because this is the sheer fragment part where the actual existence of button lies
-
just bottom part of the button has been taken care of
-
thus top, bottom, right left needs to be taken care of and you get the desired thing, which is also in accordance to the android studio design view for fragment_first.xml
corresponding code for fragment_first.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".FirstFragment">
<TextView
android:id="@+id/textview_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Aninda Meister's palace of love"
app:layout_constraintBottom_toTopOf="@id/button_first"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_first"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button named edited by me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview_first" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button created and constrained by pencil"
app:layout_constraintBottom_toTopOf="@+id/button_first"
app:layout_constraintEnd_toEndOf="@+id/textview_first"
app:layout_constraintStart_toStartOf="@+id/textview_first"
app:layout_constraintTop_toBottomOf="@+id/textview_first" />
</androidx.constraintlayout.widget.ConstraintLayout>
- fragment_second.xml which came into existence by clicking on the default available button
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".SecondFragment">
<TextView
android:id="@+id/textview_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@id/button_second"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button_second"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="got2understandVCHpartOfDbuttonISthis"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/textview_second" />
</androidx.constraintlayout.widget.ConstraintLayout>
- we need to download the API
- or else we won't get the stuff while we'd attempt to create the virtual device
– onCreate() , এক্টিভিটি ( Activity ) ক্রিয়েট হতেই এই মেথড কল হয়।
– onStart() , যখন এক্টিভিটি ( Activity ) ইউজারের কাছে ভিজিবল।
– onResume() , যখন ইউজার অ্যাপ্লিকেশনের সাথে ইন্টারেকশন শুরু করে।
– onPause() , যদি এক্টিভিটি ( Activity ) পজ করার দরকার হয়।
– onStop(), যখন এক্টিভিটি ( Activity ) ইনভিজিবল করা হয়।
– onDestroy() , ঠিক এক্টিভিটি ( Activity ) ডেস্ট্রয় করার আগের মুহুর্তে এটা কল হয়।
– onRestart() , যখন এক্টিভিটি ( Activity ) স্টপ হওয়ার পর আবার স্ট্যার্ট করতে হয় তখন এই মেথড কল হবে।
package com.anindamaulik.myapplication;
import android.os.Bundle;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
- the above is gonna attempted to be edited now
Steps to create actions in regards to the button
-
creating a variable 'b' of type Button
-
importing the package for button
b=(Button) findViewById(R.id.button);
Steps
- getting the right id of the button
Note: couldn't find that in the code and hence got it from the design, found it later and yes, it is there
-
catching the xml's button by the method call for the variable created, namely 'b'.. the method name is findViewById
-
casting the class, because there could be many types of buttons. b=(Button) findViewById(R.id.button);
-
a little confusion before 4:22
-
to get the button clicked we need the method setOnClickListener()
-
Choose Empty Activity: because later development can be in accordance to my choice
-
choose API 25, yes only 66+% is available to use my app but it's fine it seems for now; maybe later I can experiment with my phone called Coolpad
-
The following code has been put across for MainActivity.java
package com.anindamaulik.poulomisupervision;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(),"Aninda Clicked on the button", Toast.LENGTH_LONG).show();
}
});
}
}
- activity_main.xml
- the id associated to the button has been used in MainActivity.java where the line is b=(Button) findViewById(R.id.button);
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>
- data passing
- going from one activity to another
- creating the "another" activity
- a corresponding activity_second.xml is also created for SecondActivity.java
-
Intent i=new Intent(MainActivity.this, MainActivity2.class);
-
with the above we are trying to get an object 'i' associated to the pre-defined class Intent
-
the next step is to import that predefined class namely Intent
-
we mention the starting point and ending point as parameters for the Intent class
-
intent can also take data from one activity to the other activity
package com.anindamaulik.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Button b;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b=(Button) findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(),"Button to go to the next page", Toast.LENGTH_LONG).show();
Intent i=new Intent(MainActivity.this, MainActivity2.class);
startActivity(i);
}
});
}
}
- XML and HTML were designed with different goals:
- XML was designed to carry data - with focus on what data is
- HTML was designed to display data - with focus on how data looks
- XML tags are not predefined like HTML tags are
-absolute basics without any editing
<?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"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="@+id/textView"
app:layout_constraintStart_toStartOf="@+id/textView"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</LinearLayout>
- extensive markup language
- created to carry data
- button tag, list view tag, progress bar tag, text view tag, edit text tag(to accept text)
- just delete the first part Eg: androidx.constraintlayout.widget.ConstraintLayout and replace it by LinearLayout
- the above would change the complete thing, including the ending part and give me an error free xml code
- help from: https://www.youtube.com/watch?v=BWUWJEaI0aE
- android:orientation="horizontal"
- android:orientation="vertical"
- default show or default parameters
-
wrap content:- it says that however long my text is, just align the borders as such
-
match_parent: -it takes up the whole
-
android:text="hey! it's me Aninda, Welcome to my palace of straight love"
-
android:id="@+id/textView"
- same as above
- we can keep audio, icon, photo, music etc
- name convention needs to be kept in mind, like it starts with lowercase and not uppercase
- at first chose 22.png, the option didn't come up; so make sure that the image comes up.
- 'H' is not a valid file-based resource name character:
- File-based resource names must contain only lowercase a-z, 0-9, or underscore
- the name was myHCLpic.PNG, so basically no error should exist