Expected resource of type raw drawable
Try insert + before R.drawable.xxxx
// error
InputStream is = context.getResources().openRawResource(R.drawable.app_sample_code);
// ok
InputStream is = context.getResources().openRawResource(+R.drawable.app_sample_code);
396LW NO topic_id
AD
Další témata ....(Topics)
How to change the image dynamically in ImageView and button setOnClickListener Android sample.
Main.java
main.xml
Put into res/drawable this pictures:
Main.java
ipackage cz.okhelp.my_game;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
public class Main extends Activity {
private ImageView hImageViewSemafor;
private Button hButton;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
hImageViewSemafor = (ImageView)findViewById(R.id.idImageViewSemafor);
hButton = (Button) findViewById(R.id.idBtnChangeImage);
hButton.setOnClickListener(mButtonChangeImageListener);
}
View.OnClickListener mButtonChangeImageListener = new OnClickListener() {
public void onClick(View v) {
// setImageResource will change image in ImageView
hImageViewSemafor.setImageResource(R.drawable.semafor_green);
}
};
}
main.xml
Put into res/drawable this pictures:
<?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"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<ImageView
android:src="@drawable/semafor_red"
android:id="@+id/idImageViewSemafor"
android:background="#66FFFFFF"
android:adjustViewBounds="true"
android:maxWidth="47dip"
android:maxHeight="91dip"
android:padding="10dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
TableRow TableLayout table row add delete remove removeview addview get table row index indexOfChild create table row dynamically TextView dynamically Android example
Main.java
main.xml ScrollView, TableLayout, TableRow, TextView Android xml layout 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>
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);
}
}
}
The method onClick(DialogInterface, int) of type new DialogInterface.OnClickListener(){} must override a superclass method.
Try this:
Right click on project
Select Properties
In open dialogue select Java compiler
Set Enable project specific settings
Set Compiler compliance level to 1.6
Try this:
Right click on project
Select Properties
In open dialogue select Java compiler
Set Enable project specific settings
Set Compiler compliance level to 1.6
Very very quick start of Android Emulator from Eclipse.
If will closed Android Emulator all data will saved on disk.
If will reopen Android Emulator, configuration and data will read from disk.
[caption id="attachment_768" align="alignleft" width="300" caption="android-emulator-enable-quick-start"][/caption]
- Go to Eclipse s menu Window -> Android SDK and AVD Manager
- Select Virtual devices
- Select check box Snapshot: Enabled
- Press Edit AVD button.
If will closed Android Emulator all data will saved on disk.
If will reopen Android Emulator, configuration and data will read from disk.
[caption id="attachment_768" align="alignleft" width="300" caption="android-emulator-enable-quick-start"][/caption]
Editace: 2017-04-15 09:49:26
Počet článků v kategorii: 396
Url:expected-resource-of-type-raw-drawable