Android where to add the Button? - android

I have probably invested about 10 hours on this mistake xD still cant find it :/
I have basically 3 layouts. The first layout is for the menu/home, the second is a quiz, and the third is the results screen. The problem right now is that I have no idea how to connect the button from the result screen. (has a button to go back to the menu layout). I dont know where I can add this:
Button haupt = (Button) findViewById(R.id.hauptmeldung);
haupt.setOnclickListener(this); //this refers to the one in the QuizActivty,
abschlusslayout = result screen
activtymain = home/menu layout
quizlayout = quiz
Here are my 3 java files:
MainActivity (QuizActivity):
package at.lorenzdirry.philosophenquiz;
import at.lorenzdirry.philosophenquiz.R.id;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class QuizActivity extends Activity implements android.view.View.OnClickListener {
Spiellogik spiel;
Button startbut1;
View myView;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myView = (View)findViewById(id.mainlay);
startbut1= (Button)findViewById(id.startb1);
startbut1.setOnClickListener(this);
spiel = new Spiellogik();
}
public View getTheView(){
return myView;
}
public void onClick(View v) {
int id = v.getId();
if (id == R.id.antwort1)
spiel.auswerten(1, this); // spielAuswerten(1);
else if (id == R.id.antwort2)
spiel.auswerten(2, this); // spielAuswerten(2);
else if (id == R.id.antwort3)
spiel.auswerten(3, this); // spielAuswerten(3);
else if (id == R.id.antwort4)
spiel.auswerten(4, this); // spielAuswerten(4);
else if (id == R.id.startb1)
aufrufen();
else if (id==R.id.hauptmeldung)
Toast.makeText(this, "Leider nichts gewonnen. :-(", Toast.LENGTH_LONG).show();
}
View v;
#Override
public void onBackPressed() {
if(this.findViewById(id.mainlay)==getTheView()){
backButtonHandler();
}
else{
super.onBackPressed();
Intent intent = new Intent(getApplicationContext(), QuizActivity.class);
startActivity(intent);
finish();
}
}
public void backButtonHandler() {
AlertDialog.Builder alertDialog = new AlertDialog.Builder(
QuizActivity.this);
alertDialog.setTitle("Beenden");
alertDialog.setMessage("Sicher Beenden?");
alertDialog.setPositiveButton("Ja",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
alertDialog.setNegativeButton("Nein",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();
}
public void aufrufen(){
setContentView(R.layout.quiz_layout);
for (int n = 1; n <= 4; n++) {
Button btn = null;
switch (n) {
case 1:
btn = (Button) this.findViewById(R.id.antwort1);
btn.setOnClickListener(this);
break;
case 2:
btn = (Button) this.findViewById(R.id.antwort2);
btn.setOnClickListener(this);
break;
case 3:
btn = (Button) this.findViewById(R.id.antwort3);
btn.setOnClickListener(this);
break;
case 4:
btn = (Button) this.findViewById(R.id.antwort4);
btn.setOnClickListener(this);
break;
}
}
spiel.fragen[spiel.aktFrage].anzeigen(this);
}
}
Frage:
package at.lorenzdirry.philosophenquiz;
import at.lorenzdirry.philosophenquiz.R.id;
import android.app.Activity;
import android.widget.Button;
import android.widget.TextView;
class Frage {
private String frage;
private String frage2;
private String frage3;
private String option1;
private String option2;
private String option3;
private String option4;
private int loesung;
public Frage(String f,String f2,String f3, String o1, String o2, String o3, String o4, int l) {
frage = f;
frage2 = f2;
frage3 = f3;
option1 = o1;
option2 = o2;
option3 = o3;
option4 = o4;
loesung = l;
}
public void anzeigen(Activity quizActivity) {
((TextView) quizActivity.findViewById(id.frage)).setText("\u2022 "+frage);
((TextView) quizActivity.findViewById(id.frage2)).setText("\u2022 "+frage2);
((TextView) quizActivity.findViewById(id.frage3)).setText("\u2022 "+frage3);
((Button) quizActivity.findViewById(id.antwort1)).setText(option1);
((Button) quizActivity.findViewById(id.antwort2)).setText(option2);
((Button) quizActivity.findViewById(id.antwort3)).setText(option3);
((Button) quizActivity.findViewById(id.antwort4)).setText(option4);
}
public boolean richtig(int ausgewaehlt) {
if (ausgewaehlt == this.loesung)
return true;
else
return false;
}
}
Spiellogik:
package at.lorenzdirry.philosophenquiz;
import at.lorenzdirry.philosophenquiz.R.id;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import java.util.Random;
class Spiellogik{
final int ANZAHL_FRAGEN = 8;
Frage[] fragen = new Frage[ANZAHL_FRAGEN];
Random r = new Random();
int aktFrage = r.nextInt(ANZAHL_FRAGEN);
int gewinnstufe = 0;
Spiellogik() {
fragen[0] = new Frage("624-546 v.Chr.","Monismus","\"Alles besteht aus Wasser.\"",
"Thales von Milet", "Aristoteles", "Platon", "Immanuel Kant", 1);
fragen[1] = new Frage("\u2248600 v.Chr.","Daoismus","\"Wer andere kennt, ist klug. Wer sich selbst kennt, ist weise.\"",
"Laotse ", "Alkmaion", "Roger Bacon", "Sokrates", 1);
fragen[2] = new Frage("570-495 v.Chr.","a\u00B2+b\u00B2=c\u00B2","\"Vernunft ist unsterblich, alles andere sterblich.\"",
"Pythagoras", "Thomas von Aquin", "Archytas von Tarent", "Platon", 1);
fragen[3] = new Frage("563-483 v.Chr.","Buddhismus","\"Gl\u00fccklich ist, wer sein ich \u00fcberwunden hat.\"",
"Siddharta Gautama (Buddha)", "Anaximenes", "Antiphon aus Athen", "Kleanthes", 1);
fragen[4] = new Frage("551-479 v.Chr.","Konfuzianismus","\"Mache Treue und Aufrichtigkeit zu obersten Prinzipien.\"",
"Konfuzius", "Melissos", "Damaskios", "Panaitios", 1);
fragen[5] = new Frage("535-475 v.Chr.","Monismus","\"Alles flie\u00dft. (panta rhei)\"",
"Heraklit", "Pyrrhon", "Proklos", "Theodoros", 1);
fragen[6] = new Frage("490-420 v.Chr.","Relativismus","\"Der Mensch ist Ma\u00df aller Dinge.\"",
"Protagoras", "Xenokrates", "Zenon von Sidon", "Jamblichos", 1);
fragen[7] = new Frage("460-370 v.Chr.","Atomismus","\"In Wirklichkeit gibt es nur die Atome und das Leere.\"",
"Leukipp", "Epicharmos", "Thales von Milet", "Philolaos", 1);
}
void auswerten(int schalter, Activity quizActivity) {
if (!fragen[aktFrage].richtig(schalter)) { // falsch beantwortet
if (gewinnstufe == 0) {
Toast.makeText(quizActivity, "Leider nichts gewonnen. :-(", Toast.LENGTH_LONG).show();
}
else {
String str = "Sie haben Gewinnstufe " + gewinnstufe + " erreicht! :-) - Glckwunsch!!!";
Toast.makeText(quizActivity, str, Toast.LENGTH_LONG).show();
}
// Schalter deaktivieren
((Button) quizActivity.findViewById(id.antwort1)).setEnabled(false);
((Button) quizActivity.findViewById(id.antwort2)).setEnabled(false);
((Button) quizActivity.findViewById(id.antwort3)).setEnabled(false);
((Button) quizActivity.findViewById(id.antwort4)).setEnabled(false);
} else {
aktFrage= r.nextInt(ANZAHL_FRAGEN);
if (gewinnstufe < 7) {
fragen[aktFrage].anzeigen(quizActivity);
gewinnstufe++;
((TextView) quizActivity.findViewById(id.richtigeFragen)).setText("Richtig beantwortete Fragen : "+gewinnstufe+"/8");
((ProgressBar) quizActivity.findViewById(id.progressBar1)).setProgress(gewinnstufe);
}
else {
gewinnstufe++;
((TextView) quizActivity.findViewById(id.richtigeFragen)).setText("Richtig beantwortete Fragen : " + gewinnstufe + "/8");
((ProgressBar) quizActivity.findViewById(id.progressBar1)).setProgress(gewinnstufe);
quizActivity.setContentView(R.layout.abschluss_layout);
}
}
}
}
I hope you can help me, pls :)

