Start an new Activity Intent with a parameter Android example
putString(), putBoolean(), putInt() etc.¨
How we can start an activity programmatically.
How we can start an activity programmatically.
// MainActivity.java
// myButton.setOnClickListener
Intent binary = new Intent(getApplicationContext(),Calculate.class);
Bundle b = new Bundle();
b.putString("prvni_label", "Decimal");
b.putString("druhy_label", "Binary");
b.putString("mode", "binary_to_decimal");
binary.putExtras(b);
startActivityForResult(binary, 0);
// in Calculate.java onCreate
TextView mTextView1 = (TextView)findViewById(R.id.textView1);
TextView mTextView2 = (TextView)findViewById(R.id.textView2);
Bundle _bundle = getIntent().getExtras();
mTextView1.setText(_bundle.getString("prvni_label"));
mTextView2.setText(_bundle.getString("druhy_label"));
//.................. HOW OPEN START NEW ACTIVITY WITHOUT A PARAMETER .........................
startActivity(new Intent(ThisActivity.this, NewActivity.class));
396LW NO topic_id
AD
Další témata ....(Topics)
Issue: Cropped superscript index between tags sup /sup is not correctly visible in TextView or View as Button.
String s = "10<sup>12 </sup>";
textView.setText(Html.fromHtml(s)); // 12 will cropped
// solution:
s = "10<sup>12 </sup>\t "; // add behind ending of sup tag the tabulator \t,
// but not char \t but only press to TAB key!!! in source code
textView.setText(Html.fromHtml(s)); // 12 is visible correctly
private SensorManager mSensorManager;
private PowerManager mPowerManager;
private WindowManager mWindowManager;
private Display mDisplay;
// onCreate
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Get an instance of the SensorManager
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
// Get an instance of the PowerManager
mPowerManager = (PowerManager) getSystemService(POWER_SERVICE);
// Get an instance of the WindowManager
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
mDisplay = mWindowManager.getDefaultDisplay();
setContentView(R.layout.main); // main.xml or your xml file name
}
public static Bitmap createBitmap (int[] colors, int offset, int stride, int width, int height, Bitmap.Config config)
public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)
public void drawBitmap (Bitmap bitmap, float left, float top, Paint paint)
// //www.apache.org/licenses/LICENSE-2.0
public class MainActivity extends Activity {
private static final int WIDTH = 50;
private static final int HEIGHT = 50;
private static final int STRIDE = 64; // must be >= WIDTH
private static int[] createColors() {
int[] colors = new int[STRIDE * HEIGHT];
for (int y = 0; y < HEIGHT; y++) {
for (int x = 0; x < WIDTH; x++) {
int r = x * 255 / (WIDTH - 1);
int g = y * 255 / (HEIGHT - 1);
int b = 255 - Math.min(r, g);
int a = Math.max(r, g);
colors[y * STRIDE + x] = (a << 24) | (r << 16) | (g << 8) | b;
}
}
return colors;
}
@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.GREEN);
int[] mColors = createColors();
int[] colors = mColors;
Bitmap bitmap = Bitmap.createBitmap(colors, 0, STRIDE, WIDTH, HEIGHT,
Bitmap.Config.RGB_565);
canvas.drawBitmap(bitmap, 50,20, paint);
}
}
}
If project is in workspace and only not visible in project explorer using this:
Click on some project in project explorer
Menu:
File
Import project
Existing Projects into Workspace
Shortcut
Windows
Ctrl + Alt + L (format selection or all page)
Ctrl + Alt + Shift + L (show a dialog)
Linux
Ctrl + Windows Key + Alt + L
From menu Code
Code > Reformat Code
Windows
Ctrl + Alt + L (format selection or all page)
Ctrl + Alt + Shift + L (show a dialog)
Linux
Ctrl + Windows Key + Alt + L
From menu Code
Code > Reformat Code
Editace: 2013-01-27 22:37:38
Počet článků v kategorii: 396
Url:start-an-activity-with-a-parameter-android-example