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 Examples


AD MOB

Code look up at the Api Demos

android_fragments arguments attributes - three fragments on screen
android_fragments_arguments

android_fragments_alert_dialog
android_fragments_alert_dialog.png

android_fragments_context_menu
android_fragments_context_menu.png

android_fragments_custom_animation
android_fragments_custom_animation.png

android_fragments_dialog
android_fragments_dialog.png

android_fragments_dialog_or_activity
android_fragments_dialog_or_activity.png

fragment_hide_show
fragment_hide_show.png

fragment_layout
fragment_layout

fragments_list_array
fragments_list_array.png

fragment_menu
fragment_menu.png

android_fragments_get_result_from_fragment and tabs in two rows
android_fragments_get_result_from_fragment.png

android_fragments_recive_result
android_fragments_recive_result.png

android_fragments_stack
android_fragments_stack.png

fragment_tabs
fragment_tabs.png






397LW NO topic_id




AD

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


77

break statement in Java Android example | break-statement-in-java-android-example


break statement in Java Android basic example

MainClass.java

public class MainClass {
	public static void main(String[] arg) {
		String[] arrayOfString = {"nothing", "Hello", "people"
				, "bye-bye", "hello", "world!", "end" };
		
		for (int i = 0; i < arrayOfString.length; i++) {
				System.out.println(arrayOfString[i]);
				if(i > 2) 
					break; // end of loop
		}
	}
}
/*
nothing
Hello
people
bye-bye
*/
294

Get Bitmap Size Get Free Memory Exception Android | get-bitmap-size-get-free-memory-exception-android


Bitmap size calculation:
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)

Get bitmap size without allocation of memory:

   	BitmapFactory.Options options = new BitmapFactory.Options();
        // If set to true, the decoder will return null (no bitmap), but the out... fields will still
        // be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels. 
    	options.inJustDecodeBounds = true; 
    	BitmapFactory.decodeResource(getResources(), R.drawable.my_image, options);
    	int imageHeight = options.outHeight; // 1024
    	int imageWidth = options.outWidth; // 860
    	String imageType = options.outMimeType; // .jpg .png .gif
 


Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);

    float density = getResources().getDisplayMetrics().density;

    Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
    Debug.getMemoryInfo(memoryInfo);
    final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
    final int freeMemory = (int) (Runtime.getRuntime().freeMemory() / 1024);
    String memMessage = String.format(
        "Free=%d kB,

MaxMem=%d kB,
Memory: Pss=%.2f MB, Private=%.2f MB, Shared=%.2f MB", freeMemory, maxMemory, memoryInfo.getTotalPss() / 1024.0, memoryInfo.getTotalPrivateDirty() / 1024.0, memoryInfo.getTotalSharedDirty() / 1024.0); ((TextView)findViewById(R.id.textViewInfo)).setText(memMessage );
170

webcoreglue(): The real object has been deleted Emulator Error | webcoreglue-the-real-object-has-been-deleted-emulator-error


Error for example:
webcoreglue(2075): The real object has been deleted

Solution:
If this error message shows if orientation the screen is changed
try insert into AndroidManifest.xml this code:
android:configChanges="keyboard|keyboardHidden|orientation"

      <activity
            android:label="@string/app_name"
            android:name=".MyActivity" 
            android:screenOrientation="portrait"
            android:configChanges="keyboard|keyboardHidden|orientation"
            >

38

TableRow TableLayout table row add delete remove removeview addview Android example | tablerow-tablelayout-table-row-add-delete-remove-removeview-addview-android-example


TableRow TableLayout table row add delete remove removeview addview get table row index indexOfChild create table row dynamically TextView dynamically Android example
Main.java

TableLayout table = (TableLayout)findViewById(R.id.table);
TableRow row = (TableRow)findViewById(R.id.row);

// get table row index android.
int nIndex = table.indexOfChild(row);
table.removeView(row); // invisible and height == 0
// add row into same place 
table.addView(row, nIndex); // visible

// add row into certain position
table.addView(row, 3); // visible

// create new TableRow dynamically 
TableRow tr = new TableRow(this);
         tr.setLayoutParams(new LayoutParams(
                        LayoutParams.FILL_PARENT,
                        LayoutParams.WRAP_CONTENT));

// create own function for append TableRow
   private void appendRow(TableLayout table) {
        TableRow row = new TableRow(this);

        TextView hLabel = new TextView(this);
        hLabel.setText("Some text");
        hLabel.setPadding(3, 3, 3, 3);

        TextView hNextLabel = new TextView(this);
        hNextLabel.setText("Next text");
        hNextLabel.setPadding(3, 3, 3, 3);
        hNextLabel.setGravity(Gravity.RIGHT | Gravity.TOP);

        row.addView(hLabel, new TableRow.LayoutParams(1));
        row.addView(hNextLabel, new TableRow.LayoutParams());

        table.addView(row, new TableLayout.LayoutParams());
    }



main.xml ScrollView, TableLayout, TableRow, TextView Android xml layout example

<ScrollView xmlns:android="//schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
    <TableLayout
                android:id="@+id/table"
                  android:layout_width="fill_parent"
                 android:layout_height="fill_parent">
        <TableRow>
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Row index 0"/>
        </TableRow>
        <TableRow android:id="@+id/row">
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Row index 1"/>
        </TableRow>
        <TableRow>
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Row index 2"/>
        </TableRow>
        <TableRow>
            <TextView android:layout_width="wrap_content"
                      android:layout_height="wrap_content"
                      android:text="Row index 3"/>
        </TableRow>
		</TableLayout>
</ScrollView>

343

android.app.Application cannot be cast to android.app.Activity | android-app-application-cannot-be-cast-to-android-app-activity


If you using Context as parameter of function try this solution:

public class MyActivity extends Activity {
// bla bla bla .......
//error 
myFc( getapplicationcontext());
// OK
myFc(MyActivity.this);


Editace: 2017-02-01 12:36:57
Počet článků v kategorii: 397
Url:android-fragment-examples

AD
11 Share
Share
Tweet