Open top menu



In this tutorial explain how to open new Activity when swipe this listview possition right to left .
i have earlier  implement the swipe gesture detector code, this code get the  X,Y pixel point when onTouch finger.


class SwipeGestureListener extends SimpleOnGestureListener implements
    OnTouchListener {
   Context context;
   GestureDetector gestureDetector;
   static final int SWIPE_MIN_DISTANCE = 120;
   static final int SWIPE_MAX_OFF_PATH = 250;
   static final int SWIPE_THRESHOLD_VELOCITY = 200;

   public SwipeGestureListener() {
    super();
   }

   public SwipeGestureListener(Context context) {
    this(context, null);
   }

   public SwipeGestureListener(Context context, GestureDetector gestureDetector) {

    if (gestureDetector == null)
    gestureDetector = new GestureDetector(context, this);

    this.context = context;
    this.gestureDetector = gestureDetector;
   }

   @Override
   public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
     float velocityY) {

    final int position = tutorials.pointToPosition(
      Math.round(e1.getX()), Math.round(e1.getY()));

    String tutorialName = (String) tutorials.getItemAtPosition(position);

    if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
     if (Math.abs(e1.getX() - e2.getX()) > SWIPE_MAX_OFF_PATH
       || Math.abs(velocityY) < SWIPE_THRESHOLD_VELOCITY) {
      return false;
     }
     if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this, "bottomToTop" + tutorialName,
        Toast.LENGTH_SHORT).show();
     } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "topToBottom  " + tutorialName, Toast.LENGTH_SHORT)
        .show();
     }
    } else {
     if (Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {
      return false;
     }
// open new activity

     if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this, "swipe RightToLeft " + tutorialName, 5000).show();
       
      Intent intent=new Intent(MainActivity.this,second.class);
      startActivity(intent);
      
     }


else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "swipe LeftToright  " + tutorialName, 5000).show();
     }
    }

    return super.onFling(e1, e2, velocityX, velocityY);

   }

   @Override
   public boolean onTouch(View v, MotionEvent event) {

    return gestureDetector.onTouchEvent(event);
   }

   public GestureDetector getDetector() {
    return gestureDetector;
   }

  }


................................................................................................................................................................
learn More
http://androidbeginnerpoint.blogspot.in/2015/12/swipegesture-inside-listview-in-android.html
Read more


 In this Blog explain how to used swipe gesture detector inside ListView in android.
the swipe gesture is an impotent part of user  interaction on user interface your android app.


package com.example.androidbegnnerpoint;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class MainActivity  extends Activity {

  ListView tutorials;
String[] tutorial =
 { "1.SWIPE GETSTURE TUTORIAL",
"2.HOW TO BACK WEBVIEW TO ANDROID APP",
"3.LOAD WEBVIEW WITH PROGRESSBAR IN ANDROID",
"4.TABHOST WITH ACTIVITY IN ANDROID",
"5.DRAW CANVAS LINE ONTOUCH FINGER IN ANDROID",
"6.HOW TO SET DRAWABLE IMAGE IN TEXTVIEW PROGRAMATICALLY IN ANDROID",
"7.IMAGE SHADOW EFFECT (HIGHLIGHT/FOCUS) IN IMAGEVIEW IN ANDROID",
"8.GLOW EFFECT ON IMAGEVIEW IN ANDROID",
"9.DARG IMAGE ONTOUCH FINGER IN ANDROID",
"10.ANDROID BASIC CALCULATOR"};


 SwipeGestureListener gestureListener;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);
  tutorials= (ListView) findViewById(R.id.list_tutorials);
   ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(
     MainActivity.this, android.R.layout.simple_list_item_1, tutorial);
 
   tutorials.setAdapter(arrayAdapter);
      gestureListener = new SwipeGestureListener(MainActivity.this);
      tutorials.setOnTouchListener(gestureListener);
 }



  class SwipeGestureListener extends SimpleOnGestureListener implements
    OnTouchListener {
   Context context;
   GestureDetector gestureDetector;
   static final int SWIPE_MIN_DISTANCE = 120;
   static final int SWIPE_MAX_OFF_PATH = 250;
   static final int SWIPE_THRESHOLD_VELOCITY = 200;

   public SwipeGestureListener() {
    super();
   }

   public SwipeGestureListener(Context context) {
    this(context, null);
   }

   public SwipeGestureListener(Context context, GestureDetector gestureDetector) {

    if (gestureDetector == null)
    gestureDetector = new GestureDetector(context, this);

    this.context = context;
    this.gestureDetector = gestureDetector;
   }

   @Override
   public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
     float velocityY) {

    final int position = tutorials.pointToPosition(
      Math.round(e1.getX()), Math.round(e1.getY()));

    String tutorialName = (String) tutorials.getItemAtPosition(position);

    if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) {
     if (Math.abs(e1.getX() - e2.getX()) > SWIPE_MAX_OFF_PATH
       || Math.abs(velocityY) < SWIPE_THRESHOLD_VELOCITY) {
      return false;
     }
     if (e1.getY() - e2.getY() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this, "bottomToTop" + tutorialName,
        Toast.LENGTH_SHORT).show();
     } else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "topToBottom  " + tutorialName, Toast.LENGTH_SHORT)
        .show();
     }
    } else {
     if (Math.abs(velocityX) < SWIPE_THRESHOLD_VELOCITY) {
      return false;
     }
     if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "swipe RightToLeft " + tutorialName, 5000).show();
     } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE) {
      Toast.makeText(MainActivity.this,
        "swipe LeftToright  " + tutorialName, 5000).show();
     }
    }

    return super.onFling(e1, e2, velocityX, velocityY);

   }

   @Override
   public boolean onTouch(View v, MotionEvent event) {

    return gestureDetector.onTouchEvent(event);
   }

   public GestureDetector getDetector() {
    return gestureDetector;
   }

  }

}


