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)
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();
}
Check your xml files in Eclipse Graphical Editor and fix problems.
Check project setup, right click on project, select properties, Java build path and
select correct Android version etc.
Right click on project, Android Tools, Fix Project Properties
Menu Eclipse select Project ->Clean.
Check project setup, right click on project, select properties, Java build path and
select correct Android version etc.
Right click on project, Android Tools, Fix Project Properties
Menu Eclipse select Project ->Clean.
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);
R.string to string Android source code
R.array 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>
For and continue statement in Java.
public class MainClass {
public static void main(String[] arg) {
String[] arrayOfString = { "Hello", "people", "hello", "world!" };
for (int i = 0; i < arrayOfString.length; i++){
if(arrayOfString[i].equals("hello"))
continue; // skip to for
System.out.println(arrayOfString[i]);
}
}
}
/*
Hello
people
world!
*/
Editace: 2013-01-27 22:37:38
Počet článků v kategorii: 396
Url:start-an-activity-with-a-parameter-android-example