package nidhin.survey;
import android.app.Activity;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import android.os.Bundle;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioGroup;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.TextView;
public class SurveyActivity extends Activity implements OnCheckedChangeListener
{
CheckBox cb;
String myChoice;
RadioButton radio1;
RadioButton radio2;
RadioButton radio3;
RadioButton radio4;
RadioGroup rg;
EditText text1;
Button button1;
Button button2;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cb=(CheckBox)findViewById(R.id.check);
cb.setOnCheckedChangeListener(this);
RadioGroup rg=(RadioGroup)findViewById(R.id.rg);
radio1=(RadioButton)findViewById(R.id.radio1);
radio2=(RadioButton)findViewById(R.id.radio2);
radio3=(RadioButton)findViewById(R.id.radio3);
radio4=(RadioButton)findViewById(R.id.radio4);
// rg.setOnCheckedChangeListener(this);
rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch(checkedId)
{
case R.id.radio1:
myChoice = "one";
text1.setText(myChoice);
break;
case R.id.radio2:
myChoice = "two";
text1.setText(myChoice);
break;
case R.id.radio3:
myChoice = "three";
text1.setText(myChoice);
break;
case R.id.radio4:
myChoice = "four";
text1.setText(myChoice);
break;
}
}
});
text1=(EditText)findViewById(R.id.etext1);
text1.setText(myChoice);
button1 = (Button) findViewById(R.id.button01);
button1.setOnClickListener(new clicker());
button2 = (Button) findViewById(R.id.button02);
button2.setOnClickListener(new clicker());
}
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked)
{
if (isChecked)
{
cb.setText("Yes , I have a car!");
}
else
{
cb.setText(" ");
}
if (isChecked) {
TextView tv= new TextView (this);
tv.setText("You have a car , nice!");
}
}
class clicker implements Button.OnClickListener
{
public void onClick(View v)
{
if(v==button1)
{
text1.setText(myChoice);
Toast.makeText(getBaseContext(),
"~~~~Successfully submitted~~~",
Toast.LENGTH_LONG).show();
}
if(v==button2)
{
Intent viewDataIntent = new Intent(this, Survey2.class);
String myData = "You should see this";
viewDataIntent.putExtra("valueOne", myData);
startActivity(viewDataIntent);
}
}
}
}
Hello , this seems to be a simple problem , but I cannot find a solution somehow. I am trying to pass from one activity to the other in my android application . So when the second button is clicked , the program must load the new activity.The error i get is with the line - Intent viewDataIntent = new Intent(this, Survey2.class); it says that the constructor Intent(SurveyActivity.clicker, Class) is undefined. Any ideas?
Intent viewDataIntent = new Intent(this, Survey2.class);
should be
Intent viewDataIntent = new Intent(SurveyActivity.this, Survey2.class);
because SurveyActivity.this is your actual Context.
Intent viewDataIntent = new Intent(getApplicationContext(), Survey2.class);
startActivity(viewDataIntent );
Note you are creating new Intent object into View.OnClickListener class, so this is reference of OnClickListener, whereas
public Intent (Context packageContext, Class cls) need a context object as first parameter, so do instead:
Intent viewDataIntent = new Intent(v.getContext(), Survey2.class);
String myData = "You should see this";
viewDataIntent.putExtra("valueOne", myData);
startActivity(viewDataIntent);
or
Intent viewDataIntent = new Intent(SurveyActivity.this, Survey2.class);
String myData = "You should see this";
viewDataIntent.putExtra("valueOne", myData);
startActivity(viewDataIntent);
Related
How to pass intent values based on the radio button checked, and intent should be started only after clicking the button,and the values should be passed based on the swith case statement here is my code please help me out..
package com.example.simplemath;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
import android.util.Log;
public class Settings extends Activity {
OnCheckedChangeListener listner = null;
OnCheckedChangeListener listner2 = null;
int level = 0;
int TotalQues = 0;
int click = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
Bundle b = getIntent().getExtras();
click = b.getInt("click");
Typeface custom_font = Typeface.createFromAsset(getAssets(),
"fonts/SofadiOne-Regular.ttf");
Typeface custom_font1 = Typeface.createFromAsset(getAssets(),
"fonts/belligerent.ttf");
TextView heading1 = (TextView) findViewById(R.id.textView1);
heading1.setTypeface(custom_font);
TextView heading2 = (TextView) findViewById(R.id.textView2);
heading2.setTypeface(custom_font);
RadioGroup difficulty = (RadioGroup) findViewById(R.id.radioGroup1);
difficulty.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (group.getCheckedRadioButtonId()) {
case R.id.radioButton1:
Log.d("info", "one");
Intent intent1 = new Intent(Settings.this, Third.class);
level = 1;
intent1.putExtra("level", level);
intent1.putExtra("click", click);
// startActivity(intent1);
break;
case R.id.radioButton2:
Log.d("info", "two");
Intent intent2 = new Intent(Settings.this, Third.class);
level = 2;
intent2.putExtra("level", level);
intent2.putExtra("click", click);
// startActivity(intent2);
break;
case R.id.radioButton3:
Log.d("info", "three");
Intent intent3 = new Intent(Settings.this, Third.class);
level = 3;
intent3.putExtra("level", level);
intent3.putExtra("click", click);
// startActivity(intent2);
break;
}
}
});
RadioGroup NoOfQuestions = (RadioGroup) findViewById(R.id.radioGroup2);
NoOfQuestions.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (group.getCheckedRadioButtonId()) {
case R.id.radioButton4:
Log.d("info", "four");
Intent intent4 = new Intent(Settings.this, Third.class);
Bundle NoTwenty = new Bundle();
TotalQues = 1;
NoTwenty.putInt("NoQuestions", TotalQues);
intent4.putExtras(NoTwenty);
// startActivity(intent4);
break;
case R.id.radioButton5:
Log.d("info", "five");
Intent intent5 = new Intent(Settings.this, Third.class);
Bundle NoThirty = new Bundle();
TotalQues = 1;
NoThirty.putInt("NoQuestions", TotalQues);
intent5.putExtras(NoThirty);
// startActivity(intent5);
break;
case R.id.radioButton6:
Log.d("info", "six");
Intent intent6 = new Intent(Settings.this, Third.class);
Bundle NoFourty = new Bundle();
TotalQues = 1;
NoFourty.putInt("NoQuestions", TotalQues);
intent6.putExtras(NoFourty);
// startActivity(intent6);
break;
}
}
});
RadioButton easy = (RadioButton) findViewById(R.id.radioButton1);
easy.setTypeface(custom_font1);
RadioButton medium = (RadioButton) findViewById(R.id.radioButton2);
medium.setTypeface(custom_font1);
RadioButton hard = (RadioButton) findViewById(R.id.radioButton3);
hard.setTypeface(custom_font1);
RadioButton twenty = (RadioButton) findViewById(R.id.radioButton4);
twenty.setTypeface(custom_font1);
RadioButton thirty = (RadioButton) findViewById(R.id.radioButton5);
thirty.setTypeface(custom_font1);
RadioButton fourty = (RadioButton) findViewById(R.id.radioButton6);
fourty.setTypeface(custom_font1);
Button submit = (Button) findViewById(R.id.button1);
submit.setTypeface(custom_font);
submit.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
startActivity(new Intent(Settings.this, Third.class));
}
});
}
}
Use the following one inside OnClickListener of RadioGroup Button.
AlertDialogBuilder voteBuilder = new AlertDialogBuilder(baseContext);
final Context context = voteBuilder.getThemeContext();
voteBuilder.setTitle("Vote");
LayoutInflater inflater = voteBuilder.getLayoutInflater();
View viewVote = inflater.inflate(R.layout.eip_vote_popup, null, false);
TextView qsnText = (TextView) viewVote.findViewById(R.id.textPollingQuestion);
qsnText.setText(description + "?");
final RadioButton radioPositive = (RadioButton) viewVote.findViewById(R.id.radioPositive);
final RadioButton radioNegative = (RadioButton) viewVote.findViewById(R.id.radioNegative);
if (pollType.equals("AD")) {
radioPositive.setText("Agree");
radioNegative.setText("Disagree");
} else {
radioPositive.setText("Yes");
radioNegative.setText("No");
}
voteBuilder.setView(viewVote);
voteBuilder.setNegativeButton("Cancel", null);
voteBuilder.setPositiveButton("Vote", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
voteBuilder.setCancelable(true);
final AlertDialog dialog = voteBuilder.show();
dialog.setCanceledOnTouchOutside(true);
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!radioPositive.isChecked() && !radioNegative.isChecked()) {
Toast.makeText(context, "Select your opinion", Toast.LENGTH_SHORT).show();
return;
}
//EIPService service = new EIPService(context);
//service.SaveUserPoll(pollingId, radioPositive.isChecked());
dialog.dismiss();
}
});
instead of Service , you call the necessary Intent. Dont use Switch cases,sometimes it arises the problem .
Pease help me with my code.
When i click any button, button1, button2 or button3 opens new activity, but layout is empty, without any text's and others.
Code of activity from calling the new activity:
package com.novator.inweld;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class TentsCatalog extends Activity implements OnClickListener
{
private Button button1;
private Button button2;
private Button button3;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tents_catalog);
button1 = (Button)findViewById(R.id.button1);
button2 = (Button)findViewById(R.id.button2);
button3 = (Button)findViewById(R.id.button3);
button1.setOnClickListener(this);
button2.setOnClickListener(this);
button3.setOnClickListener(this);
}
#Override
public void onClick(View view)
{
if(view == button1)
{
Intent intent = new Intent(this, TentPage.class);
intent.putExtra("tentId", "1");
startActivity(intent);
}
if(view == button2)
{
Intent intent = new Intent(this, TentPage.class);
intent.putExtra("tentId", "2");
startActivity(intent);
}
if(view == button3)
{
Intent intent = new Intent(this, TentPage.class);
intent.putExtra("tentId", "3");
startActivity(intent);
}
}
}
Code of my new activity:
package com.novator.inweld;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class TentPage extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent= getIntent();
String tentId = intent.getStringExtra("tentId");
if(tentId == "1")
{
setContentView(R.layout.tent1);
}
if(tentId == "2")
{
setContentView(R.layout.tent2);
}
if(tentId == "3")
{
setContentView(R.layout.tent3);
}
}
}
use equals(), not ==
if(tentId.equals("1"))
change onClick method with:
#Override
public void onClick(View v)
{
Intent intent = new Intent(this, TentPage.class);
switch (v.getId()) {
case R.id.button1:
intent.putExtra("tentId", "1");
startActivity(intent);
break;
case R.id.button2:
intent.putExtra("tentId", "2");
startActivity(intent);
break;
case R.id.button3:
intent.putExtra("tentId", "3");
startActivity(intent);
break;
default:
break;
}
and use tentId.equals(""); for String check you must use equals() method and for number value use == like:
if(tentId.equals("1"))
{
setContentView(R.layout.tent1);
}
if(tentId.equals("2"))
{
setContentView(R.layout.tent2);
}
if(tentId.equals("3"))
{
setContentView(R.layout.tent3);
}
Java is a b*%$#ch... Use equals():
if(tentId.equals("1")) ...
Also, according to this answer, Android supports Java 1.7's strings in switch statements, meaning you can rewrite your code in a tidier fashion:
switch(tendId) {
case "1": ...
case "2": ...
case "3": ...
}
Keep in mind that the simplest solution would be to pass tendId as an int and not a string:
intent.putExtra("tendId", 1);
int tendId = intent.getIntExtra("tendId");
Replace your TentPage like:
package com.novator.inweld;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class TentPage extends Activity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Intent intent= getIntent();
String tentId = intent.getStringExtra("tentId");
if(tentId.equals("1"))
{
setContentView(R.layout.tent1);
}
if(tentId.equals("2"))
{
setContentView(R.layout.tent2);
}
if(tentId.equals("3"))
{
setContentView(R.layout.tent3);
}
}
}
Hi Im using several Image buttons that are displayed at the bottom of each activity, and I was wondering if there is any way to instantiate the objects outside of their respective activities Oncreate as they do the same thing in each activity but I do not want to be repeating code..
Any advice would be greatly appreciated thanks.
Marc
at the moment i am receiving a null pointer exception when trying to call the build() function.
Here is my menu where tabs will display at the bottom
package koodoo.hcp.plus;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import koodoo.hcp.utilities.Tabbuilder;
public class Hcp_Menu extends Activity implements OnClickListener {
/**
* Stores all the buttons within the HCP_Menu Activity
*/
ImageButton groupBtn;
ImageButton readingBtn;
ImageButton activityBtn;
ImageButton calendarBtn;
ImageButton ongoingBtn;
Context context = this;
View view = new View(this);
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_hcp__menu);
Tabbuilder tb = new Tabbuilder();
tb.build(view, context);
/**
* Create Activity Buttons
*/
//group button
groupBtn = (ImageButton) findViewById(R.id.imageButtonGroup);
groupBtn.setOnClickListener(this);
//reading button
readingBtn = (ImageButton) findViewById(R.id.imageButtonReading);
readingBtn.setOnClickListener(this);
//activity button
activityBtn = (ImageButton) findViewById(R.id.imageButtonActivity);
activityBtn.setOnClickListener(this);
//calendar button
calendarBtn = (ImageButton) findViewById(R.id.imageButtonCalender);
calendarBtn.setOnClickListener(this);
//ongoing button
ongoingBtn = (ImageButton) findViewById(R.id.imageButtonOngoing);
ongoingBtn.setOnClickListener(this);
/**
* create Tab buttons
*//*
//dash tab
dashTab = (ImageButton) findViewById(R.id.dashButton);
dashTab.setOnClickListener(this);
//stats tab
statsTab = (ImageButton) findViewById(R.id.statsButton);
statsTab.setOnClickListener(this);
//invite tab
inviteTab = (ImageButton) findViewById(R.id.inviteButton);
inviteTab.setOnClickListener(this);
//settings tab
settingsTab = (ImageButton) findViewById(R.id.settingsButton);
settingsTab.setOnClickListener(this);
//log tab
logTab = (ImageButton) findViewById(R.id.logButton);
logTab.setOnClickListener(this);*/
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.hcp__menu, menu);
return true;
}
/**
* onclick function for each button on the Activity.
* #param v
*/
#Override
public void onClick(View v) {
Intent i;
switch (v.getId()){
case R.id.imageButtonGroup: i = new Intent(this, Group.class);
startActivity(i);
break;
case R.id.imageButtonActivity: i = new Intent(this, Activities.class);
startActivity(i);
break;
case R.id.imageButtonCalender: i = new Intent(this, Calender.class);
startActivity(i);
break;
case R.id.imageButtonOngoing: i = new Intent(this, Ongoing.class);
startActivity(i);
break;
case R.id.imageButtonReading: i = new Intent(this, Reading.class);
startActivity(i);
break;
default:
break;
}
}
}
Tabbuilder class
package koodoo.hcp.utilities;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.view.View;
import android.widget.ImageButton;
import koodoo.hcp.plus.Hcp_Menu;
import koodoo.hcp.plus.Invite;
import koodoo.hcp.plus.Log;
import koodoo.hcp.plus.R;
import koodoo.hcp.plus.Settings;
import koodoo.hcp.plus.Stats;
/**
* Created by Marc Davies on 18/09/2013.
*/
public class Tabbuilder {
ImageButton dashTab;
ImageButton statsTab;
ImageButton inviteTab;
ImageButton settingsTab;
ImageButton logTab;
public void build(View v, final Context context) {
/**
* create Tab buttons
*/
//dash tab
dashTab = (ImageButton) v.findViewById(R.id.dashButton);
dashTab.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(context, Hcp_Menu.class);
}
});
//stats tab
statsTab = (ImageButton) v.findViewById(R.id.statsButton);
statsTab.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(context, Stats.class);
}
});
//invite tab
inviteTab = (ImageButton) v.findViewById(R.id.inviteButton);
inviteTab.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(context, Invite.class);
}
});
//settings tab
settingsTab = (ImageButton) v.findViewById(R.id.settingsButton);
settingsTab.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(context, Settings.class);
}
});
//log tab
logTab = (ImageButton) v.findViewById(R.id.logButton);
logTab.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(context, Log.class);
}
});
}
}
Create a base activity and instantiate buttons in it. Now let other activities inherit the base activity. Dont forget to handle the layouts properly though
you can make a utils class with static initiate Methods.
Those would take a context and an image and return an imageButton. You would still call that in the onCreate of the corresponding Activity, but you wouldnt have to copy paste your code anymore.
I Have an activty in my app which uses putextra(int) method to pass the value 0 first when the aactivty is started. Then on pressing a next button it passes 6,Subsequently 12 and so on. But the trouble is on pressing the next second time I found that the value of index received using getextras method is 0.Is it cause i am calling the activity from itself . This is the code snippet:
package com.movie;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
public class movielist extends Activity implements OnClickListener{
Button bm[] = new Button[6];
Button nxt,prev;
String namesdb[]=new String[50];
databaseconnect db;
String lang;
int start,index,end;
public 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.mallu_list);
db = new databaseconnect(this);
db.open();
start=this.getIntent().getExtras().getInt("index");
lang =this.getIntent().getExtras().getString("lang");
Toast.makeText(this, start+"", Toast.LENGTH_SHORT).show();
Log.i("info",start+"");
if(!db.isdata(lang))
{
Toast.makeText(this, "No data in Database", Toast.LENGTH_SHORT).show();
finish();
return;
}
end=start+6;
bm[0] = (Button) findViewById(R.id.bm1);
bm[1] = (Button) findViewById(R.id.bm2);
bm[2] = (Button) findViewById(R.id.bm3);
bm[3] = (Button) findViewById(R.id.bm4);
bm[4] = (Button) findViewById(R.id.bm5);
bm[5] = (Button) findViewById(R.id.bm6);
nxt = (Button) findViewById(R.id.nxt);
prev = (Button) findViewById(R.id.prev);
if(start==0)
{
// prev.setBackgroundResource(0);
// prev.setText("");
}
else
prev.setOnClickListener(this);
namesdb = db.getmovie("",lang);
for (int i = 0; start+i < namesdb.length && i<6; i++) {
bm[i].setText(namesdb[start+i]);
bm[i].setOnClickListener(this);
}
int flag=0;
int i=namesdb.length;
Log.i("info",i+"");
Toast.makeText(this, i+"", Toast.LENGTH_SHORT).show();
for(int j=5;j>=i-start;j--)
{
bm[j].setBackgroundResource(0);
flag=1;
}
if(flag==1)
{
// nxt.setBackgroundResource(0);
// nxt.setText("");
}
else
nxt.setOnClickListener(this);
}
#Override
public void onBackPressed() {
// TODO Auto-generated method stub
super.onBackPressed();
Intent myint2 = new Intent(this, list.class);
startActivity(myint2);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bm1:
call(namesdb[start],start,lang);
break;
case R.id.bm2:
call(namesdb[start+1],start,lang);
break;
case R.id.bm3:
call(namesdb[start+2],start,lang);
break;
case R.id.bm4:
call(namesdb[start+3],start,lang);
break;
case R.id.bm5:
call(namesdb[start+4],start,lang);
break;
case R.id.bm6:
call(namesdb[start+5],start,lang);
break;
case R.id.nxt:
int i=namesdb.length;
Intent myint2 = new Intent(this,movielist.class);
myint2.putExtra("index",end);
myint2.putExtra("lang",lang);
startActivity(myint2);
case R.id.prev:
if(start==0)
{
prev.setBackgroundResource(0);
}
else
{
myint2 = new Intent(this,movielist.class);
myint2.putExtra("index",start-6);
myint2.putExtra("lang",lang);
startActivity(myint2);}
break;
}
}
public void call(String name,int start2,String lang) {
Intent myint = new Intent(this, detail.class);
myint.putExtra("nameid", name);
myint.putExtra("index", start2);
myint.putExtra("lang", lang);
startActivity(myint);
}
}
Here's your problem. This part of the switch statement:
case R.id.nxt:
int i=namesdb.length;
Intent myint2 = new Intent(this,movielist.class);
myint2.putExtra("index",end);
myint2.putExtra("lang",lang);
startActivity(myint2);
is missing a break at the end. So it falls through to the next case, which starts the activity with different extras.
I tried to make a signup page in android where I use a reset button that should clear all fields in the page. Please see the code below and correct it as my code is not working.
Button btnreset = (Button) findViewById(R.id.btnreset);
btnreset.setOnClickListener(new View.OnClickListener() {
public void restartActivity(Activity act){
Intent intent=new Intent();
act.finish();
intent.setClass(act, act.getClass());
act.startActivity(intent);
}
}
this is an signup page and fields are first name,last name,user id,password.when user click on reset button it clear all the fields who's filled the user.I'm give a complete source code to you please check this:
package com.boyzcorn.android.fyp;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.content.Intent;
public class signup extends Activity{
public void onCreate(Bundle icicle)
{
super.onCreate(icicle);
setContentView(R.layout.signup);
Button b = (Button) findViewById(R.id.btnClick2);
Button btnreset = (Button) findViewById(R.id.btnreset);
final EditText eText1 = (EditText)findViewById(R.id.firstname);
final EditText eText2 = (EditText)findViewById(R.id.lastname);
final EditText eText3 = (EditText)findViewById(R.id.userid);
final EditText eText4 = (EditText)findViewById(R.id.password);
b.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
{
if(eText1.getText().toString().equals("") ||eText2.getText().toString().equals("") || eText3.getText().toString().equals("") ||eText4.getText().toString().equals(""))
{
Toast.makeText( getApplicationContext(),"Fill Empty Fields",Toast.LENGTH_SHORT ).show();
}
else
{
Intent i = new Intent(signup.this,login.class);
startActivity(i);
}
}
}
});
}
btnreset.setOnClickListener(new View.OnClickListener() {
public void restartActivity(Activity act){
Intent intent=new Intent();
act.finish();
intent.setClass(act, act.getClass());
act.startActivity(intent);
}
}
public void onClick(View arg0) {
}
}
You've only defined the function; you're not calling it. You will need to execute restartActivity(signup.this) from the OnClickListener.
Also, your intent will likely not execute, because its parent has been finished. Perhaps rearranging the lines of code might help, but a better solution would be having the parent activity start it. Try replacing the click listener with:
btnreset.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Activity act = signup.this;
Intent intent = new Intent(act, act.getClass());
act.startActivity(intent);
act.finish();
}
}