Thursday, 25 July 2013

Java while running some external library file is missing

Do the following

Go to Project->Properties->Java Build Path than select Order and export tab. Set android-support-v4.jar library checked and up it into top of the list. And clean and rebuild..It works for most of the cases


External library is android-support-v4.jar in this case

Android header footer with scrollable listview



<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/background_color" >

    <include
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="119dp"
        layout="@layout/header_text" />

    <include
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        layout="@layout/mnbuttons"
        android:id="@+id/footer"/>
    <ListView
        android:id="@id/android:list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_above="@+id/footer"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="73dp" >
    </ListView>

</RelativeLayout>

Tuesday, 23 July 2013

Introducing hyperlink in alertdialogue box

package com.example.alertdialogue;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Html;
import android.text.method.LinkMovementMethod;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;

import android.widget.CheckBox;
import android.widget.TextView;

public class MainActivity extends Activity {
    public static final String PREFS_NAME = "MyPrefsFile1";
    public CheckBox dontShowAgain;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        AlertDialog.Builder adb = new AlertDialog.Builder(this);

        LayoutInflater adbInflater = LayoutInflater.from(this);
        View eulaLayout = adbInflater.inflate(R.layout.checkbox, null);
        dontShowAgain = (CheckBox) eulaLayout.findViewById(R.id.skip);
        adb.setView(eulaLayout);
        adb.setTitle("Attention");

        adb.setMessage(R.string.link_text_manual);
        adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                String checkBoxResult = "NOT checked";
                if (dontShowAgain.isChecked())
                    checkBoxResult = "checked";
                SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                SharedPreferences.Editor editor = settings.edit();
                editor.putString("skipMessage", checkBoxResult);
                // Commit the edits!
                editor.commit();
                return;
            }
        });

        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        String skipMessage = settings.getString("skipMessage", "NOT checked");
        if (skipMessage != "checked") {

            AlertDialog welcomeAlert = adb.create();
            welcomeAlert.show();

            ((TextView) welcomeAlert.findViewById(android.R.id.message))
                    .setMovementMethod(LinkMovementMethod.getInstance());
        }
    }
}


activity_main
--------------------
<RelativeLayout 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" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

</RelativeLayout>


checkbox
-------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="10dp" >

    <CheckBox
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/skip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Do not show again" >
    </CheckBox>

</LinearLayout>


strings.xml
---------------------------------
<resources>

    <string name="app_name">alertdialogue</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>
      <string name="ok">ok</string>
 <string name="link_text_manual">Terms &amp; Conditions <a href="http://www.google.com">link</a>

</string>

</resources>

Monday, 22 July 2013

Intoducing TextView in alertdialogue and Onclicklistener on that

import android.app.Activity;


import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity {
    public static final String PREFS_NAME = "MyPrefsFile1";
    public CheckBox dontShowAgain;

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

        final CheckBox dontShowAgain = new CheckBox(this);

        TextView textViewTerms = new TextView(this);

        textViewTerms.setText("Terms & Conditions   ");

        TextView textView = new TextView(this);

        textView.setText(Html.fromHtml("<u>Details</u>"));
        textView.setTextColor(Color.BLUE);
       
       
       
       
        textView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(getApplicationContext(), "clicked",
                        Toast.LENGTH_LONG).show();

            }
        });

        LinearLayout checkBoxLayout = new LinearLayout(this);
        checkBoxLayout.setLayoutParams(new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.MATCH_PARENT));

        checkBoxLayout.addView(dontShowAgain);
        checkBoxLayout.addView(textViewTerms);
        checkBoxLayout.addView(textView);

        AlertDialog.Builder altDialog = new AlertDialog.Builder(this);
        altDialog.setCancelable(false);
        altDialog.setView(checkBoxLayout);
        altDialog.setMessage("Do not Show Again");
        altDialog.setPositiveButton("OK",
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                   

                        String checkBoxResult = "NOT checked";
                        if (dontShowAgain.isChecked())
                            checkBoxResult = "checked";
                        SharedPreferences settings = getSharedPreferences(
                                PREFS_NAME, 0);
                        SharedPreferences.Editor editor = settings.edit();
                        editor.putString("skipMessage", checkBoxResult);
                        // Commit the edits!
                        editor.commit();
                        return;

                    }
                });

        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        String skipMessage = settings.getString("skipMessage", "NOT checked");
        if (skipMessage != "checked") {

            altDialog.show();
           
        }

       
   
    }
   
   
   
}

Sunday, 21 July 2013

Alert dialogue with checkbox should appear only when check box is unchecked

