I recently moved to Android from Python and am stuck here.
This is my class declaration to create a common function for an Alert Dialog which accepts necessary parameters:
public static AlertDialog.Builder getAlertDialog(String strArray[], String strTitle, Activity v) { return new AlertDialog.Builder(v) .setTitle(strTitle).setItems(strArray, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); }
But I cannot call this function via this piece of code which gives me an error:
getAlertDialog(strArray, strTitle, MakeCall.class).show();
The error is:
the method getAlertDialog(String[], String, Activity) in the type MakeCallAlertDialog is not applicable for the arguments (String[], String, Class<TestActivity>)
How can I get this correctly?
String value = A. _utfValue ; Option 3: You can use SharedPreference to save the value and get it from other class. Option 4: You can use a static method with some return value and fetch the method in your java class through class name.
Using Intents This example demonstrate about How to send data from one activity to another in Android using intent. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
ButtonClickBySani(R.id.btnsehrabandi, sehrabandiActivity.class);
private void ButtonClickBySani(int ButtonId, final Class<? extends Activity> ActivityToOpen) { Button btn; // Locate the button in activity_main.xml btn = (Button) findViewById(ButtonId); // Capture button clicks btn.setOnClickListener(new OnClickListener() { public void onClick(View arg0) { startActivity(new Intent(getBaseContext(), ActivityToOpen)); // Start NewActivity.class //Intent myIntent = new Intent(getBaseContext(), ActivityToOpen); // startActivity(myIntent); } }); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With