Skip to main content

Posts

Showing posts from 2012

Date picker android

Button toDate = (Button) findViewById(R.id.doc_dateto); toDate.setOnClickListener(new OnClickListener() { private int month; private int year; private int day; @Override public void onClick(View v) { OnDateSetListener datePickerListener = null; datePickerListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int selectedYear, int selectedMonth, int selectedDay) { year = selectedYear; month = selectedMonth; day = selectedDay; Calendar c = Calendar.getInstance(); c.set(year, month, day); toDate.setText(c.getTime().toGMTString()); } }; final Calendar c = Calendar.getInstance(); year = c.get(Calendar.YEAR); month = c.get(Calendar.MONTH); day = c.get(Calendar.DAY_OF_MONTH); DatePickerDialog datePicker = new DatePickerDialog( SUP101SampleActivity.this, datePickerListener, year, mo...

Simple and sort Listview example (Android)

private View getChapterLayout() { ListView listView = new ListView(this); listView.setAdapter(new BaseAdapter() { public int getCount() { return chapterdata.size(); } public Object getItem(int position) { return chapterdata.get(position); } public long getItemId(int addressList) { return 0; } public View getView(int position, View convertView, ViewGroup parent) { inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.button_chapter, null); TextView textview = (TextView) convertView .findViewById(R.id.button); textview.setText(chapterdata.get(position).getName()); return convertView; } }); return listView; } // chapterdata is an arrayList // Add Event to each Row  listView.setOnItemClickListener(new OnItemClickListener() { public void onItemClic...

How to set costume fonts in android

1. create  assets/fonts/  and put your TTF files in there: 2.set view's properties. TextView tv =( TextView ) findViewById ( R . id . custom );   Typeface face = Typeface . createFromAsset ( getAssets (), "fonts/ARIAL.ttf" );   tv . setTypeface ( face );

Google Map Api key for Android, JDK6 and JDK 7. and Android Invalid Map API Key

How to get Google Api key? 1. Getting the MD5 Fingerprint of the SDK Debug Certificate   open commnad prompt. Using cd command reach java bin folder ex. cd  C:\Program Files\Java\jdk1.7.0_04\bin> 2. Type following command. For windows  JDK 1.7 keytool -v -list -alias androiddebugkey -keystore "C:\Users\virens\.android\debug.keystore" -storepass android -keypass android jdk 1.6 keytool -list -alias androiddebugkey -keystore "C:\Users\virens\.android\debug.keystore" -storepass android -keypass android other platform Windows Vista:  C:\Users\<user>\.android\debug.keystore Windows XP:  C:\Documents and Settings\<user>\.android\debug.keystore OS X and Linux:  ~/.android/debug.keystore 3.Open below url and create account.Paste that md5 signature.  http://code.google.com/android/maps-api-signup.html Note :  Android Invalid Map API Key I'm willing to bet that you ha...

Get cursor position of Edittext android or How to insert text at cursor position.

You can get the Cursor position using the getSelectionStart() and getSelectionEnd() methods. If no text is highlighted, both getSelectionStart() and getSelectionEnd() return the position of the cursor.  myEditText . getSelectionStart (); or myEditText . getSelectionEnd (); How to insert text at cursor position. int curPos = editText .getSelectionStart(); String str = editText .getText().toString(); String str1 = (String) str.substring(0, curPos); String str2 = (String) str.substring(curPos); editText .setText(str1+ "<br/>" + list1 [which] +str2);

How to increasing heap size of Eclipse Windows & Mac

Windows Go eclipse installed package using file explorer, Open Eclipse.ini file. Modify following detail. Minsize: - Xms24m Maxsize: - Xmx125m increase min & max size according to your pc configuration. Mac OS Go Right click on eclipse icon -> seletct show package contains -> package using file explorer, Open contains/macOS/Eclipse.ini file. Modify following detail. Minsize: - Xms24m Maxsize: - Xmx125m -startup ../../../plugins/org.eclipse.equinox.launcher_1.0.200.v20090520.jar --launcher.library ../../../plugins/org.eclipse.equinox.launcher.cocoa.macosx_1.0.0.v20090519 -product org.eclipse.epp.package.java.product -showsplash org.eclipse.platform --launcher.XXMaxPermSize 256m -vmargs -Dosgi.requiredJavaVersion=1.5 -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts -XX:MaxPermSize=256m -Xms21m //change min size -Xmx64m // change max size -Xdock:icon=../Resources/Eclipse.icns -XstartOnFirstThread -Dorg.eclipse.swt.intern...

How to Create animated drawable.

This is simple example which rotate frame by frame , just you need to create each rotate image ans play one by one. http://developer.android.com/guide/topics/graphics/drawable-animation.html 1.Create animated drawable. <animation-list xmlns:android = " http://schemas.android.com/apk/res/android "     android:oneshot = "true" >     <item android:drawable = "@drawable/rocket_thrust1" android:duration = "200" />     <item android:drawable = "@drawable/rocket_thrust2" android:duration = "200" />     <item android:drawable = "@drawable/rocket_thrust3" android:duration = "200" /> </animation-list> 2. AnimationDrawable rocketAnimation ; public void onCreate ( Bundle savedInstanceState ) {   super . onCreate ( savedInstanceState );   setContentView ( R . layout . main );   ImageView rocketImage = ( ImageView ) findViewById ( R . id . rocket_ima...

Store array of String or int or list in SharedPreferences android

 SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences( this );         JSONArray arr = new JSONArray ();         arr.put( "Viren" );         arr.put( "Android" );         prefs.edit().putString( "key" , arr.toString());         prefs.edit().commit();         try {             arr = new JSONArray (prefs.getString( "key" , "{}" ));             System. out .println(arr.getString(1));          } catch ( JSONException e) {             e.printStackTrace();         }

ProgressDialog example using handler android

final ProgressDialog dialog = ProgressDialog . show ( this , "Title" , "Message" , true ); final Handler handler = new Handler () { public void handleMessage ( Message msg ) { dialog . dismiss (); } } ; Thread t = new Thread () { public void run () { // write process code here. handler . sendEmptyMessage ( 0 ); } } ; t . start ();

local image & text load in webview

public void onCreate ( Bundle savedInstanceState ) {         super . onCreate ( savedInstanceState );         setContentView ( R . layout . main );         WebView view = ( WebView ) findViewById ( R . id . webView1 );         try {         InputStream input = getResources (). openRawResource ( R . raw . lights );         Reader is = new BufferedReader (                 new InputStreamReader ( input , "windows-1252" ));             //InputStream input = getAssets().open("ws.TXT");             int size ;             size = input . available ();             byte [] buffer = new byte [ size ];             input . read ( buffer );     ...