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.

Start Activity from list - launches other activities from list


AD MOB

Activities launcher

public class MainActivity extends ListActivity {
    private class Sample {
        private CharSequence title;
        private Class<? extends Activity> activityClass;

        public Sample(int titleResId, Class<? extends Activity> activityClass) {
            this.activityClass = activityClass;
            this.title = getResources().getString(titleResId);
        }

        @Override
        public String toString() {
            return title.toString();
        }
    }

    private static Sample[] mSamples;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Instantiate the list of samples.
        mSamples = new Sample[]{
                new Sample(R.string.title_first_app, FirstActivity.class),
                new Sample(R.string.title_second_app, SecondActivity.class),
                new Sample(R.string.title_third_app, ThirdActivity.class),
        };

        setListAdapter(new ArrayAdapter<Sample>(this,
                android.R.layout.simple_list_item_1,
                android.R.id.text1,
                mSamples));
    }

    @Override
    protected void onListItemClick(ListView listView, View view, int position, long id) {
        // Launch the sample associated with this list position.
        startActivity(new Intent(MainActivity.this, mSamples[position].activityClass));
    }
}


397LW NO topic_id




AD

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


145

Compressing converting a bitmap to PNG format Android example | compressing-converting-a-bitmap-to-png-format-android-example



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.YELLOW);
            
        
			Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.flower_blue);
             
			Bitmap bPNGcompress = codec(bmp, Bitmap.CompressFormat.PNG, 0);

		   int h = bmp.getHeight();
           
           canvas.drawBitmap(bmp, 10,10, paint);
           canvas.drawBitmap(bPNGcompress, 10,10 + h + 10, paint);
           
		}

	}
}

4

Read file from URL | read-file-from-url


Read file from URL to array of byte and convert to UTF-8 String Android examle source code.

URL urlLoc = new URL("//myweb.com/myfile.html");
URLConnection conexion = urlLoc.openConnection();
conexion.setConnectTimeout(4000);
conexion.setReadTimeout(1000);
conexion.connect();

// downlod the file
InputStream input = new BufferedInputStream(urlLoc
		.openStream());

StringBuffer responseBuffer = new StringBuffer();
byte[] byteArray = new byte[1024];
while (input.read(byteArray) != -1)
 {   
        String res = new String(byteArray, "UTF-8");
        responseBuffer.append(res);
        byteArray = null;
        byteArray = new byte[1024];
 }

String response = responseBuffer.toString().trim();



226

R.string to string R.array to array Android | r-string-to-string-r-array-to-array-android


R.string to string Android source code
R.array to string [] Android source code

String s = getResources().getString(R.string.my_string); // Hello world!!
String[] arrayOfStrings = getResources().getStringArray(R.array.my_array); // one, two


<xml version="1.0" encoding="utf-8">
<resources>
    <string-array name="my_array">
        <item>one</item>
        <item>two</item>
    </string-array>
<string name="my_string">Hello world!!</string>
</resources>
360

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
}
34

How get Android SDK location on PC with Eclipse | how-get-android-sdk-location-on-pc-with-eclipse


How get Android SDK location - PATH on PC from Eclipse tutorial.


  1. Open dialog from menu Window -> AVD and SDK manager

  2. In dialog select Available packages

  3. On top of dialog will displayed similar path: SKD Location: C:\PROGRA~1\Android\android-sdk-windows\





Editace: 2016-02-25 19:32:45
Počet článků v kategorii: 397
Url:start-activity-from-list-launches-other-activities-from-list

AD
11 Share
Share
Tweet