Home > Mobile >  Call problem android Second jump and Toast
Call problem android Second jump and Toast

Time:12-04

My android small white, recently encountered in the learning process two very strange questions,
The first question, I added a SecondActivity outside the main activities, and added a few buttons, inside XML code:
 & lt; The Button 
The android: id="@ + id/button_good"
Android: layout_width="0 dp"
Android: layout_height="0 dp"
Android: layout_marginTop="68 dp"
Android: layout_marginBottom="35 dp"
Android: text="this?"
App: layout_constraintBottom_toTopOf="@ + id/textView"
App: layout_constraintEnd_toEndOf="@ + id/textView2"
App: layout_constraintStart_toStartOf="@ + id/button4"
App: layout_constraintTop_toTopOf="parent"/& gt;

The android: id="@ + id/button_he"
Android: layout_width="0 dp"
Android: layout_height="0 dp"
Android: layout_marginEnd="133 dp"
Android: layout_marginRight="133 dp"
Android: layout_marginBottom="32 dp"
Android: text="dormitory to:
"App: layout_constraintBottom_toTopOf="@ + id/textView2"
App: layout_constraintEnd_toEndOf="parent"
App: layout_constraintStart_toEndOf="@ + id/baidu"
App: layout_constraintTop_toBottomOf="@ + id/textView"/& gt;

The android: id="@ + id/button4"
Android: layout_width="wrap_content"
Android: layout_height="wrap_content"
Android: layout_marginStart="9 dp"
Android: layout_marginLeft="9 dp"
Android: layout_marginBottom="34 dp"
Android: text="exit"
App: layout_constraintBottom_toTopOf="@ + id/textView3"
App: layout_constraintStart_toStartOf="@ + id/textView3"
App: layout_constraintTop_toBottomOf="@ + id/textView2"/& gt;

And, the click event is added in the activity, the Java code:
 
The Button b1=(Button) the findViewById (R.i db utton_good), b2=(Button) the findViewById (R.i db utton_he);
The Button b4=(Button) the findViewById (R.i db utton4);
B1. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
Toast. MakeText (SecondActivity. This, "this is not good," Toast. LENGTH_SHORT);
}
});

B2. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
Toast. MakeText (SecondActivity. This reconciliation! "" And Toast. LENGTH_LONG);
}
});

B4. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
Toast. MakeText (SecondActivity. This, "thank you my friends," Toast. LENGTH_SHORT);
finish();
}
});

I jump from the main activities in the past, click on the button, all did not Toast display text,
And the same, I in the MainActivity Settings button corresponding response events also use the Toast of display text, can be normal, according to the following:
 Button b1=(Button) the findViewById (R.i db utton1); 
The Button b2=(Button) the findViewById (R.i db utton2);

B1. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
Toast. MakeText (MainActivity. This, "I am button 1, what are you doing me, button for 2 ah",
Toast. LENGTH_SHORT). The show ();
}
});

B2. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
Toast. MakeText (MainActivity. This, "I am the button 2, what are you doing me, some button 1",
Toast. LENGTH_SHORT). The show ();
}
});

Could you tell me why the second activity after the button click Toast without work?

The second question:
It worked this is happening today (yesterday), I was of the jump button to set the click event is this:
 Button b4=(Button) the findViewById (R.i db utton_tiao); 
B4. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
Intent temperament=new Intent (MainActivity. This, SecondActivity. Class);
/*
Note Intent here, not to use. This activity class instead.
*/
StartActivity (temperament);
}
});

But today, I added a string of jump button:
 Button send_data=https://bbs.csdn.net/topics/(Button) the findViewById (R.i db utton_send_data); 
Send_data. SetOnClickListener (new View. An OnClickListener () {
@ Override
Public void onClick (View v) {
SecondActivity String data="https://bbs.csdn.net/topics/Hello";
Intent temp=new Intent (MainActivity. This, SecondActivity. Class);
Temp. PutExtra (" extra_data ", data);
//to the intention of string message
StartActivity (temp);
}
});

Click on the button, the original is not jump to SecondActivity, after but card program, the App directly to quit, I thought I'm every whole finish,

And, what is more fantastic, I took the string jump after the delete button on the events of the original button clicks or card program, the effect of normal jump to click on the button (send_data that can SecondActivity)
What is this why?
What's the modification method? More want to know why ()

CodePudding user response:

Behind the first problem to solve, I didn't add the show, thank you

The second problem is temporarily not solve

CodePudding user response:

Card program? Flash back, so log?
  • Related