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.

Write new file or append text Java Android example



BufferedWriter, FileWriter, write, close MODE_APPEND Java and Android example

Write to file Android example

try {
		String MYFILE = "my_file";
		String strText = "My text";

                // MODE_APPEND, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE
		// create new file or rewrite existing
                FileOutputStream fos = openFileOutput(MYFILE, getApplicationContext().MODE_PRIVATE);
                // append to file
                FileOutputStream fos = openFileOutput(MYFILE, getApplicationContext().MODE_APPEND);

		fos.write(strText.getBytes());
		fos.close();					
	} catch (IOException e) {
		e.toString();
    }	




Write to file Java example

try {
// new file    
BufferedWriter out = new BufferedWriter(
    		new FileWriter("outfilename"));
    // append text 
   BufferedWriter out = new BufferedWriter(new FileWriter("outfilename", true));
    out.write("some text");
    out.close();
 } catch (IOException e) {
   e.toString();
}			

397LW NO topic_id



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


348

Android Studio lock unlock file make read only or writable | android-studio-lock-unlock-file-make-read-only-or-writable


Select file in project explorer
Menu:
File - Make File Read-only - to lock
File - Make File Writable - to unlock

android-studio-lock-unlock-file.png
43

No title bar Android application without titlebar style Theme NoTitleBar Android example | no-title-bar-android-application-without-titlebar-style-theme-notitlebar-android-example


Set in AndroidManifest.xml android:theme="@android:style/Theme.NoTitleBar" AndroidManifest.xml example source code.
AndroidManifest.xml


<manifest xmlns:android="//schemas.android.com/apk/res/android"
    package="com.myexample.without_titlebar">
    <application android:label="My app">
      <activity android:name="NoTitleBar"
        android:theme="@android:style/Theme.NoTitleBar"
        android:screenOrientation="portrait"
        android:configChanges="keyboardHidden|orientation">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

362

No executable code found at line - omits breakpoints | no-executable-code-found-at-line-omits-breakpoints


No executable code found at line ....
Try one from this solution:
1.) uninstall app from test device, try to debugg app
or
2.) open module gradle file and set minifyEnabled to false in debug condition

debug {
minifyEnabled false
}
314

Import project Android Eclipse | import-project-android-eclipse


Import a new Android project for example downloaded from internet via Eclipse into project folder.

  1. Right click into projects explorer in Eclipse and select Import

  2. Android

  3. Existing Android Code Into Workspace

  4. Root Directory (select folder of downloaded project)

  5. Check your downloaded project

  6. Check Copy project into Workspace

  7. Finish (press)




56

Change background color dynamically View TableRow setBackgroundColor Android example | change-background-color-dynamically-view-tablerow-android-example


How change background color of View Android sample.

MainActivity.java

public class MainActivity extends Activity {
TextView hTextView;
TableRow hTableRow;
Button hButton, hButtonStop;
private Handler mHandler = new Handler();
private int nCounter = 0;
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        hTextView = (TextView)findViewById(R.id.idTextView);
        hButton = (Button)findViewById(R.id.idButton);
        hButton.setOnClickListener(mButtonStartListener);
        hTableRow = (TableRow)findViewById(R.id.idTableRow1);


        
        
    } // end onCreate

 View.OnClickListener mButtonStartListener = new OnClickListener() {
	public void onClick(View v) {
           hTableRow.setBackgroundColor(Color.YELLOW);
	}
 };
}





main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="//schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >


<TableLayout android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/tableLayout1">
    <TableRow android:id="@+id/idTableRow1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" android:background="#5655AA">
<TextView  
	android:id="@+id/idTextView"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    />
    
    </TableRow>
</TableLayout>
</LinearLayout>


Editace Jana Žákovská : 2011-10-03 11:09:06
Počet článků v kategorii: 397
Url:write-file-java-android-example
Share
Share
Tweet