0% found this document useful (0 votes)
7 views3 pages

Q10

Uploaded by

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

Q10

Uploaded by

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

Q10.

Create an Android application, where the user can enter player name and points in one
view and display it in another view.

//MainActivity

package com.example.pract_10;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

EditText editTextPlayerName, editTextPlayerPoints;


Button buttonSubmit;

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

editTextPlayerName = findViewById(R.id.editTextPlayerName);
editTextPlayerPoints = findViewById(R.id.editTextPlayerPoints);
buttonSubmit = findViewById(R.id.buttonSubmit);

buttonSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String playerName = editTextPlayerName.getText().toString();
String playerPoints = editTextPlayerPoints.getText().toString();

Intent intent = new Intent(MainActivity.this, DisplayActivity.class);


intent.putExtra("playerName", playerName);
intent.putExtra("playerPoints", playerPoints);
startActivity(intent);
}
});
}
}

//DisplayActivity

package com.example.pract_10;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;

public class DisplayActivity extends AppCompatActivity {

TextView textViewDisplay;

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

textViewDisplay = findViewById(R.id.textViewDisplay);

Bundle extras = getIntent().getExtras();


if (extras != null) {
String playerName = extras.getString("playerName");
String playerPoints = extras.getString("playerPoints");

String displayText = "Player Name: " + playerName + "\n" +


"Player Points: " + playerPoints;

textViewDisplay.setText(displayText);
}
}
}

You might also like