Tag Archives: java

java

Class has not initialiser error in Swift – Solved.

By | August 14, 2017

Apart from other languages, when you write a class in Swift, It should have a initialiser. To solve this we have to write init() function in that particular class. Just like below. For example, look at the below class. Here we have 5 variables. The above error usually comes when you don’t initialize all variables in the class… Read More »

Uploading Image to Server – Android Eclipse Version.

By | February 18, 2016

Hi all, In today’s tutorial I will show you how to send an image to server using POST method in ANDROID. If you are working in Android studio, then checkout the article here. Uploading an image to server is a basic requirement in many of our application. Sending data to server which is using a PHP Script is… Read More »

How to draw Arcs in Android using canvas?

By | January 10, 2013

This is a simple example showing how to draw Arcs in android, You can use this to create piecharts or someother similar thing you want. Here we have 3 classes. 1. GraphicsActivity.java 2. MainActivity.java 3. PictureLayout.java GraphicsActivity.java [java] package com.coderzheaven.arcdrawing; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.ViewGroup; class GraphicsActivity extends Activity { // set to true to… Read More »

How to crop an Image in Android?

By | December 15, 2012

This is a sample program that launches the camera and crop the captured image. Check this link to another crop image example. http://www.coderzheaven.com/2011/03/15/crop-an-image-in-android/ This is the layout xml. activity_main.xml [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:layout_margin="3dp" android:text="@string/intro" android:textStyle="bold" /> <Button android:id="@+id/capture_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/capture" /> <ImageView android:id="@+id/picture" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="5dp" android:contentDescription="@string/picture"… Read More »

How to load a spinner with values from SQlite Database in android?

By | November 18, 2012

Here is a simple example showing how to load a database values in a spinner in android. OK we will start. This is the layout for the spinner row. spinner_row.xml [xml] <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation = "vertical" android:id="@+id/tv" android:layout_margin="10dp"> </TextView> [/xml] This is the layout for the interface. activity_main.xml [xml] <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"… Read More »

How to Get Contact Image in Android.

By | November 12, 2012

This simple example gets the image from contacts in android. [java] private void getContactsDetails() { Cursor phones = getContentResolver().query( ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null); while (phones.moveToNext()) { String Name = phones .getString(phones .getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)); String Number = phones .getString(phones .getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)); String image_uri = phones .getString(phones .getColumnIndex(ContactsContract.CommonDataKinds.Phone.PHOTO_URI)); System.out.println("Contact1 : " + Name + ", Number " + Number + ",… Read More »

How to create a Slide from Left animation while deleting a row from a ListView in Android?

By | September 12, 2012

Hello all…… I have written a lost of posts on Listviews. You can see that by just searching Listviews in my site. Today I will show you how to create a slide out animation while we delete a row from a ListView. So this is the xml that contains the ListView. Let it be in the main.xml main.xml… Read More »

Using Tabbars in ANDROID, A Simple Example……….

By | April 22, 2012

This is a simple example showing how to use tabbars in ANDROID. First create a new project and copy this code to it. [java] package com.coderzheaven; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public class tabbar extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);… Read More »

Java Applet MouseEvents

By | April 22, 2012

A simple event based applet applications is described below First importing the necessary header files // Demonstrate the mouse event handlers. import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code=”MouseEvents” width=300 height=100> </applet> */ Next step is to create a class which implements the “MouseListener” and “MouseMotionListener “ public class MouseEvents extends Applet implements MouseListener, MouseMotionListener { String msg =… Read More »

Simulate a Balloon in Box2D, iPhone or ANDROID

By | April 12, 2012

Hello……… Sometimes you may want your body to act against the gravity of the world. One method to do this is described below. First what you have to do is to make a body in the shape of a circle and give it the image of a balloon as the userdata. Then in the tick function write this… Read More »

Date and TimePicker in ANDROID.

By | April 12, 2012

The following code simply allows you to select a date and time using the datepicker and timepicker in ANDROID. [java] package AndroidDatePicker.pack; import java.util.Calendar; import android.app.Activity; import android.app.DatePickerDialog; import android.app.Dialog; import android.app.TimePickerDialog; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.DatePicker; import android.widget.TimePicker; import android.widget.Toast; public class AndroidDatePicker extends Activity { private int myYear, myMonth, myDay, myHour, myMinute; static… Read More »

Saving Key-Value pair in Windows Phone using IsolatedStorageSettings

By | April 12, 2012

This sample code helps you to save a key and a corresponding value in windows Phone inside your application sandbox with the help of isolatedStorageSettings. PLease check this post before working around this post. How to save a text file in Windows Phone 7 or How to use isolated storage settings in Windows Phone 7? Here is the… Read More »

Switch Images in ANDROID.

By | April 7, 2012

Hi all …….. Ofter we have trouble with loading continous images in ANDROID from our application directory. The reason is that all resources have a unique resource ID which we need to get to load these resources. The following example shows how to get these unique identifier from the “path” of the resource. For example Here I have… Read More »

CustomAlert without any custom Layout in android.

By | February 6, 2012

We can create a dialog with custom alert dialog with our xml in android. But for making simple alerts we can make custom alerts through code itself. Here is a simple function for this. Here I am having a Listview and an edittext with two buttons in the alertBox. [java] public void addDialog(){ String test[] = {"hello1","hello2"}; AlertDialog.Builder… Read More »

How to check whether your service is running in android?

By | October 2, 2011

This example will test whether a service is running in android if you know it’s package name. Run this sample of code to check this. [java] private boolean checkMyServiceRunningOrNot() { ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE); for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) { if ("com.example.your_Service".equals(service.service.getClassName())) { return true; } } return false; } [/java]

How to Upload Multiple files in one request along with other string parameters in android?

By | August 16, 2011

Hello everyone, I have shown two methods to upload files in android. In today’s tutorial I will show another simple method to upload files. With this method you can upload multiple files in one request + you can send your own string parameters with them. Here is another method on working with uploading of images. How to upload… Read More »

How to find if a string starts with a particular word – JAVA ?

By | June 29, 2011

Hi, In order to find whether a given string starts with a particular string or not in JAVA, use the following code. [java] public class Main { public static void main(String[] args) { String urStr = "Coderz Heaven"; if (urStr.startsWith("Coderz")) { System.out.println("Yes! Your string starts with Coderz"); } else { System.out.println("No!"); } } } [/java]

Simple View Animation in ANDROID?

By | June 11, 2011

Hi all….. In this post I will show you a simple animation using a textView. It’s really simple. Steps. 1. Create a fresh project and copy this java code into it. [java] package pack.coderzheaven; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.view.animation.Animation.AnimationListener; import android.widget.Toast; public class AnimationDemo extends Activity implements AnimationListener { View v;… Read More »

Applet FlowLayout Example

By | May 16, 2011

The FlowLayout class puts components in a row, sized at their preferred size. Creates a new flow layout manager with the indicated alignment and the indicated horizontal and vertical gaps. The hgap and vgap arguments specify the number of pixels to put between components. [java] import java.applet.*; import java.awt.*; /* <applet code="FlowLayoutApplet" width=300 height=200> </applet> */ public class… Read More »

How to send email from and ANDROID Application programatically?

By | May 16, 2011

Hello all…….. In today’s post I will show you send mail from an android application progrmatically.. Let’s go to the code fast…… This is the code in the mail java file…. [java] package com.coderzheaven; 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; import android.widget.Toast; public class sendMailDemo extends Activity { Button send;… Read More »

ANDROID Tabbars Example……..

By | May 9, 2011

This is a simple example showing how to use tabbars in ANDROID. First create a new project and copy this code to it. [java] package com.coderzheaven; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public class tabbar extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);… Read More »

Using Tabbars in ANDROID, A Simple illustration……….

By | May 9, 2011

This is a simple example showing how to use tabbars in ANDROID. First create a new project and copy this code to it. [java] package com.coderzheaven; import android.app.TabActivity; import android.content.Intent; import android.os.Bundle; import android.widget.TabHost; import android.widget.TabHost.TabSpec; public class tabbar extends TabActivity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);… Read More »