Pages

Saturday 8 October 2011

How to highlight text in android?


TextView txtview = (TextView)findViewById(R.id.txtid);
TV.setText("RorRaja Hooda, highlighted, italic", TextView.BufferType.SPANNABLE);
Spannable spantext = (Spannable)txtview.getText();
spantext.setSpan(new BackgroundColorSpan(0xFF00f8), 7, 16, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
TV.setText(spantxt);

How to pick a random image from the sd card?



public void selectRandomImage()
   {
      Cursor c = getContentResolver().query( Images.Media.EXTERNAL_CONTENT_URInullnullnullnull );
      if ( c != null ) {
         int count = c.getCount();
         int position = (int)( Math.random() * count );
         if ( c.moveToPosition( position ) ) {
            long id = c.getLong( c.getColumnIndex( Images.Media._ID ) );
            int orientation = c.getInt( c.getColumnIndex( Images.Media.ORIENTATION ) );
            
            Uri imageUri = Uri.parse( Images.Media.EXTERNAL_CONTENT_URI + "/" + id );
            Bitmap bitmap;
            try {
               bitmap = ImageLoader.loadFromUri( this, imageUri.toString()10241024 );
               mImageView.setImageBitmapReset( bitmap, orientation, true );
            }
            catch ( IOException e ) {
               Toast.makeText( this, e.toString(), Toast.LENGTH_LONG ).show();
            }
         }
         c.close();
         c = null;
         return;
      }
   }



Anyway, if you want to download the source, here is the eclipse source project:
http://blog.sephiroth.it/wp-…/ImageZoom.zip