Skip to content

Instantly share code, notes, and snippets.

View AkaashSaini's full-sized avatar
🏠
Working from home

Akash Saini AkaashSaini

🏠
Working from home
  • searce
  • rajkot,GJ
View GitHub Profile
PDO
It allows developers to create code which is portable across many databases and platforms. In simple words it makes application independent from the data source. We can connect our application with any database like mysql, oracle etc. without make any change in our PHP code.
Front-End-> PHP Code(Middleware) ->PDO->Data Source(Back-end)
It work like layer between middleware and back-end.
----------------------------------------------------------------------------------------------------------------------------------
Creating Connection –
Create object of PDO and make connection between PHP and data source.
Passing Data from one activity to other
Use following code in first activity
Intent intent=new Intent(Main.this,second.class);
Intent.putExtra(“val”, t1.getText().toString()); //parameter, value
startActivity(intent)
putExtra() – It is used to store parameter with value in intent.
Write following code in second activity
TextView tv=(TextView) findViewById(R.layout.tv1);
Tv.setText(getIntent().getExtras().getString(“val”));
Alert Dialog
If you want to ask the user about taking a decision between yes or no in response of any particular action taken by the user, you can use Alert Dialog.
Steps
Create the object of DialogBuilder and set operations
AlertDialog.Builder alertbuilder=new AlertDialog.Builder(MainActivity.this);
alertbuilder.setMessage("Do you want to continue....");
alertbuilder.setPositiveButton("YES", new op1());
alertbuilder.setNegativeButton("NO", new op2());
Custom Dialog
Create a Dialog
Dialog d=new Dialog(MainActivity.this);
Set Following Properties
Dialog d=new Dialog(MainActivity.this);
d.setContentView(R.layout.dialog);
d.setTitle("Important Message....");
Input Dialog
Create layout file inputdialog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_root"
android:layout_width="fill_parent"
Playing and Stopping Sound –
• Create a folder raw in res
• Copy some songs in raw folder (all file names must be in small letters)
• Create a radio button group
<RadioGroup
android:id="@+id/rmusic"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
</RadioGroup>
• Add some radio buttons
Setting wallpaper -
• Copy some images in folder drawable-hdpi like a.jpg, b.jpg etc.
• add following controls to layout
o ImageView1(width-200dp, height=200dp)
o Button1
o Add scroll view and linear layout
<HorizontalScrollView
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_gravity="center">
Creating the Menu –
• Create a new menu using
o Create a new android xml file in menu folder with name main_menu.xml
o Write following code in this file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/item1"
android:alphabeticShortcut="s"
android:title="Sweet">
Using Image Gallery of Phone
1. Start Emulator
2. Open DDMS
3. Push images to sdcard
Storagesdcardpictures
Find push button on title bar of DDMS
4. Create UI
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
Using ListView control
ListView control allows us to manipulate each record which in the list. It provides index number to each item of list starting from 0.
Steps
Add ListView control to layout
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
Create the string array of items to be added