Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App (2014) Testing and Debugging Toast Notifications

Eleni Minadaki
Eleni Minadaki
3,687 Points

Automatic change the OnClick() method.

Hi!Have some problems after the lesson with the "Toast", 1.On ClickListener() the right as shows at the lesson is this: View.OnClickListener listener = new View.OnClickListener() BUT when the file closed(have saved the result)the next time i open is automatic this: View.OnClickListener listener = (view)and an arrow only 2)Can't see the result of the Toast and 3)Can't find my mobile which have connect with usb in laptop.On choose running device shows nothing. For be more understandable here is all my code: package com.allyouask.thoughtoftheday;

import android.app.Activity; import android.graphics.Color; import android.support.v7.app.ActionBarActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast;

import java.util.Random;

public class ThoughtOfTheDayActivity extends Activity { private FactBook mFactBook = new FactBook(); private ColorWheel mColorWheel = new ColorWheel();

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_thought_of_the_day);
    final TextView factLabel = (TextView) findViewById(R.id.factTextView);
    final Button showFactButton = (Button) findViewById(R.id.showFactButton);
    final RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativeLayout);
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
        String fact = mFactBook.getFact();

            factLabel.setText(fact);

            int color = mColorWheel.getColor();
            relativeLayout.setBackgroundColor(color);
            showFactButton.setTextColor(color);
        }
    };
    showFactButton.setOnClickListener(listener);

 Toast.makeText(this, "Yay!our activity was created!", Toast.LENGTH_LONG).show();

}

} Thanks for any help!

2 Answers

Hello,

For your first problem, Android Studio sometimes will collapse code on screen to improve readability. The code is still there as you can see from your copy and paste above. You can expand it back out by clicking on the plus sign near the line numbers.

For your second problem, I don't see any issues on why your toast message wouldn't be showing at first look, maybe once we fix your third problem you'll be able to provide more info.

For the third problem, you will need to enable USB debugging to be able to see your device as a running device. To do this, you'll first need to enable Developer Options in your Settings Menu of your phone by going to Settings -> About Phone and tapping the build number 7 times. Then exit back out to the Settings menu and go to Developer Options, enable Developer Options if it is disabled, then turn on Enable USB Debugging. You should then be able to see your phone as a running device. If not, we can try more troubleshooting, but I'd need to know your Operating System.

Once you are able to see your device, could you try seeing if you can see the Toast message again, it should only appear once when you first start the application.

Eleni Minadaki
Eleni Minadaki
3,687 Points

Hi James! Thank you for your very good explanation. It works!and my second problem fix also.