أول مشروع في برنامج اندرويد استديو (android studio) - برمجة واجھة تطبيق الطقس

3 min read 7 months ago
Published on Aug 25, 2025 This response is partially generated with the help of AI. It may contain inaccuracies.

Table of Contents

Introduction

In this tutorial, we will guide you through creating your first project in Android Studio by developing a weather application. This step-by-step guide is perfect for beginners looking to familiarize themselves with Android development concepts and tools.

Step 1: Setting Up Android Studio

  1. Download and Install Android Studio

    • Visit the Android Studio download page.
    • Select the appropriate version for your operating system (Windows, macOS, or Linux).
    • Follow the installation instructions provided on the website.
  2. Start a New Project

    • Open Android Studio.
    • Click on "Start a new Android Studio project."
    • Choose "Empty Activity" as the project template, then click "Next."
  3. Configure Your Project

    • Enter your application name (e.g., "WeatherApp").
    • Set the package name (e.g., "com.example.weatherapp").
    • Choose a save location for your project.
    • Select the language (Java or Kotlin) and the minimum API level.
    • Click "Finish" to create the project.

Step 2: Designing the User Interface

  1. Open the Layout Editor

    • Navigate to res/layout in the project directory.
    • Open the activity_main.xml file.
  2. Add UI Elements

    • Use the Palette to drag and drop elements onto the design surface:
      • TextView for displaying the city name.
      • EditText for user input.
      • Button to trigger the weather update.
      • TextView for displaying the weather information.
  3. Adjust Properties

    • Click on each element and modify its properties in the Attributes panel to customize the appearance and behavior.

Step 3: Implementing Functionality

  1. Open MainActivity File

    • Navigate to the java directory and open MainActivity.java or MainActivity.kt.
  2. Set Up Variables

    • Declare variables for the UI elements:
    EditText cityInput;
    TextView weatherInfo;
    Button fetchWeatherButton;
    
  3. Initialize Elements in onCreate()

    • In the onCreate method, initialize the variables:
    cityInput = findViewById(R.id.city_input);
    weatherInfo = findViewById(R.id.weather_info);
    fetchWeatherButton = findViewById(R.id.fetch_weather_button);
    
  4. Add Button Click Listener

    • Implement an OnClickListener to fetch weather data:
    fetchWeatherButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String city = cityInput.getText().toString();
            fetchWeatherData(city);
        }
    });
    
  5. Create Fetch Weather Data Method

    • Write a method to fetch weather data from an API (you may need to use libraries like Retrofit or Volley):
    private void fetchWeatherData(String city) {
        // API call logic goes here
    }
    

Step 4: Testing Your Application

  1. Run the Application

    • Click on the "Run" button in Android Studio.
    • Choose a virtual device or connect a physical device to test your app.
  2. Interact with the App

    • Enter a city name and click the button to see if the weather data is fetched correctly.

Conclusion

You've now created a basic weather application using Android Studio! This project introduces you to essential concepts like UI design, event handling, and API integration. As next steps, consider exploring more advanced features, such as displaying weather details dynamically or improving the user interface. Happy coding!