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");
			}
		}

	}



397LW NO topic_id



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


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);
           
		}

	}
}




rotate bitmap android
51

Get assets folder files to array of strings Android example | get-assets-folder-files-to-array-of-strings-android-example


Get assets folder files to array of strings.
Its show files in assets folder and sub folders:


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final AssetManager assetManager = getAssets();
        try {
			// for assets folder add empty string
                        String[] filelist = assetManager.list("");
                        // for assets/subFolderInAssets add only subfolder name
                        String[] filelistInSubfolder = assetManager.list("subFolderInAssets");
			if (filelist == null) {
			    // dir does not exist or is not a directory
			} else {
			    for (int i=0; i<filelist.length; i++) {
			        // Get filename of file or directory
			        String filename = filelist[i];
			    }
			}
                     
                        // if(filelistInSubfolder == null) ............  

		} catch (IOException e) {
			e.printStackTrace();
		}
     }


373

FrameLayout fragment not visible Android | framelayout-fragment-not-visible-android


ListFragment show only one item issue

Try to change layout_width to 0dp

   <fragment android:name="cz.okhelp.android.fragchangfromlist.ArticleFragment"
              android:id="@+id/article_fragment"
              android:layout_weight="2"
              android:layout_width="0dp"
              android:layout_height="match_parent" />
<!--todo LAYOUT_WIDTH have to be 0dp !!!!!!!!!!!!!!!!!!!!! -->

    <FrameLayout android:id="@+id/article_fragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="2" />
248

Set Custom Font to View Android Example | set-custom-font-to-view-android-example


You have to put your font fonts/samplefont.ttf into assets/fonts folder in your project!

// set own custom font from assets
TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface mFace = Typeface.createFromAsset(getContext().getAssets(),
                                             "fonts/samplefont.ttf");
    txt.setTypeface(mFace);
271

Eclipse - How open deleted project from workspace | eclipse-how-open-deleted-project-from-workspace


If project is in workspace and only not visible in project explorer using this:



Click on some project in project explorer
Menu:
File
Import project
Existing Projects into Workspace




Editace Jana Žákovská : 2016-02-24 09:07:16
Počet článků v kategorii: 397
Url:android-fragment-onattach-deprecated
Share
Share
Tweet