package com.example.callingintent;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends Activity {

    public String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    protected static final int REQUEST_CODE = 0;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        EditText edt1 = (EditText) findViewById(R.id.editText1);
        Button button1 = (Button) findViewById(R.id.button1);
        EditText et1 = (EditText) findViewById(R.id.editText1);
        et1.setText(getName());
        button1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub

                Intent myintent = new Intent(MainActivity.this,
                        secondActivity.class);
                myintent.putExtra("name", "namratha");
                myintent.putExtra("Id", 1);
                // startActivity(myintent);
                startActivityForResult(myintent, REQUEST_CODE);
            }
        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        String returnString;
        if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
            if (data.hasExtra("returnString1")) {
                returnString = data.getExtras().getString("returnString1");
                System.out.println("return string is   " + returnString);
                setName(returnString);

            }
        }

    }

}




package com.example.callingintent;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;

public class secondActivity extends Activity {
    public static final String PREFS_NAME = "MyPrefsFile1";
    public CheckBox dontShowAgain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.second);
        EditText et1 = (EditText) findViewById(R.id.editText1);
        EditText et2 = (EditText) findViewById(R.id.editText2);
        Bundle mydata = getIntent().getExtras();
        if (mydata != null) {
            String name = mydata.getString("name");
            int id = mydata.getInt("Id");
            System.out.println("id is " + id);

            et1.setText(name);
            // et1.setText(id);

        }

        AlertDialog.Builder adb = new AlertDialog.Builder(this);
        LayoutInflater adbInflater = LayoutInflater.from(this);
        View eulaLayout = adbInflater.inflate(R.layout.checkbox, null);
        dontShowAgain = (CheckBox) eulaLayout.findViewById(R.id.skip);
        adb.setView(eulaLayout);
        adb.setTitle("Attention");
        adb.setMessage(Html.fromHtml("Message"));
        adb.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                String checkBoxResult = "NOT checked";
                if (dontShowAgain.isChecked())
                    checkBoxResult = "checked";
                SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
                SharedPreferences.Editor editor = settings.edit();
                editor.putString("skipMessage", checkBoxResult);
                // Commit the edits!
                editor.commit();
                return;
            }
        });
        SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
        String skipMessage = settings.getString("skipMessage", "NOT checked");
        if (skipMessage != "checked")
            adb.show();

    }

    public void finish() {
        Intent data = new Intent();

        data.putExtra("returnString1", "Message to parent activity");
        setResult(RESULT_OK, data);
        super.finish();

    }

}



activity_main.xml
-------------------------
<RelativeLayout 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" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="44dp"
        android:text="Button" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/button1"
        android:layout_marginTop="33dp"
        android:layout_toLeftOf="@+id/textView1"
        android:ems="10" >

        <requestFocus />
    </EditText>

</RelativeLayout>


checkbox.xml
-------------------------------
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/layout_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal"
    android:padding="10dp" >

    <CheckBox
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/skip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Do not show again" >
    </CheckBox>

</LinearLayout>

second.xml
--------------------------
<RelativeLayout 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" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="Hello Second Activity"
        tools:context=".MainActivity" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="36dp"
        android:layout_marginTop="36dp"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/editText1"
        android:layout_below="@+id/editText1"
        android:layout_marginLeft="21dp"
        android:layout_marginTop="20dp"
        android:ems="10" />

</RelativeLayout>

Wednesday, 17 July 2013

Delete DataBase android sqllite

// TODO Auto-generated method stub
         public void deleteDatabase() {
             System.out.println("delete deleteDatabase calleds");
             mHelper = new MyDbHelper(context,
                      "dbname");
                 SQLiteDatabase db = mHelper.getWritableDatabase();
           
                 mHelper.close();
                 db.close();
              if (this.context().deleteDatabase("dbname") {
              System.out.println("db deleted");
              } else {
                System.out.println("not deleted");
              }
            }

InsertList RemoveList Easy Approach


import java.util.ArrayList;
import java.util.List;

public class ListCompApa {
    public static void main(String[] args) {
       
       
           

         final List<String> gatewaylist = new ArrayList<String>();
   
         gatewaylist.add("namea");
         gatewaylist.add("sam");
         final List<String> dblist = new ArrayList<String>();
         dblist.add("ddd");
         dblist.add("lll");
         dblist.add("namea");
       
         final List<String> insertList = new ArrayList<String>(gatewaylist);
         insertList.removeAll(dblist);
         final List<String> removeList = new ArrayList<String>(dblist);
         removeList.removeAll(gatewaylist);
         System.out.println("gatewaylist ins "+insertList);
         System.out.println("dblist rem "+removeList);
       
    }

}

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...