To return on your Menu activity by using a Button :
Button yourbutton = (Button)findViewById(R.id.yourbutton);
yourbutton.setOnClickListener(new OnClickLIstener(){
#Override
public void onClick(View v){
startActivity(new Intent(this,Menu.class));
}
}
Replace all the vars by yours ;)

Related

Convert to AnsyncTask Android

I am new to Android development, I am working on a App and I want to convert my below mentioned code to AnsyncTask. Because it is showing me Run-time error that I am doing too much work on UI thread. Please help me to convert it to AnsyncTask.
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
public class PlayActivity extends AppCompatActivity {
GridView gridview;
TextView textView;
TextView result;
TextView remainingChance;
Button giveup;
Button goback;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.play);
textView = (TextView) findViewById(R.id.blanks);
result = (TextView) findViewById(R.id.result);
remainingChance = (TextView) findViewById(R.id.remainingChance);
giveup = (Button) findViewById(R.id.giveup);
goback = (Button) findViewById(R.id.goback);
goback.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent goBack = new Intent(PlayActivity.this, MainActivity.class);
startActivity(goBack);
}
});
String dash = "";
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String easyArray[] = bundle.getStringArray("easy");
final String randomStr = easyArray[new Random().nextInt(easyArray.length)]; // Getting a random string from Array
giveup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
result.setText(randomStr); // By clicking on Give up button, it displays the actual word & a message Go Back and try again
remainingChance.setText("Go Back and try again");
}
});
final Integer strLength = randomStr.length();
// Creating string with question mark with 2nd and 5th character only
for(int i=1; i<=strLength; i++){
if(i == 2){
dash = dash+Character.toString(randomStr.charAt(1));
} else if (i == 5){
dash = dash+ Character.toString(randomStr.charAt(4));
} else {
dash = dash + "?";
}
}
final String displayVal = dash;
textView.setText(displayVal); // Displaying string with question mark with 2nd and 5th character only
gridview = (GridView) findViewById(R.id.gridview);
final String[] mAlphabets = new String[]{"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
final ArrayList<String> array_list = new ArrayList<String>(Arrays.asList(mAlphabets));
final ArrayAdapter arrayAdapter = new ArrayAdapter (getApplicationContext(),android.R.layout.simple_list_item_1,array_list);
gridview.setNumColumns(8);
gridview.setBackgroundColor(Color.BLUE);
gridview.setGravity(Gravity.CENTER);
gridview.setAdapter(arrayAdapter);
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
String finalDisplayVal = displayVal;
int count = 0;
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
final ProgressDialog mProgressDialog = new ProgressDialog(PlayActivity.this);
// Set progressdialog title
mProgressDialog.setTitle("Loading...");
// Set progressdialog message
mProgressDialog.setMessage("Checkinggg...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
long delayInMillis = 1000;
Timer timer = new Timer();
timer.schedule(new TimerTask() {
#Override
public void run() {
mProgressDialog.dismiss();
}
}, delayInMillis);
String itemValue = (String) gridview.getItemAtPosition(position);
array_list.remove(position); // Removing character from 26 alphabets which is clicked by user
arrayAdapter.notifyDataSetChanged(); // Reset gridview
if(randomStr.contains(itemValue)){ // If selected alphabets exists in string
for(int k=0; k<strLength; k++){
if(Character.toString(randomStr.charAt(k)).equalsIgnoreCase(itemValue)){
int charPos = randomStr.indexOf(itemValue);
while(charPos >= 0){
finalDisplayVal = replaceCharAt(finalDisplayVal, charPos, itemValue);
textView.setText(finalDisplayVal);
charPos = randomStr.indexOf(itemValue, charPos + 1);
}
}
}
checkWinCount(); // Checking if User Wins
} else {
count++;
int remVal = 4-count;
remainingChance.setText("Not Exist, You have " + remVal + " chance(s) left.");
}
checkLoseCount(); // Checking if User Lose
}
public String replaceCharAt(String s, int pos, String c) {
return s.substring(0, pos) + c + s.substring(pos + 1);
}
public void checkLoseCount() {
if(count > 3) {
Toast.makeText(PlayActivity.this, "You Loose, Value is: "+randomStr, Toast.LENGTH_LONG).show();
Intent goBack = new Intent(PlayActivity.this, MainActivity.class);
startActivity(goBack);
}
}
public void checkWinCount(){
if(randomStr.equalsIgnoreCase(finalDisplayVal)){
Toast.makeText(PlayActivity.this, "Hurray!!! You WIN... It's "+randomStr, Toast.LENGTH_LONG).show();
Intent goBack = new Intent(PlayActivity.this, MainActivity.class);
startActivity(goBack);
}
}
});
}
}
AsyncTask Code;
import android.app.ProgressDialog;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Gravity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import android.os.AsyncTask;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Timer;
import java.util.TimerTask;
public class PlayActivity1 extends AppCompatActivity {
GridView gridview;
TextView textView;
TextView result;
TextView remainingChance;
Button giveup;
Button goback;
int count = 0;
String randomStr;
String finalDisplayVal;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.play);
textView = (TextView) findViewById(R.id.blanks);
result = (TextView) findViewById(R.id.result);
remainingChance = (TextView) findViewById(R.id.remainingChance);
giveup = (Button) findViewById(R.id.giveup);
goback = (Button) findViewById(R.id.goback);
goback.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent goBack = new Intent(PlayActivity1.this, MainActivity.class);
startActivity(goBack);
}
});
String dash = "";
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String easyArray[] = bundle.getStringArray("easy");
final String randomStr = easyArray[new Random().nextInt(easyArray.length)]; // Getting a random string from Array
giveup.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
result.setText(randomStr); // By clicking on Give up button, it displays the actual word & a message Go Back and try again
remainingChance.setText("Go Back and try again");
}
});
final Integer strLength = randomStr.length();
// Creating string with question mark with 2nd and 5th character only
for (int i = 1; i <= strLength; i++) {
if (i == 2) {
dash = dash + Character.toString(randomStr.charAt(1));
} else if (i == 5) {
dash = dash + Character.toString(randomStr.charAt(4));
} else {
dash = dash + "?";
}
}
final String displayVal = dash;
textView.setText(displayVal); // Displaying string with question mark with 2nd and 5th character only
gridview = (GridView) findViewById(R.id.gridview);
final String[] mAlphabets = new String[]{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"};
final ArrayList<String> array_list = new ArrayList<String>(Arrays.asList(mAlphabets));
final ArrayAdapter arrayAdapter = new ArrayAdapter(getApplicationContext(), android.R.layout.simple_list_item_1, array_list);
gridview.setNumColumns(8);
gridview.setBackgroundColor(Color.BLUE);
gridview.setGravity(Gravity.CENTER);
gridview.setAdapter(arrayAdapter);
gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AsyncTaskRunner runner = new AsyncTaskRunner();
String finalDisplayVal = displayVal;
runner.execute(finalDisplayVal);
String itemValue = (String) gridview.getItemAtPosition(position);
array_list.remove(position); // Removing character from 26 alphabets which is clicked by user
arrayAdapter.notifyDataSetChanged(); // Reset gridview
if (randomStr.contains(itemValue)) { // If selected alphabets exists in string
for (int k = 0; k < strLength; k++) {
if (Character.toString(randomStr.charAt(k)).equalsIgnoreCase(itemValue)) {
int charPos = randomStr.indexOf(itemValue);
while (charPos >= 0) {
finalDisplayVal = replaceCharAt(finalDisplayVal, charPos, itemValue);
textView.setText(finalDisplayVal);
charPos = randomStr.indexOf(itemValue, charPos + 1);
}
}
}
checkWinCount(); // Checking if User Wins
} else {
count++;
int remVal = 4 - count;
remainingChance.setText("Not Exist, You have " + remVal + " chance(s) left.");
}
checkLoseCount(); // Checking if User Lose
}
});
}
public String replaceCharAt(String s, int pos, String c) {
return s.substring(0, pos) + c + s.substring(pos + 1);
}
public void checkLoseCount() {
if (count > 3) {
Toast.makeText(PlayActivity1.this, "You Loose, Value is: " + randomStr, Toast.LENGTH_LONG).show();
Intent goBack = new Intent(PlayActivity1.this, MainActivity.class);
startActivity(goBack);
}
}
public void checkWinCount() {
if (randomStr.equalsIgnoreCase(finalDisplayVal)) {
Toast.makeText(PlayActivity1.this, "Hurray!!! You WIN... It's " + randomStr, Toast.LENGTH_LONG).show();
Intent goBack = new Intent(PlayActivity1.this, MainActivity.class);
startActivity(goBack);
}
}
private class AsyncTaskRunner extends AsyncTask<String, String, ProgressDialog> {
#Override
protected ProgressDialog doInBackground(String... params) {
final ProgressDialog mProgressDialog = new ProgressDialog(PlayActivity1.this);
// Set progressdialog title
mProgressDialog.setTitle("Loading...");
// Set progressdialog message
mProgressDialog.setMessage("Checkinggg...");
mProgressDialog.setIndeterminate(false);
// Show progressdialog
mProgressDialog.show();
try {
long delayInMillis = 1000;
Timer timer = new Timer();
timer.schedule(new TimerTask() {
#Override
public void run() {
mProgressDialog.dismiss();
}
}, delayInMillis);
}catch (Exception e){
e.printStackTrace();
}
return mProgressDialog;
}
}
}

