Skip to content

Instantly share code, notes, and snippets.

@afifabroory
Created October 16, 2022 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afifabroory/4ec0d36e96c8c2eb4a741ced7a229ed6 to your computer and use it in GitHub Desktop.
Save afifabroory/4ec0d36e96c8c2eb4a741ced7a229ed6 to your computer and use it in GitHub Desktop.
Activity & Intent Challenge
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal|center_vertical"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:id="@+id/text_three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_three"
tools:layout_editor_absoluteX="277dp"
tools:layout_editor_absoluteY="342dp" />
<Button
android:id="@+id/text_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_two"
tools:layout_editor_absoluteX="142dp"
tools:layout_editor_absoluteY="342dp" />
<Button
android:id="@+id/text_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/label_one"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="342dp" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".SecondActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
android:layout_marginBottom="36dp" />
</ScrollView>
package com.example.activityintentchallenge;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.example.activityintentchallenge.databinding.ActivityMainBinding;
public class MainActivity extends AppCompatActivity {
private ActivityMainBinding mainBinding;
private final static String LOG_TAG = MainActivity.class.getSimpleName();
public final static String EXTRA_ACTIVITY_MAIN = "MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainBinding = ActivityMainBinding.inflate(getLayoutInflater());
setButtonOnClickListener();
setContentView(mainBinding.getRoot());
}
private void setButtonOnClickListener() {
mainBinding.textOne.setOnClickListener(view -> {
Log.d(LOG_TAG,"Text One button clicked.");
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra(EXTRA_ACTIVITY_MAIN, 0);
startActivity(intent);
});
mainBinding.textTwo.setOnClickListener(view -> {
Log.d(LOG_TAG,"Text Two button clicked.");
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra(EXTRA_ACTIVITY_MAIN, 1);
startActivity(intent);
});
mainBinding.textThree.setOnClickListener(view -> {
Log.d(LOG_TAG,"Text Three button clicked.");
Intent intent = new Intent(this, SecondActivity.class);
intent.putExtra(EXTRA_ACTIVITY_MAIN, 2);
startActivity(intent);
});
}
}
package com.example.activityintentchallenge;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import com.example.activityintentchallenge.databinding.ActivityMainBinding;
import com.example.activityintentchallenge.databinding.ActivitySecondBinding;
public class SecondActivity extends AppCompatActivity {
private ActivitySecondBinding secondBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
secondBinding = ActivitySecondBinding.inflate(getLayoutInflater());
setContentView(secondBinding.getRoot());
Intent intent = getIntent();
switch (intent.getIntExtra(MainActivity.EXTRA_ACTIVITY_MAIN, 0)) {
case 0:
secondBinding.textView.setText(R.string.text_one);
break;
case 1:
secondBinding.textView.setText(R.string.text_two);
break;
case 2:
secondBinding.textView.setText(R.string.text_three);
}
}
}
<resources>
<string name="app_name">2.1 Challenge</string>
<string name="label_one">Text One</string>
<string name="label_two">Text Two</string>
<string name="label_three">Text Three</string>
<string name="text_three">Pommy ipsum \'tis you \'avin a laugh that\'s ace complete mare roast beef pulled out the eating irons, two weeks on\'t trot farewell gravy cheese and chips jellied eels middle class River Song, jammy git make a brew fish and chips one feels that golly bloke. Bottled it gosh up the duff bow ties are cool queer as a clockwork orange, jellied eels bit of a Jack the lad doolally Northeners get away with ya, well fit completely starkers treacle. Bad Wolf not some sort of dosshouse corgi tad doofer fork out working class, blighty pork scratchings every fortnight rambunctious bow ties are cool.
Marvelous rivetting stuff bent as a nine bob note taking the mick owt terribly Sonic Screwdriver, it\'s me peepers a bit wonky jolly hockey sticks the fuzz on his bill. Cor blimey\' naff one would like curry sauce lost her marbles bloody shambles down South what a load of cobblers because there was nothing on the gogglebox see a man about a dog, bangers and mash easy peasy yorkshire mixture bog off goggledegook chinwag nuthouse cornish pasty. Ey up pigeons in Trafalgar Square clotted cream on the beat posh nosh real ale come hither man and his whippet jolly, oo ecky thump I\'d reet fancy a you mean it ain\'t me noggin\' bog off and thus tosser what a load of cobblers.
Biscuits numpty trouble and strife absolute know your onions ridicule grab a jumper, well chuffed twiglets pie-eyed twiglets squirrel. Know your onions guinness Big Ben scally I\'m off to Bedfordshire fork out, snotty nosed brat and thus eton mess. Kate and Will scones one would like the old bill hadn\'t done it in donkey\'s years, have a gander Shakespeare indeed horses for courses lost her marbles, throw a paddy therewith bread and butter pudding. Manky houlligan Dr. Watson clock round the earhole crumpets The Hounds of Baskerville gobsmacked golly, well fit corgi knackered willy bent as a nine bob note ee bah gum cor blimey\', devonshire cream tea off t\'shop teacakes daft cow a cuppa make a brew.
I could reet fancy a real ale pikey, round our gaff.</string>
<string name="text_two">Bounty belaying pin quarterdeck scuttle grog blossom red ensign hands pillage coxswain heave down. Pressgang long clothes walk the plank pirate driver parley heave down bilge execution dock overhaul. Crack Jennys tea cup scallywag Pirate Round rutters belay bowsprit bring a spring upon her cable Brethren of the Coast clap of thunder Jack Tar.
Furl Buccaneer blow the man down take a caulk tender tackle booty lateen sail killick gangway. Hardtack main sheet crack Jennys tea cup parley fluke tackle Letter of Marque lookout carouser scuppers. Coffer grapple wench no prey, no pay keel lookout Yellow Jack scourge of the seven seas Blimey fire in the hole.
Splice the main brace heave down hulk provost killick Letter of Marque bilge rat flogging grog blossom Chain Shot. Warp to go on account gaff scallywag line man-of-war hands crack Jennys tea cup weigh anchor Sink me. Tender bucko mutiny jury mast sutler snow hornswaggle yard fire ship gabion.</string>
<string name="text_one">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante.
Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante.\n\nLorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Fusce ac turpis quis ligula lacinia aliquet. Mauris ipsum. Nulla metus metus, ullamcorper vel, tincidunt sed, euismod in, nibh. Quisque volutpat condimentum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam nec ante.
Vestibulum sapien. Proin quam. Etiam ultrices. Suspendisse in justo eu magna luctus suscipit. Sed lectus. Integer euismod lacus luctus magna. Integer id quam. Morbi mi. Quisque nisl felis, venenatis tristique, dignissim in, ultrices sit amet, augue. Proin sodales libero eget ante.</string>
</resources>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment