Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9062943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:51:51+00:00 2026-06-16T15:51:51+00:00

i got home work to do that when i write a country in a

  • 0

i got home work to do that when i write a country in a new activity(forresult)
it will write it in the main activity and the color i write and the new activity will change the text color to what i wrote.
but the Ok and Cancel buttons wont transfer any information searched for solution with no success

MainActivity –

public class MainActivity extends Activity implements OnClickListener {
TextView tvDisplayCountry;
Random crazy;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_main);

    initsialize();

}

private void initsialize() {
    Button bAddCountry = (Button) findViewById(R.id.bAddCountry);
    bAddCountry.setOnClickListener(this);
    tvDisplayCountry = (TextView) findViewById(R.id.tvDisplayCountry);
    // ImageView ivCountryPhoto =
    // (ImageView)findViewById(r.id.ivCountryPhoto);
}

@Override
public void onClick(View v) {

    switch (v.getId()) {

    case R.id.bAddCountry:
        Intent countryactivityIntent = new Intent(MainActivity.this,
                CountryActivity.class);
        startActivityForResult(countryactivityIntent, 12);

        break;
    }

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {


    switch(resultCode){
    case 12:
        if (resultCode == Activity.RESULT_OK) {
            String Country = data.getStringExtra("country");
            String Color = data.getStringExtra("color");
            tvDisplayCountry.setText(Country);
            if (Color.equalsIgnoreCase("blue")) {
                tvDisplayCountry.setTextColor(android.graphics.Color.BLUE);
            } else if (Color.equalsIgnoreCase("yellow")) {
                tvDisplayCountry
                .setTextColor(android.graphics.Color.YELLOW);
            } else if (Color.equalsIgnoreCase("gray")) {
                tvDisplayCountry.setTextColor(android.graphics.Color.GRAY);
            } else if (Color.equalsIgnoreCase("red")) {
                tvDisplayCountry.setTextColor(android.graphics.Color.RED);
            }
            else{
                Toast.makeText(MainActivity.this, "canceld", Toast.LENGTH_SHORT).show();
            }
            break;
        }
    }

    super.onActivityResult(requestCode, resultCode, data);
}

}

CountryActivity –

public class CountryActivity extends Activity implements OnClickListener {
EditText etCountry, etColor;
String getCountry, getColor;
Button bOk,bCancel;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.activity_country);



    init();


}

private void init() {
    etColor = (EditText)findViewById(R.id.etColor);
    etCountry = (EditText)findViewById(R.id.etCountry);
    bOk = (Button)findViewById(R.id.bOk);
    bCancel = (Button)findViewById(R.id.bCancel);
    bOk.setOnClickListener(this);
    bCancel.setOnClickListener(this);


}

@Override
public void onClick(View v) {

    switch (v.getId()) {
    case R.id.bOk:
        Intent myIntet = new Intent();
        getCountry = etCountry.getText().toString();
        myIntet.putExtra("country",getCountry );
        getColor = etColor.getText().toString();
        myIntet.putExtra("color", getColor);

        setResult(Activity.RESULT_OK, myIntet);
        finish();

        break;

    case R.id.bCancel:
        Intent myIntent = new Intent();

        setResult(Activity.RESULT_CANCELED, myIntent);
        finish();
        break;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:51:53+00:00Added an answer on June 16, 2026 at 3:51 pm

    There is an error in your onActivityResult — you switch on the resultCode (which will be RESULT_OK or RESULT_CANCELED, not 12).

    Just change the switch(resultCode) to switch(requestCode).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got an array var assoc_pagine = new Array(); assoc_pagine[home]=0; assoc_pagine[about]=1; assoc_pagine[work]=2; I tried
I've got eclipse workspaces for my full time job and my home test work
ok i got this problem. i have this routes: (code bit change) File:/home/dotcloud/current/config/routes.js exports.routes
I am trying to write a simple perl script that will iterate through the
I do my php work on my dev box at home, where I've got
Homework. Dice Game. I've got an array that represents five rolls of a die.
I recently got my home PC upgraded to a quad-core CPU and 64-bit OS.
I've got blocks of text with various specs in them and want to have
I know that I am missing something simple here. I have got this homework
I've got a rake task that renames a bunch of stuff in various files.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.