Menu issue - Edit/Delete menu wont show

I have added a Contacts class to my app and have it working well , but my edit/delete menu wont show up . I have it in java as well as a menu xml (display contacts) for it . I have an add menu menu main) that works just fine .Any suggestions ?
package com.cb45.mhpd_1;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.database.Cursor;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
public class DisplayContact extends Activity {
int from_Where_I_Am_Coming = 0;
private DBHelper mydb ;
TextView name ;
TextView phone;
TextView email;
TextView street;
TextView place;
int id_To_Update = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_contact);
name = (TextView) findViewById(R.id.editTextName);
phone = (TextView) findViewById(R.id.editTextPhone);
email = (TextView) findViewById(R.id.editTextStreet);
street = (TextView) findViewById(R.id.editTextEmail);
place = (TextView) findViewById(R.id.editTextCity);
mydb = new DBHelper(this);
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
int Value = extras.getInt("id");
if(Value>0){
Cursor rs = mydb.getData(Value);
id_To_Update = Value;
rs.moveToFirst();
String nam = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_NAME));
String phon = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_PHONE));
String emai = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_EMAIL));
String stree = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_STREET));
String plac = rs.getString(rs.getColumnIndex(DBHelper.CONTACTS_COLUMN_CITY));
if (!rs.isClosed())
{
rs.close();
}
Button b = (Button)findViewById(R.id.button1);
b.setVisibility(View.INVISIBLE);
name.setText(nam);
name.setFocusable(false);
name.setClickable(false);
phone.setText(phon);
phone.setFocusable(false);
phone.setClickable(false);
email.setText(emai);
email.setFocusable(false);
email.setClickable(false);
street.setText(stree);
street.setFocusable(false);
street.setClickable(false);
place.setText(plac);
place.setFocusable(false);
place.setClickable(false);
}
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
int Value = extras.getInt("id");
if(Value>0){
getMenuInflater().inflate(R.menu.display_contact, menu);
}
else{
getMenuInflater().inflate(R.menu.menu_main, menu);
}
}
return true;
}
public boolean onOptionsItemSelected(MenuItem item)
{
super.onOptionsItemSelected(item);
switch(item.getItemId())
{
case R.id.Edit_Contact:
Button b = (Button)findViewById(R.id.button1);
b.setVisibility(View.VISIBLE);
name.setEnabled(true);
name.setFocusableInTouchMode(true);
name.setClickable(true);
phone.setEnabled(true);
phone.setFocusableInTouchMode(true);
phone.setClickable(true);
email.setEnabled(true);
email.setFocusableInTouchMode(true);
email.setClickable(true);
street.setEnabled(true);
street.setFocusableInTouchMode(true);
street.setClickable(true);
place.setEnabled(true);
place.setFocusableInTouchMode(true);
place.setClickable(true);
return true;
case R.id.Delete_Contact:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(R.string.deleteContact)
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
mydb.deleteContact(id_To_Update);
Toast.makeText(getApplicationContext(), "Deleted Successfully", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),NewContact.class);
startActivity(intent);
}
})
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog d = builder.create();
d.setTitle("Are you sure");
d.show();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
public void run(View view)
{
Bundle extras = getIntent().getExtras();
if(extras !=null)
{
int Value = extras.getInt("id");
if(Value>0){
if(mydb.updateContact(id_To_Update,name.getText().toString(), phone.getText().toString(), email.getText().toString(), street.getText().toString(), place.getText().toString())){
Toast.makeText(getApplicationContext(), "Updated", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),NewContact.class);
startActivity(intent);
}
else{
Toast.makeText(getApplicationContext(), "not Updated", Toast.LENGTH_SHORT).show();
}
}
else{
if(mydb.insertContact(name.getText().toString(), phone.getText().toString(), email.getText().toString(), street.getText().toString(), place.getText().toString())){
Toast.makeText(getApplicationContext(), "done", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), "not done", Toast.LENGTH_SHORT).show();
}
Intent intent = new Intent(getApplicationContext(),NewContact.class);
startActivity(intent);
}
}
}
}

