Friday, 8 April 2016

Android Example - PopUp

Example of using PopupWindow

android.widget.PopupWindow can be used to display an arbitrary view. The popup windows is a floating container that appears on top of the current activity.

Example of PopupWindow

Create /res/layout/popup.xml to define the view of the PopupWindow.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@android:color/background_light">
 <LinearLayout 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:orientation="vertical" 
     android:layout_margin="1dp"
     android:background="@android:color/darker_gray">
     >
     <LinearLayout 
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:orientation="vertical" 
      android:layout_margin="20dp">
      <TextView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="It's a PopupWindow" />
      <ImageView
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:src="@drawable/ic_launcher" />
      <Button
          android:id="@+id/dismiss"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:text="Dismiss" />
      </LinearLayout>
 </LinearLayout>
</LinearLayout>


Main activity Java code to handle the PopupWindow
package com.exercise.AndroidPopupWindow;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.PopupWindow;

public class AndroidPopupWindowActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Button btnOpenPopup = (Button)findViewById(R.id.openpopup);
        btnOpenPopup.setOnClickListener(new Button.OnClickListener(){

   @Override
   public void onClick(View arg0) {
    LayoutInflater layoutInflater 
     = (LayoutInflater)getBaseContext()
      .getSystemService(LAYOUT_INFLATER_SERVICE);  
    View popupView = layoutInflater.inflate(R.layout.popup, null);  
             final PopupWindow popupWindow = new PopupWindow(
               popupView, 
               LayoutParams.WRAP_CONTENT,  
                     LayoutParams.WRAP_CONTENT);  
             
             Button btnDismiss = (Button)popupView.findViewById(R.id.dismiss);
             btnDismiss.setOnClickListener(new Button.OnClickListener(){

     @Override
     public void onClick(View v) {
      // TODO Auto-generated method stub
      popupWindow.dismiss();
     }});
               
             popupWindow.showAsDropDown(btnOpenPopup, 50, -30);
         
   }});
    }
}


main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello" />
    <Button
        android:id="@+id/openpopup"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Open Popup Window" />
    
</LinearLayout>

video on youtube

Android Studio 2.0 and Emulator 25.1.1 are official now

Android Studio 2.0 and Emulator 25.1.1 are officially now


Android Studio 2.0 and Emulator 25.1.1 are moved to stable release channels.
This release is focused on development productivity by introducing instant run and a much faster emulator. Please see our blog post for more details.

announcement: Android Tools Project Site - Android Studio 2.0 and Emulator 25.1.1 are Available in the Stable, Beta, and Dev Channels

Upgrade to Android Studio 2.0 from 1.5:

Android Example - Alert Box

In this tutorial, we show you how to display an alert box in Android. See flowing Steps :
  1. First, use the AlertDialog.Builder to create the alert box interface, like title, message to display, buttons, and button onclick function
  2. Later attach above builder to AlertDialog and display it.
  3. Done.
P.S This project is developed in Eclipse 3.7, and tested with Android 2.3.3.

1 Android Layout Files

Simpel layout file, display a button on screen.
File : res/layout/main.xml
Markup
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 
    <Button
        android:id="@+id/buttonAlert"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Show Alert Box" />
            
</LinearLayout>

2. Activity

When user click on this button, display the alert box, with your pre-defined alert dialog interface.
File : MainActivity.java
Java
package com.mkyong.android;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivity extends Activity {

 final Context context = this;
 private Button button;

 public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  button = (Button) findViewById(R.id.buttonAlert);

  // add button listener
  button.setOnClickListener(new OnClickListener() {

  @Override
  public void onClick(View arg0) {

   AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
    context);

   // set title
   alertDialogBuilder.setTitle("Your Title");

   // set dialog message
   alertDialogBuilder
    .setMessage("Click yes to exit!")
    .setCancelable(false)
    .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialog,int id) {
      // if this button is clicked, close
      // current activity
      MainActivity.this.finish();
     }
      })
    .setNegativeButton("No",new DialogInterface.OnClickListener() {
     public void onClick(DialogInterface dialog,int id) {
      // if this button is clicked, just close
      // the dialog box and do nothing
      dialog.cancel();
     }
    });

    // create alert dialog
    AlertDialog alertDialog = alertDialogBuilder.create();

    // show it
    alertDialog.show();
   }
  });
 }
}

3. Demo

Start it, display a button.
android alert box example
When button is clicked, display the alert box
android alert box example
If “Yes” button is clicked, close the activity and return back to your Android main screen.
android alert box example
Follow me on twitter - @tweet_naman

Malaria Defender - By Naman Tiwari


I have developed an application known as Malaria Defender .
It is an only application through which a person can check malaria in seconds with just few clicks .

It have a nice design and some nice graphics . 
Download the app here - Click here

Steps to use app .

1. Create a profile .


2. Browse the content

3. Check malaria.


4. Gather Report


5. Gather profile


6. Edit Profile


7. Take doctors advice


And a lot more .

Developer - Naman Tiwari
Age 13 .

follow me on twitter - @tweet_naman








Tuesday, 12 January 2016

"Programming IQ" Version 2.0

"Programming IQ" - Version 2.0

 Programming IQ has launched Version 2.0
. Get it now on play store . Link of the app



An app for people those who want to clear out programming interviews.

App contain more than 700 Questions of 12 languages .

App is developed by a 12 years boy Naman Tiwari

Contact me for help - namantiwari2002@gmail.com
Twitter - @tweet_naman

Please download and rate the application.

Wednesday, 16 December 2015

My app "Vector War"

Get my new app "Vector War" now......  please download and rate it  .. it is a simple game based on shettle war ...... #A12YearsAppDeveloper

....https://play.google.com/store/apps/details?id=namantiwari.vectorwar






Please download , share and rate it..........

Get me on twitter  -  https://twitter.com/tweet_naman

Monday, 14 December 2015

Programming IQ android app by Naman Tiwari

Introducing my new android application - "Programming IQ"
It is for those people who want to clear out their programming languages interviews.

It contains about 660 questions of 10 different programming languages.......

Features:-
1. 660 Questions
2. 10 Programming languages
3. Offline
4. Great UI
5. Easy to handle
6. Read easily with Night Mode.


Link for app - https://play.google.com/store/apps/details?id=namantiwari.programminginterviewquestions