Showing posts with label Android Widgets. Show all posts
Showing posts with label Android Widgets. Show all posts

Saturday, 15 October 2016

WebView in android

WebView is a view and it displays the web pages inside the applications.
Creating and setting webview client.
Example : Loading the web page like websites etc. (Urls).
                 1)http://androiddevelopersstudio.blogspot.in

acivitymain.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"
  tools:context="com.kiranapp.MainActivity">

<ProgressBar
  android:layout_centerHorizontal="true"
  android:layout_height="wrap_content"
  android:layout_width="wrap_content"
  android:layout_gravity="center_vertical|center_horizontal"
  android:id="@+id/progressBar1"/>

<TextView
   android:layout_below="@+id/progressBar1"
   android:layout_height="wrap_content"
   android:id="@+id/LoadingText"
   android:layout_width="fill_parent"
   android:text="please wait loading website"
   android:textSize="20sp"
   android:gravity="center_horizontal">
</TextView>
<WebView
  android:id="@+id/activity_main_webview"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:layout_gravity="center_horizontal" />

</LinearLayout>

How to design the widgets please follow below figure :
or we can select from widgets we can find in side bar.

WebView
XML Figure




















MainActivity.java :-

package com.kiranapp;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ProgressBar;

public class MainActivity extends Activity {

 private WebView mWebView;
  ProgressBar progressBar;

@Override
   protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.activity_main);

  mWebView = (WebView) findViewById(R.id.activity_main_webview);
  progressBar = (ProgressBar) findViewById(R.id.progressBar1);

WebSettings webSettings = mWebView.getSettings();
 webSettings.setJavaScriptEnabled(true);
 mWebView.loadUrl("http://androiddevelopersstudio.blogspot.in/");

    }
}

Output :-

WebView
WebView fig :1




















WebView
WebView fig :2


Wednesday, 12 October 2016

AlertDialogBox

 It is display the some alert
  Using Builder class


activitymain.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"
  tools:context="com.kiranapp.MainActivity">
<Button
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:id="@+id/button"
  android:layout_gravity="center_horizontal"
  android:text="Alertdialog"
  android:layout_marginTop="20dp" />
</LinearLayout>

MainActivity.java :-


package com.kiranapp;

import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
 Button alertbtn;

@Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 alertbtn=(Button)findViewById(R.id.button);
 alertbtn.setOnClickListener(new View.OnClickListener() {
@Override
  public void onClick(View v) {

AlertDialog.Builder builder=new AlertDialog.Builder(MainActivity.this);
 builder.setTitle("Alert?");
 builder.setMessage("Hello do u want to close the app");
 builder.setIcon(R.mipmap.ic_launcher);
 builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
  public void onClick(DialogInterface dialog, int which) {
  finish();
 Toast.makeText(MainActivity.this, "App Closed", Toast.LENGTH_SHORT).show();
  }
 });
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
  public void onClick(DialogInterface dialog, int which) {
 Toast.makeText(MainActivity.this, "Dialog is CLosed", Toast.LENGTH_SHORT).show();
  }
 });
 builder.create();
 builder.show();
 }
});
}
}

Output :-


AlertDialogBox
AlertDialogBox fig :1
AlertDialogBox
AlertDialogBox fig :2

AutoCompleteTextView

activitymain.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"
  tools:context="com.kiranapp.MainActivity">
<AutoCompleteTextView
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:id="@+id/autoCompleteTextView"
  android:layout_gravity="center_horizontal"
  android:layout_marginTop="20dp"
  android:hint="enter letter" />
<Button
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:id="@+id/button"
 android:layout_gravity="center_horizontal"
 android:text="show" />
</LinearLayout>

MainActivity.java :-


package com.kiranapp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {
AutoCompleteTextView autoCompleteTextView;
Button show;
String name;
static final String[] fruits={"Apple","Orange","Watermelon","Bannana","Strawberry","Peaches"};
@Override
  protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  autoCompleteTextView=(AutoCompleteTextView)findViewById(R.id.autoCompleteTextView);
  show=(Button)findViewById(R.id.button);
  ArrayAdapter<String>arrayAdapter=new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_dropdown_item_1line,fruits);
  autoCompleteTextView.setThreshold(0);
  autoCompleteTextView.setAdapter(arrayAdapter);
  autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
  name= (String) parent.getItemAtPosition(position);
  }
 });
 show.setOnClickListener(new View.OnClickListener() {
@Override
    public void onClick(View v) {
  Toast.makeText(MainActivity.this,"Select Fruits :"+name,Toast.LENGTH_SHORT).show();
  }
  });
  }
}

Output :-

AutoCompleteTextView
AutoCompleteTextView fig :1



Monday, 3 October 2016

Android Widgets

There are different widgets in android are

1) Button :-

It is a  widget.
When ever the user click or press doing some action
For example   Login,Signup,Sign in(Facebook, Gmail, Yahoo etc)
                       Register
In Android Studio,  Design the app
                               Drag and Drop
                               XML or HTML Code
2) Edit Text :-
    It is a widget.
    When ever the user to giving the input values is called edit text
    For example username,password.
3) Text View :-
     It is a widget
     When ever the user display the some text and content is called text view.

4) Check Box :-
      It is a widget
      When ever the user to select single item at a time multiple items
 
5) Radio Button :-
    A Radio Button is a two states button that can either checked or unchecked.
 
6) Toggle Button :-
     It displays checked or unchecked states as a button with a 'light' indicator and by default    
     accompanied with the text ON or OFF.
7) Switch :-
     A Switch is a two-state toggle switch widget that can select between two options.
8) Image Button :-
     It displays a button with an image (instead of text) that can be pressed or by click the user.
 
9) Image View :-
     It displays an arbitrary image, such as icon.

10) Progressive Bar :-
      The progressive bar view provides visual feedback about some going on tasks, when u are   
       performing a task in background. 

11) Spinner :-
      A view that displays one child at a time and lets the user picks among them.

12) Web View :-
       A view that displays Web Pages. This class is basis upon which u can roll your own web browser or simply display some online content within your Activity.