Anomailies when an activity calls itself

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.

How to use Application class to share variables while extending Activity class

Im having problem sharing a global variable that I need to retain across multiple activities. This variable is created in TextPlay class and copied onto DailyDataEntry class. I have done some research sharing variables between two activities using Intent but Im looking to share that variable to multiple classes. I think I will have to extends Application but all my other classes are extending Activity already. How am I supposed to extend Application while extending Activity? Thanks a million
///TextPlay Class///
package com.armstrong.y.android.app;
import java.util.Random;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
public class TextPlay extends Activity implements View.OnClickListener {
Button chkCmd;
ToggleButton passTog;
EditText input;
TextView display;
EditText etUserId;
Button btnUserId;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.text);
baconAndEggs();
passTog.setOnClickListener(this);
chkCmd.setOnClickListener(this);
// Share variables between classes controls
etUserId = (EditText) findViewById(R.id.etUserId);
btnUserId = (Button) findViewById(R.id.btnUserId);
}
private void baconAndEggs() {
// TODO Auto-generated method stub
chkCmd = (Button) findViewById(R.id.bResults);
passTog = (ToggleButton) findViewById(R.id.tbPassword);
input = (EditText) findViewById(R.id.etCommands);
display = (TextView) findViewById(R.id.tvResults);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.bResults:
// get the text from the command box then convert it to string
String check = input.getText().toString();
display.setText(check);
if (check.contentEquals("left")) {
display.setGravity(Gravity.LEFT);
} else if (check.contentEquals("center")) {
display.setGravity(Gravity.CENTER);
} else if (check.contentEquals("right")) {
display.setGravity(Gravity.RIGHT);
} else if (check.contentEquals("blue")) {
display.setTextColor(Color.BLUE);
display.setText("blue");
} else if (check.contains("hellow")) {
Random crazy = new Random();
display.setText("hello!!!!");
display.setTextSize(crazy.nextInt(75));
display.setTextColor(Color.rgb(crazy.nextInt(255),
crazy.nextInt(255), crazy.nextInt(255)));
switch (crazy.nextInt(3)) {
case 0:
display.setGravity(Gravity.LEFT);
break;
case 1:
display.setGravity(Gravity.CENTER);
break;
case 2:
display.setGravity(Gravity.RIGHT);
break;
}
} else {
display.setText("invalid");
display.setGravity(Gravity.CENTER);
display.setTextColor(Color.BLACK);
}
break;
case R.id.tbPassword:
// If toggle button is set to ON, password will be ***
if (passTog.isChecked()) {
input.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
} else {
// if toggle is off, its going be plain text
input.setInputType(InputType.TYPE_CLASS_TEXT);
}
break;
}
}
}
///DailyDataEntry Class///
package com.armstrong.y.android.app;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class DailyDataEntry extends Activity {
String strdate;
EditText etGetDate;
Calendar calendarDateToday = Calendar.getInstance();
Calendar calendarDateNext = Calendar.getInstance();
Calendar calendarDatePrevious = Calendar.getInstance();
int counterNext = 0;
int counterPrevious = 0;
Button btnTodayDate;
Button btnPreviousDate;
Button btnGetNextDate;
EditText etDailyCaloriesIn;
EditText etDailyCaloriesOut;
EditText etDailyAnxietyLevel;
EditText etDailySleepQuality;
TextView tvUserId;
Button btnSubmit;
Button btnReset;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.daily_data_entry);
// Toast Message Warning
Toast.makeText(getApplicationContext(),
"DO NOT LEAVE FIELD BLANK OR CRASH IS ON YOU!",
Toast.LENGTH_LONG).show();
btnTodayDate = (Button) findViewById(R.id.btnGetTodayDate);
btnPreviousDate = (Button) findViewById(R.id.btnGetPreviousDate);
btnGetNextDate = (Button) findViewById(R.id.btnGetNextDate);
etGetDate = (EditText) findViewById(R.id.etGetDate);
btnSubmit = (Button) findViewById(R.id.btnSubmit);
btnReset = (Button) findViewById(R.id.btnReset);
etDailyCaloriesIn = (EditText) findViewById(R.id.etDailyCaloriesIn);
etDailyCaloriesOut = (EditText) findViewById(R.id.etDailyCaloriesOut);
etDailyAnxietyLevel = (EditText) findViewById(R.id.etDailyAnxietyLevel);
etDailySleepQuality = (EditText) findViewById(R.id.etDailySleepQuality);
tvUserId = (TextView) findViewById(R.id.tvUserId);
// When Submit Button is clicked
btnSubmit.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Grab User Input from EditText and Convert input String to
// Integer
int check1 = Integer.parseInt(etDailyCaloriesIn.getText()
.toString());
int check2 = Integer.parseInt(etDailyCaloriesOut.getText()
.toString());
int check4 = Integer.parseInt(etDailyAnxietyLevel.getText()
.toString());
int check5 = Integer.parseInt(etDailySleepQuality.getText()
.toString());
strdate = etGetDate.getText().toString();
// Run Legal Value Integrity Check
if (strdate.length() != 8) {
etGetDate.setText("Please enter in the correct format.");
} else if (strdate.equals("")) {
etGetDate.setText("Please enter a date.");
} else if (check1 > 10 || check1 < 1) {
etDailyCaloriesIn.setText("Incorrect Value!");
} else if (check2 > 10 || check2 < 1) {
etDailyCaloriesOut.setText("Incorrect Value!");
} else if (check4 > 10 || check4 < 1) {
etDailyAnxietyLevel.setText("Incorrect Value!");
} else if (check5 > 10 || check5 < 1) {
etDailySleepQuality.setText("Incorrect Value!");
} else {
etGetDate.setText("Submited!");
etDailyCaloriesIn.setText("Submited!");
etDailyCaloriesOut.setText("Submited!");
etDailyAnxietyLevel.setText("Submited!");
etDailySleepQuality.setText("Submited!");
}
}
});
// When Reset Button is Clicked
btnReset.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String empty = "";
etDailyCaloriesIn.setText(empty);
etDailyCaloriesOut.setText(empty);
etDailyAnxietyLevel.setText(empty);
etDailySleepQuality.setText(empty);
etGetDate.setText(empty);
}
});
// Capture Today's Date
btnTodayDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyy");
strdate = sdf.format(calendarDateToday.getTime());
etGetDate.setText(strdate);
}
});
// Capture Previous's Date
btnPreviousDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyy");
if (counterPrevious == 0) {
calendarDatePrevious.add(Calendar.DATE, -1);
}
strdate = sdf.format(calendarDatePrevious.getTime());
etGetDate.setText(strdate);
counterPrevious++;
}
});
// Capture Next's Date
btnGetNextDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyy");
if (counterNext == 0) {
calendarDateNext.add(Calendar.DATE, +1);
}
strdate = sdf.format(calendarDateNext.getTime());
etGetDate.setText(strdate);
counterNext++;
}
});
}
}
Create class that will extends to Application and use it in the following manner whenever you need it:
MyApplication myAppHelper = (MyApplication) context.getApplication();
myAppHelper.setWhatever(whatever);
Whatever whatever = myAppHelper.getWhatever();

