0% found this document useful (0 votes)
18 views2 pages

Central Central: // Search For The Target String in The Array

The document contains code for an Android application that handles intents, searches arrays, calculates change, and builds interfaces with buttons, text views, and spinners. It includes layout code and Java code to populate and interact with the user interface elements.

Uploaded by

phlwin722
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Central Central: // Search For The Target String in The Array

The document contains code for an Android application that handles intents, searches arrays, calculates change, and builds interfaces with buttons, text views, and spinners. It includes layout code and Java code to populate and interact with the user interface elements.

Uploaded by

phlwin722
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Intent y = getIntent();

String destinationn = y.getStringExtra("destini");


String arrivall = y.getStringExtra("arriv");

String [] array={"Central Terminal","Muzon","San jose","Dulong


Bayan","Binay","4B","Bulacan State University","Starmall"};
// Search for the target string in the
array int arrivalll = -1; int destiniii = -
1;

// this is to count of length of array


for (int i = 0; i < array.length; i++){
// this check if the equal or not
if (array[i].equals(destinationn)){
destiniii = i; break;
}
}
/////////////////////////////////////////////////////////////////////////////////////////
Button central; central = (Button) findViewById(R.id.central);
Toast.makeText(MainActivity2.this,"Same route are not allowed",Toast.LENGTH_LONG).show();
Intent y = new Intent(MainActivity2.this, MainActivity4.class);
startActivity(y);
int [] demomination = {1000,500,200,100,50,20,10,5,1}; int
[] modulusdenimination = new int [demomination.length];
String [] displaymodulust = new
String[demomination.length]; String dis = "";
int amount =
Integer.parseInt(etamount.getText().toString()); for(int i =
0; i < demomination.length; i++){ modulusdenimination[i]
= amount / demomination[i]; amount %=
demomination [i];
}
/////////////////////////////////////////////////////////////////////////////////////////
for (int x = 0; x < demomination.length; x++){
displaymodulust[x] = String.valueOf(demomination[x]) +" :
"+ String.valueOf(modulusdenimination[x]); dis = dis +
displaymodulust[x] + "\n"; tvview.setText(dis);
}
int i =
Integer.parseInt(etvalue.getText().toString()); int
sumresult = 0; if(i > 25){
Toast.makeText(getApplicationContext(),"Maximum of 25", Toast.LENGTH_LONG).show();
}else {
for (int o = i ; o>=0; o--){
sumresult += o; // 5+ 0 = 5 + 4 = 9 + 3 = 12 + 2 = 14 + 1 = 15
}
result.setText(String.valueOf(sumresult));
////////////////////////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="8dp"
android:textSize="16sp"
android:textColor="@android:color/black" />
/////////////////////////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Choose an item:"
android:textSize="18sp" />

<Spinner
android:id="@+id/spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dropdown"
android:popupBackground="@android:color/white"
android:dropDownWidth="match_parent"
android:dropDownHorizontalOffset="0dp"
android:dropDownVerticalOffset="0dp"
android:padding="8dp" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="16dp" />

</LinearLayout>
/////////////////////////////////////////////////////////////////////////////////////////
public class MainActivity extends AppCompatActivity {

private Spinner spinner;


private Button button;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

spinner = findViewById(R.id.spinner);
button = findViewById(R.id.button);

// Create an array adapter for the spinner


ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.items, R.layout.spinner_layout);
adapter.setDropDownViewResource(R.layout.spinner_layout);

// Set the adapter for the spinner


spinner.setAdapter(adapter);

// Set an item selected listener for the spinner


spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position,
long id) {
// Display a toast message with the selected item
Toast.makeText(MainActivity.this, "Selected: " +
parent.getItemAtPosition(position), Toast.LENGTH_SHORT).show();
}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// Do nothing
}
});

// Set a click listener for the button


button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Display a toast message with the selected item
Toast.makeText(MainActivity.this, "Selected: " +
spinner.getSelectedItem(), Toast.LENGTH_SHORT).show();
////////////////////////////////////////////////////////////////////////////////////////
AlertDialog.Builder builer = new AlertDialog.Builder(MainActivity4.this);
builer.setTitle("Confirmation");
builer.setCancelable(false);
builer.setMessage("From: " + destinationn + "\n" + "To: " +arrivall+"\n"+"Quantity: " +
quan.getText().toString());
builer.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Intent y = new Intent(MainActivity4.this,MainActivity3.class);
y.putExtra("destini",destinationn);
y.putExtra("arriv",arrivall);
y.putExtra("quantity",quan.getText().toString());
startActivity(y)

You might also like