no button feedback in android studio, i just want to guide from one activity to another! :(
no errors
here's the code
public abstract class OrderActivity extends AppCompatActivity {
private Button clickButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
clickButton =(Button) findViewById(R.id.IDbutton2);
clickButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openActivity();
}
});
}
public void openActivity(){
Intent intent = new Intent(OrderActivity.this, orderPage.class);
startActivity(intent);
}
}
using nexus 6 emulator
please help guys
You haven't set a content view, so your OrderActivity has no layout. As such, there is no view with ID IDbutton2. This causes clickButton to be null, and not do anything.
You can see a very similar example in the Android training (I've removed the irrelevant bits):
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void sendMessage(View view) {
Intent intent = new Intent(this, DisplayMessageActivity.class);
startActivity(intent);
}
}
Related
I have three activities A.B and C. I have a button in activity C. My requirement is that the button should only visible when going from activity B to C. The button should be invisble when going from A to C. Please help me.
Activity A
public class A extends AppCompatActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayout);
// TODO: 5/5/2018 consider findViewById
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(A.this, C.class);
intent.putExtra(KEY_EXTRA, FROM_A);
startActivity(intent);
}
});
}
}
Activity B
public class B extends AppCompatActivity {
Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayout);
// TODO: 5/5/2018 consider findViewById
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(B.this, C.class);
intent.putExtra(KEY_EXTRA, FROM_B);
startActivity(intent);
}
});
}
}
Activity C
public class C extends AppCompatActivity {
Button button;
public static int FROM_A = 1;
public static int FROM_B = 2;
public static String KEY_EXTRA = "KEY_EXTRA";
int activityStartedFrom;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourLayout);
// TODO: 5/5/2018 consider findViewById
activityStartedFrom = getIntent().getIntExtra(KEY_EXTRA, FROM_B);
button.setVisibility(activityStartedFrom == FROM_B ? View.VISIBLE : View.GONE);
}
}
ANSWERED
I am trying to send and int to another activity.There is a button in first act. and it opens second act. and takes int from here to other page.But i cant start two of them at one time.
Here is my first activity :
public class ana_ekran extends AppCompatActivity {
public TextView ana_ekran_kule;
public TextView ana_ekran_can;
public int ana_ekran_can_int=30;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ana_ekran);
ana_ekran_kule=(TextView) findViewById(R.id.textView);
ana_ekran_can=(TextView) findViewById(R.id.textView2);
ana_ekran_can.setText(ana_ekran_can_int+" CAN");
}
public void devam (View v){
Intent i = new Intent(getApplicationContext(),fight_1.class);
i.putExtra("deger", ana_ekran_can_int);
startActivity(i);
startActivity(new Intent(this,fight_1.class));
}
}
and this is second:
public class fight_1 extends AppCompatActivity {
public TextView fight_1_can;
public int fight_1_can_int;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fight_1);
fight_1_can=(TextView) findViewById(R.id.textView3);
int i = getIntent().getIntExtra("deger",-1);
fight_1_can_int=i;
fight_1_can.setText(fight_1_can_int+"");
}
}
This startActivity(i); will do the same thing as next line but it will carry the data as well whereas startActivity(new Intent(this,fight_1.class)); will only start the other instance of fight_1 activity so
public void devam (View v){
Intent i = new Intent(getApplicationContext(),fight_1.class);
i.putExtra("deger", ana_ekran_can_int);
startActivity(i);
// start fight_1 again without any data so not required
//startActivity(new Intent(this,fight_1.class));
}
I just wanted to create an application that works like an HTML page or something. Just after clicked button, new site is opening.
I don't know why there are 5 errors: 2 Errors:(15, 11 and 15,18) error: illegal start of expression, and 2 Errors:(15, 31 and 15,41) error: ';' expected.
Here's the code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
{
public void nextStep(View view) {
Intent i = new Intent(this, SecondaryActivity.class);
startActivity(i);
}
}
}
Coud you help me? :/
your message is not formated
It shows like if
{ public void nextStep(View view) {Intent i = new Intent(this, SecondaryActivity.class);startActivity(i); }
is inside you onCreate function,
if true, you can't write a function inside another function
There was problem with bracket.Try this
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void nextStep(View view) {
Intent i = new Intent(this, SecondaryActivity.class);
startActivity(i);
}
}
I am using the library scringo on Android. "openChat" function doesn't seem to be working. It does absolutely nothing. Here is my code.
I read through their API:
http://www.scringo.com/docs/api/android/
openChat function should open the 1-on-1 chat with the other user. But that doesnt happen. Nothing happens. All the other functions are working fine.
It doesn't even log any errors or warning.
public class MainActivity extends Activity implements OnClickListener {
private Scringo scringo;
private Activity mainactivity;
private Button button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mainactivity = this;
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(this);
Scringo.setAppId("MY-APP-ID");
Scringo.setDebugMode(true);
scringo = new Scringo(this);
scringo.init();
scringo.addSidebar();
Scringo.loginWithEmail("a#testapp.com", "hi", new ScringoSignUpListener(){
#Override
public void onError(String arg0) {
}
#Override
public void onSuccess(String arg0) {
Log.w("user",Scringo.getUserId());
}
});
}
#Override
public void onClick(View arg0) {
//I am using the ID of another user.
//This does not work. Nothing happens. No error or warning either.
Scringo.openChat(this, "Qk8vJs4fRE");
//This works fine.
//Scringo.openChatRooms(this);
}
}
You should call the openChat after getting the user:
Scringo.getUserByScringoId("SOME_ID...", new ScringoGetUserListener() {
#Override
public void gotUser(ScringoUser user) {
Scringo.openChat(MainActivity.this, "SOME_ID...");
}
});
i got 2 java files app.java and gallaery.java
App.java
public class App extends Activity implements OnClickListener {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button Listvideo = (Button) findViewById(R.id.Listvideo);
Listvideo.setOnClickListener(this);
public void onClick(View view) {
if (view == findViewById(R.id.Listvideo)) {
// i have to call gallery.java here which executes list of images in the android pone
}
}
Assuming Gallery.java also extends Activity you should call:
Intent mIntent = new Intent(this, Gallery.class);
startActivity(mIntent);