How to change an existing Activity class to fragment class

I am trying to update my existing Android Application to work on both mobile phone and Tablet. So I want to change the Activity class to fragment. The below is my activity class.
Individual Activity class
package FXPAL.Unity.Android;
import FXPAL.Unity.Android.Person.CalendarEntry;
import FXPAL.Unity.Android.Person.IM;
import FXPAL.Unity.Android.Person.Person;
import FXPAL.Unity.Android.Person.Status;
import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.preference.PreferenceManager;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;
import android.widget.Toast;
public class IndividualViewActivity extends Activity {
private static final String DB_TAG = "IndividualView";
//private static final String DB_TAG_PING = "ShowPingView";
private TextView displayName, presence, phoneNum, cellNum, emailAddr, btLocation, calInfo, status;
private ImageView userImage;
private Person personToDisplay;
private String phoneNumber, cellNumber, username, emailAddress;
private TableRow fxpalIMrow, skypeIMrow, msLiveIMrow, gtalkIMrow;
private TableLayout imTable;
private TextView fxpalIMstatus, skypeIMstatus, msLiveIMstatus, gtalkIMstatus, pingText;
private Button nudgeButton, pingButton, clearPingButton, calendarButton;
private LinearLayout pingLayout, pingNudgeButtonLayout;
protected String numToCall, numtype;
private DatabaseHelper db;
//private int pingID = -1;
private UnityMobileApp appCtx;
private static final int DIALOG_CALL_OFFICE_ID = 0;
private static final int DIALOG_CALL_CELL_ID = 1;
protected static final int DIALOG_VIEW_CALENDAR = 2;
private static final int REFRESH_MENU_ID = 0;
protected static final String OFFICE = "office";
private static final String CELL = "cell";
protected static final int MESSAGE_CONNECTION_ERROR_TOAST = 0;
//private static final String DEBUG_TAG = "unity.IndividualViewActivity";
private final Handler mHandler = new Handler() {
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_CONNECTION_ERROR_TOAST:
Toast.makeText(IndividualViewActivity.this, Consts.CONNECTION_ERROR_MESSAGE, Toast.LENGTH_SHORT).show();
break;
}
}
};
private SharedPreferences prefs;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//doBindService();
setContentView(R.layout.individual_view);
db = new DatabaseHelper(this);
appCtx = (UnityMobileApp) getApplication();
prefs = PreferenceManager.getDefaultSharedPreferences(this);
//Setup View
displayName = (TextView)findViewById(R.id.individualName);
presence = (TextView)findViewById(R.id.individualPresence);
userImage = (ImageView)findViewById(R.id.individualUserImage);
phoneNum = (TextView)findViewById(R.id.individualPhone);
cellNum = (TextView)findViewById(R.id.individualCellPhone);
emailAddr = (TextView)findViewById(R.id.individualEmail);
btLocation = (TextView)findViewById(R.id.individualLocation);
calInfo = (TextView)findViewById(R.id.individualCalendarInfo);
status = (TextView)findViewById(R.id.individualStatus);
fxpalIMrow = (TableRow)findViewById(R.id.im_fxpal);
skypeIMrow = (TableRow)findViewById(R.id.im_skype);
msLiveIMrow = (TableRow)findViewById(R.id.im_ms_live);
gtalkIMrow = (TableRow)findViewById(R.id.im_gtalk);
fxpalIMstatus = (TextView)findViewById(R.id.im_status_fxpal);
skypeIMstatus = (TextView)findViewById(R.id.im_status_skype);
msLiveIMstatus = (TextView)findViewById(R.id.im_status_ms_live);
gtalkIMstatus = (TextView)findViewById(R.id.im_status_gtalk);
imTable = (TableLayout)findViewById(R.id.individualIMStatus);
nudgeButton = (Button)findViewById(R.id.individual_nudge_button);
pingButton = (Button) findViewById(R.id.individual_ping_button);
calendarButton = (Button)findViewById(R.id.individualViewCalendarButton);
pingText = (TextView)findViewById(R.id.individualPingText);;
clearPingButton = (Button) findViewById(R.id.individualClearPingButton);
pingLayout = (LinearLayout)findViewById(R.id.individualPingInfo);
pingNudgeButtonLayout = (LinearLayout)findViewById(R.id.individual_nudge_ping_layout);
calendarButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
showDialog(DIALOG_VIEW_CALENDAR);
db.viewEvent(DB_TAG + ":CalendarDialog", username);
}
});
nudgeButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(IndividualViewActivity.this, SendNudgeActivity.class)
.putExtra(Consts.EXTRA_USERNAME, personToDisplay.getUsername())
.putExtra(Consts.EXTRA_DISPLAY_NAME, personToDisplay.getDisplayName()));
}
});
pingButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
startActivity(new Intent(IndividualViewActivity.this, SendPingActivity.class)
.putExtra(Consts.EXTRA_USERNAME, personToDisplay.getUsername())
.putExtra(Consts.EXTRA_DISPLAY_NAME, personToDisplay.getDisplayName()));
}
});
}
public void onPause(){
super.onPause();
}
public void onDestroy(){
super.onDestroy();
//doUnbindService();
db.close();
}
public void onResume(){
super.onResume();
Intent mIntent = getIntent();
username = mIntent.getStringExtra(Consts.EXTRA_USERNAME);
if(username.equalsIgnoreCase(prefs.getString(Consts.PREF_USERNAME, "")))
pingNudgeButtonLayout.setVisibility(View.GONE);
else
pingNudgeButtonLayout.setVisibility(View.VISIBLE);
personToDisplay = appCtx.getEveryone().get(username);
updateView();
updateInfo();
if (personToDisplay == null || personToDisplay.getCalendar() == null ||
personToDisplay.getCalendar().getCalendar().size() == 0)
calendarButton.setEnabled(false);
else
calendarButton.setEnabled(true);
db.viewEvent(DB_TAG, username);
pingLayout.setVisibility(View.GONE);
//}
}
private void updateInfo(){
ServerHelper.RequestListener listener = new ServerHelper.RequestListener() {
public void onCompleted(ServerHelper.Request request) {
if (request.isUnauthorized())
startActivity(new Intent(IndividualViewActivity.this, LoginActivity.class));
else if (request.isSuccess()) {
Person.PersonHelper.getEveryoneAsync(IndividualViewActivity.this, appCtx.everyone, null, request.getResponseString(),
new Runnable() {
public void run () {
personToDisplay = appCtx.everyone.get(username);
updateView();
}
});
}
}
};
ServerHelper.appCtx = appCtx;
ServerHelper.getStatus (prefs, listener);
}
private void updateView(){
if (personToDisplay == null)
return;
displayName.setText(personToDisplay.getDisplayName());
presence.setText(personToDisplay.getPresenceState());
Status mStatus = personToDisplay.getStatus();
if( mStatus!= null && mStatus.toString().length()>0){
status.setVisibility(View.VISIBLE);
status.setText(mStatus.toString());
}
userImage.setImageBitmap(personToDisplay.getRoundedImage(Consts.LARGE_USER_IMAGE_SIZE, Consts.LARGE_USER_IMAGE_BORDER));
phoneNumber = personToDisplay.getPhoneNum();
if(phoneNumber.length()>0){
phoneNum.setText(OFFICE + ": " + phoneNumber);
phoneNum.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
numToCall = phoneNumber;
numtype = OFFICE;
showDialog(DIALOG_CALL_OFFICE_ID);
}
});}
else
phoneNum.setVisibility(View.GONE);
cellNumber = personToDisplay.getCellPhoneNum();
if(cellNumber.length()>0){
cellNum.setText(CELL + ": " + cellNumber);
cellNum.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
numToCall = cellNumber;
numtype = CELL;
showDialog(DIALOG_CALL_CELL_ID);
}
});}
else
cellNum.setVisibility(View.GONE);
emailAddress = personToDisplay.getEmailAddress();
emailAddr.setText(emailAddress);
emailAddr.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
db.communicate(DB_TAG, "email", username);
Intent emailIntent = new Intent();
emailIntent.setAction(android.content.Intent.ACTION_SENDTO);
emailIntent.setData(Uri.parse("mailto:" + emailAddress));
startActivity(Intent.createChooser(emailIntent, "Select Email Client"));
}
});
if(personToDisplay.hasLocation()){
btLocation.setVisibility(View.VISIBLE);
btLocation.setText(personToDisplay.getLocation().toString());
}
CalendarEntry usefulCalInfo = personToDisplay.getCalendar().getMostUseful();
if(usefulCalInfo != null){
calInfo.setVisibility(View.VISIBLE);
calInfo.setText("Calendar: " + usefulCalInfo.toString());
}
if(personToDisplay.hasIM()){
imTable.setVisibility(View.VISIBLE);
}
for(IM mIM : personToDisplay.getIMList().values()){
switch(mIM.getId()){
case(IM.FXPAL_ID):
fxpalIMrow.setVisibility(View.VISIBLE);
fxpalIMstatus.setText(mIM.getStatus());
break;
case(IM.SKYPE_ID):
skypeIMrow.setVisibility(View.VISIBLE);
skypeIMstatus.setText(mIM.getStatus());
break;
case(IM.MS_LIVE_ID):
msLiveIMrow.setVisibility(View.VISIBLE);
msLiveIMstatus.setText(mIM.getStatus());
break;
case(IM.GTALK_ID):
gtalkIMrow.setVisibility(View.VISIBLE);
gtalkIMstatus.setText(mIM.getStatus());
break;
default:
}
}
}
protected Dialog onCreateDialog(int id) {
Dialog dialog = null;
switch(id) {
case DIALOG_CALL_OFFICE_ID:
case DIALOG_CALL_CELL_ID:
dialog = CommDialog.getCallDialog(displayName.getText().toString(), numToCall, numtype, IndividualViewActivity.this, db);
break;
case DIALOG_VIEW_CALENDAR:
return CalendarListDialog.getDialog(username, IndividualViewActivity.this, appCtx);
default:
dialog = null;
}
return dialog;
}
public boolean onCreateOptionsMenu(Menu menu){
menu.add(Menu.NONE, REFRESH_MENU_ID, Menu.NONE, "Refresh")
.setIcon(R.drawable.ic_menu_refresh)
.setAlphabeticShortcut('r');
return(super.onCreateOptionsMenu(menu));
}
#Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()) {
case REFRESH_MENU_ID:
refresh();
break;
}
return (super.onOptionsItemSelected(item));
}
void refresh() {
// update the location and report it to the server
ReportingService.startLocationRequest(appCtx, true);
// this may still retrieve the old location
updateInfo();
}
}
Please help me guys. I am stuck with this problem since long time.
Regards,
Rakesh

Categories

Resources