Tuesday, March 27, 2012

another simple list

Main.java
-------------------------
package home.customList;

import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class Main extends ListActivity{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        String[] countries = getResources().getStringArray(R.array.countries_array);
        setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,countries));
        ListView listView = getListView();//getListView() from ListActivity //public class ListView
        
        listView.setTextFilterEnabled(true);
    }
}


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

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
    </ListView>

</LinearLayout>

values/country.xml
------------------------------

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string-array name="countries_array">
       
        <item name="bangladesh">bangladesh</item>
        <item name="usa">usa</item>
        <item name="russia">russia</item>
        <item name="england">england</item>
       
    </string-array>
</resources>

Sunday, March 25, 2012

how can create root account in ubuntu

1.open terminal

2.then type
passwd

3.set password for root account.

4.close terminal

5.logout for changing user account

6.choose other user account

7. type user=root
    password=which set in terminal

Sunday, March 4, 2012

customized toast design


ToastActivity.java
------------------------------------------------
///////////////////////////////////////////////////////////
package home.toast;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

public class ToastActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);
       
        LayoutInflater inflater = getLayoutInflater();
        View view = inflater.inflate(R.layout.cust_toast_layout,
                                       (ViewGroup) findViewById(R.id.relativeLayout1));

        Toast toast = new Toast(this);
        toast.setView(view);
        toast.show();

    }
}
///////////////////////////////////////////////////////////


cust_toast_layout.xml
---------------------------------------------------
///////////////////////////////////////////////////////////////

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:id="@+id/relativeLayout1"
  android:background="@android:color/white">

<TextView
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:id="@+id/textView1" android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="Paresh N. Mayani"
    android:gravity="center"
    android:textColor="@android:color/black">
    </TextView>

    <ImageView
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:src="@drawable/images"
    android:layout_below="@+id/textView1"
    android:layout_margin="5dip"
    android:id="@+id/imageView1">
    </ImageView>

    <TextView
    android:id="@+id/textView2"
    android:layout_height="wrap_content"
    android:layout_width="fill_parent"
    android:text="This is the demo of Custom Toast Notification"
    android:gravity="center"
    android:layout_below="@+id/imageView1"
    android:textColor="@android:color/black">
    </TextView>

</RelativeLayout>
////////////////////////////////////////////////////////////////

Friday, March 2, 2012

create directory , read & write file in sd card

FileDemo2.java
----------------------------------------
/////////////////////////////////////////////////////
package com.javasamples;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;

import android.app.Activity;
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 FileDemo2 extends Activity {
// GUI controls
EditText txtData;
Button btnWriteSDFile;
Button btnReadSDFile;
Button btnClearScreen;
Button btnClose;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// bind GUI elements with local controls
txtData = (EditText) findViewById(R.id.txtData);
txtData.setHint("Enter some lines of data here...");

btnWriteSDFile = (Button) findViewById(R.id.btnWriteSDFile);
btnWriteSDFile.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// write on SD card file data in the text box
try {
 
   File testDir= new File("/sdcard/TestDir/");
   // have the object build the directory structure, if needed.
   testDir.mkdirs();
 
 
File myFile = new File("/sdcard/TestDir/mysdfile.txt");
myFile.createNewFile();
FileOutputStream fOut = new FileOutputStream(myFile);
OutputStreamWriter myOutWriter =
new OutputStreamWriter(fOut);
myOutWriter.append(txtData.getText());
myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(),
"Done writing SD 'mysdfile.txt'",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}// onClick
}); // btnWriteSDFile

btnReadSDFile = (Button) findViewById(R.id.btnReadSDFile);
btnReadSDFile.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// write on SD card file data in the text box
try {
File myFile = new File("/sdcard/TestDir/mysdfile.txt");
FileInputStream fIn = new FileInputStream(myFile);
BufferedReader myReader = new BufferedReader(
new InputStreamReader(fIn));
String aDataRow = "";
String aBuffer = "";
while ((aDataRow = myReader.readLine()) != null) {
aBuffer += aDataRow + "\n";
}
txtData.setText(aBuffer);
myReader.close();
Toast.makeText(getBaseContext(),
"Done reading SD 'mysdfile.txt'",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(),
Toast.LENGTH_SHORT).show();
}
}// onClick
}); // btnReadSDFile

btnClearScreen = (Button) findViewById(R.id.btnClearScreen);
btnClearScreen.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// clear text box
txtData.setText("");
}
}); // btnClearScreen

btnClose = (Button) findViewById(R.id.btnClose);
btnClose.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
// clear text box
finish();
}
}); // btnClose

}// onCreate

}// AndSDcard
///////////////////////////////////////////////////////////////////////////////



main.xml
------------------------------------------
///////////////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget28"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ff0000ff"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<EditText
android:id="@+id/txtData"
android:layout_width="fill_parent"
android:layout_height="180px"
android:textSize="18sp"  />

<Button
    android:id="@+id/btnWriteSDFile"
    android:layout_width="143px"
    android:layout_height="wrap_content"
    android:text="1. Write SD File" />

<Button
    android:id="@+id/btnClearScreen"
    android:layout_width="141px"
    android:layout_height="wrap_content"
    android:text="2. Clear Screen" />

<Button
    android:id="@+id/btnReadSDFile"
    android:layout_width="140px"
    android:layout_height="wrap_content"
    android:text="3. Read SD File" />

<Button
    android:id="@+id/btnClose"
    android:layout_width="141px"
    android:layout_height="wrap_content"
    android:text="4. Close" />

</LinearLayout>

///////////////////////////////////////////////////////////////////////////////




mainifest.xml
----------------------------------------------------

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.javasamples"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="7" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

    <application
     
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
         
            android:label="@string/app_name"
            android:name=".FileDemo2" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
 
     

</manifest>

/////////////////////////////////////////////////////////


android usb debugging in ubuntu