activity_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"
    android:id="@+id/layout">

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/logoweb" />

    <ListView
        android:id="@+id/list_tutorials"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
          >
    </ListView>
</LinearLayout>
...............................................................................................................................................................






try this code...

Read more



In this blog implement the Basic calculator, try this code


Step 1:
 Create a activity_main.xml inside res/layout folder....

activity_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" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10pt"
        android:layout_marginRight="10pt"
        android:layout_marginTop="3pt" >

        <EditText
            android:id="@+id/editNumber"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginRight="5pt"
            android:layout_weight="1"
            android:inputType="numberDecimal" >
        </EditText>

        <EditText
            android:id="@+id/editNumbers"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="5pt"
            android:layout_weight="1"
            android:inputType="numberDecimal" >
        </EditText>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/linearLayout2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5pt"
        android:layout_marginRight="5pt"
        android:layout_marginTop="3pt" >

        <Button
            android:id="@+id/btnAddtion"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="+"
            android:textSize="8pt" >
        </Button>

        <Button
            android:id="@+id/btnSubtract"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="-"
            android:textSize="8pt" >
        </Button>

        <Button
            android:id="@+id/btnMultiply"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="*"
            android:textSize="8pt" >
        </Button>

        <Button
            android:id="@+id/btnDivision"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="/"
            android:textSize="8pt" >
        </Button>
    </LinearLayout>

    <TextView
        android:id="@+id/tvResult"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="5pt"
        android:layout_marginRight="5pt"
        android:layout_marginTop="3pt"
        android:gravity="center_horizontal"
        android:textSize="12pt" >
    </TextView>

</LinearLayout>


Step:2
Create MainActivity.java inside src folder

Main_Activity.java
..................................................................................................................................................................
package com.example.androidbeginnerpoin;

import android.app.Activity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity implements OnClickListener {

 EditText editNum1;
 EditText editNum2;

 Button buttionAdd;
 Button buttionSub;
 Button buttionMult;
 Button buttionDiv;

 TextView  textResult;

 String oper = "";


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

 
   editNum1 = (EditText) findViewById(R.id.editNumber);
   editNum2 = (EditText) findViewById(R.id.editNumbers);

   buttionAdd = (Button) findViewById(R.id.btnAddtion);
   buttionSub = (Button) findViewById(R.id.btnSubtract);
   buttionMult = (Button) findViewById(R.id.btnMultiply);
   buttionDiv = (Button) findViewById(R.id.btnDivision);

     textResult= (TextView) findViewById(R.id.tvResult);

 
   buttionAdd.setOnClickListener((OnClickListener) this);
   buttionSub.setOnClickListener(this);
   buttionMult.setOnClickListener(this);
   buttionDiv.setOnClickListener(this);

 }

 @Override
 public void onClick(View v) {
 
   float num1 = 0;
   float num2 = 0;
   float result = 0;

 
   if (TextUtils.isEmpty(editNum1.getText().toString())
       || TextUtils.isEmpty(editNum2.getText().toString())) {
     return;
   }

 
   num1 = Float.parseFloat(editNum1.getText().toString());
   num2 = Float.parseFloat(editNum2.getText().toString());

   
   switch (v.getId()) {
   case R.id.btnAddtion:
     oper = "+";
     result = num1 + num2;
     break;
   case R.id.btnSubtract:
     oper = "-";
     result = num1 - num2;
     break;
   case R.id.btnMultiply:
     oper = "*";
     result = num1 * num2;
     break;
   case R.id.btnDivision:
     oper = "/";
     result = num1 / num2;
     break;
   default:
     break;
   }

 
   textResult.setText(num1 + " " + oper + " " + num2 + " = " + result);
 }
}



Read more



In this bloag implement  How to Back WebView to Our android app. try this code



// To handle "Back" key press event for WebView to go back to previous screen.
   @Override
   public boolean onKeyDown(int keyCode, KeyEvent event)
   {
       if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
        webview.goBack();
           return true;
       }
       return super.onKeyDown(keyCode, event);
   }
Read more


try this code..

// first, get all checked checkBox in listview
final SparseBooleanArray checkedItems = listviewroti_prata.getCheckedItemPositions();

for (int i = 0; i < checkedItems.size(); i++){
  
//find all checked or not
final boolean isChecked; = checkedItems.valueAt(i);
   
if (!isChecked){
   
Toast.makeText(getApplicationContext(), "not checked", Toast.LENGTH_LONG).show();                                                            
 } else{
Toast.makeText(getApplicationContext(), " checked", Toast.LENGTH_LONG).show();
}
Read more