-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeatherService.java
More file actions
51 lines (37 loc) · 1.6 KB
/
Copy pathWeatherService.java
File metadata and controls
51 lines (37 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.example.trip_packer;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class WeatherService extends AppCompatActivity {
private EditText cityEditText, countryEditText, areaEditText;
private Button searchButton;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_weather_service);
cityEditText = findViewById(R.id.editTextCity);
countryEditText = findViewById(R.id.editTextCountry);
areaEditText = findViewById(R.id.editTextArea);
searchButton = findViewById(R.id.buttonSearch);
searchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String city = cityEditText.getText().toString();
String country = countryEditText.getText().toString();
String area = areaEditText.getText().toString();
openGoogleWeather(city, country, area);
}
});
}
private void openGoogleWeather(String city, String country, String area) {
String searchQuery = "https://www.google.com/search?q=weather+" + city + "+" + area + ",+" + country;
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(searchQuery));
startActivity(intent);
}
}