ANDROID problems
ANDROID problems
<Button
android:id="@+id/btnSelfCall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Call Self Activity" />
<Button
android:id="@+id/btnNewActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Call New Activity" />
</LinearLayout>
Java Code (MainActivity.java):
package com.example.intentexample;
import android.content.Intent;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
AISHA SIDDIQUA BCA 5th E Roll no 5
import android.view.View;
import android.widget.Button;
btnSelfCall.setOnClickListener(view -> {
Intent selfIntent = new Intent(MainActivity.this, MainActivity.class);
startActivity(selfIntent);
});
btnNewActivity.setOnClickListener(view -> {
Intent newIntent = new Intent(MainActivity.this, SecondActivity.class);
startActivity(newIntent);
});
}
}
Java Code (SecondActivity.java):
package com.example.intentexample;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
}
}
Output –
AISHA SIDDIQUA BCA 5th E Roll no 5
<Button android:id="@+id/btnSendEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send Email" />
<Button android:id="@+id/btnSendSMS"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send SMS" />
<Button android:id="@+id/btnMakeCall"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Make Call" />
<Button android:id="@+id/btnOpenURL"
AISHA SIDDIQUA BCA 5th E Roll no 5
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Open URL" />
</LinearLayout>
Java Code (MainActivity.java):
package com.example.implicitintentapp;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
btnSendEmail.setOnClickListener(view -> {
Intent emailIntent = new Intent(Intent.ACTION_SENDTO,
Uri.fromParts("mailto", "[email protected]", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message");
startActivity(Intent.createChooser(emailIntent, "Send Email"));
});
AISHA SIDDIQUA BCA 5th E Roll no 5
btnSendSMS.setOnClickListener(view -> {
Intent smsIntent = new Intent(Intent.ACTION_SENDTO,
Uri.parse("smsto:1234567890"));
smsIntent.putExtra("sms_body", "Hello, this is a test message.");
startActivity(smsIntent);
});
btnMakeCall.setOnClickListener(view -> {
Intent callIntent = new Intent(Intent.ACTION_DIAL,
Uri.parse("tel:1234567890"));
startActivity(callIntent);
});
btnOpenURL.setOnClickListener(view -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.example.com"));
startActivity(browserIntent);
});
}
}
X`Output –
AISHA SIDDIQUA BCA 5th E Roll no 5
AISHA SIDDIQUA BCA 5th E Roll no 5
<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_marginBottom="20dp" />
<Button
android:id="@+id/btnChangeImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next Image" />
</LinearLayout>
Java Code (MainActivity.java):
package com.example.imageviewapp;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
AISHA SIDDIQUA BCA 5th E Roll no 5
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnChangeImage.setOnClickListener(view -> {
currentIndex = (currentIndex + 1) % images.length;
imageView.setImageResource(images[currentIndex]);
});
}
}
Output –
AISHA SIDDIQUA BCA 5th E Roll no 5
AISHA SIDDIQUA BCA 5th E Roll no 5
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Java Code (MainActivity.java):
package com.example.listviewapp;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
Output –