Okhelp.cz

Recepty, články, nápady, programování. Dříve dum-zahrada, finance, internet a know-how.okhelp.cz Pro lepší výsledky hledání používejte i diakritiku.

Android Fragment onAttach deprecated


// Context instead Activity as a parameter
@Override
public void onAttach(Context context) {
    super.onAttach(context);

    Activity a;

    if (context instanceof Activity){
        a=(Activity) context;
    }

}

OnNoteClickedListener listener;
/* old emxample of usage
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		try {
			listener = (OnNoteClickedListener) activity;
		} catch (ClassCastException e) {
			throw new ClassCastException(activity.toString()
					+ " must implement OnNoteClickedListener");
		}
	}
*/
// new version of code
	@Override
	public void onAttach(Context context) {
		super.onAttach(context);

		Activity a;

		if (context instanceof Activity){
			a=(Activity) context;
			try {
				listener = (OnNoteClickedListener) a;
			} catch (ClassCastException e) {
				throw new ClassCastException(a.toString()
						+ " must implement OnNoteClickedListener");
			}
		}

	}



396LW NO topic_id




AD

Další témata ....(Topics)


300

sqlite database get path Android | sqlite-database-get-path-android



Context context = getApplicationContext();
String DB_PATH = "/data/data/"
                + context.getPackageName()
                + "/databases/";
157

Get Resource ID by Resources String Name Android example | get-resource-id-by-resources-string-name-android-example



// image from res/drawable
	int resID = getResources().getIdentifier("my_image", 
			"drawable", getPackageName());
// view
	int resID = getResources().getIdentifier("my_resource", 
			"id", getPackageName());

// string
	int resID = getResources().getIdentifier("my_string", 
			"string", getPackageName());


146

Rotate a image bitmap picture Android example | rotate-a-image-bitmap-android-example


Rotate a bitmap Android source code.

public class MainActivity extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(new SampleView(this));
	}


	private static class SampleView extends View {

		// CONSTRUCTOR
		public SampleView(Context context) {
			super(context);
			setFocusable(true);

		}
		@Override
		protected void onDraw(Canvas canvas) {
			Paint paint = new Paint();
			
			canvas.drawColor(Color.YELLOW);
            
          // Bitmap b = Bitmap.createBitmap(200, 200, Bitmap.Config.ARGB_8888);
			
		    //  you need to insert a image flower_blue into res/drawable folder 
			Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.flower_blue);
			 Matrix mat = new Matrix();
			                mat.postRotate(90);
			                Bitmap bmpRotate = Bitmap.createBitmap(bmp, 0, 0,
			  bmp.getWidth(), bmp.getHeight(),
			  mat, true);
		   int h = bmp.getHeight();
           
           canvas.drawBitmap(bmp, 10,10, paint);
           canvas.drawBitmap(bmpRotate, 10,10 + h + 10, paint);
           
		}

	}
}




android/rotate-image-android.png
179

HTC Incredible 2 | htc-incredible-2


HTC Incredible 2 cena od 6 000 KCZ Kč (únor.2012)
Spokojenost uživatelů nadprůměrná.
HTC Incredible 2 je chytrý telefon s operačním systémem Android.
HTC Incredible 2 je (22.února2012) 7. nejpoužívanějším chytrým telefonem u programu Sky Map viz tabulka.

HTC Incredible 2 - video recense