Save Instance State if device is rotated
Try this trick.
In AndroidManifest - activity tag write this code
App hold data of a views if will to rotation of device.
In AndroidManifest - activity tag write this code
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
App hold data of a views if will to rotation of device.
<activity
android:name=".Tests_Activity"
android:label="@string/app_name"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
396LW NO topic_id
AD
Další témata ....(Topics)
static boolean mbThemeLight = false;
@Override
public void onCreate(Bundle savedInstanceState) {
if(mbThemeLight)
setTheme(android.R.style.Theme_Light);
super.onCreate(savedInstanceState);
// bla bla bla..........
}
private void switchTheme(){
mbThemeLight = true;
this.recreate();
}
LayoutLib is too recent. Update your tool!
Eclipse Android Graphical layout resolving problem.
Eclipse Android Graphical layout resolving problem.
- Open in Eclipse menu Help ->Check for Updates
- Select updates:
- Press Next and update all
- Restart Eclipse
[caption id="attachment_596" align="alignleft" width="300" caption="Restart Eclipse if updates finished."][/caption]
BufferedReader , FileReader, StringBuilder , readLine, close Java example
Android example
Java example
Android example
String MYFILE = "my_file";
FileInputStream fis = openFileInput(MYFILE);
int c; String sText = "";
while((c=fis.read())!=-1)
{
sText += (char)c; // convert int to char
}
fis.close();
Java example
try {
BufferedReader in = new BufferedReader(new FileReader("myfile.txt"));
StringBuilder strBuilder = new StringBuilder();
String str;
while ((str = in.readLine()) != null) {
strBuilder.append(str);
}
in.close();
} catch (IOException e) {
e.toString();
}
Codec, compress(), CompressFormat, quality, decodeByteArray(), Android example source code with image.
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static Bitmap codec(Bitmap src, Bitmap.CompressFormat format,
int quality) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
src.compress(format, quality, os);
byte[] array = os.toByteArray();
return BitmapFactory.decodeByteArray(array, 0, array.length);
}
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.GRAY);
// you need to insert some image flower_blue into res/drawable folder
Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.flower_blue);
// Best of quality is 80 and more, 3 is very low quality of image
Bitmap bJPGcompress = codec(b, Bitmap.CompressFormat.JPEG, 3);
// get dimension of bitmap getHeight() getWidth()
int h = b.getHeight();
canvas.drawBitmap(b, 10,10, paint);
canvas.drawBitmap(bJPGcompress, 10,10 + h + 10, paint);
}
}
}
R.string.app_name to String example.
MyActivity.java
res/values/string.xml
MyActivity.java
Resources res = getResources();
String sText = res.getString(R.string.app_name);
res/values/string.xml
<resources>
<string name="app_name">My app name</string>
</resources>
Editace: 2016-03-12 18:53:26
Počet článků v kategorii: 396
Url:save-instance-state-if-device-is-rotated