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.

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)


52

ImageView change image Android example | imageview-change-image-android-example


How to change the image dynamically in ImageView and button setOnClickListener Android sample.


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:
android/semafor_red.png
android/semafor_green.png



<?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>






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>

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

	}
}




android/rotate-image-android.png
221

android - OnClickListener must override a superclass method | android-onclicklistener-must-override-a-superclass-method


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

android/project-properties-eclipse.png

android/java-compiler-settings-eclipse.png