im trying to make an app in Android Studio that recordes gps locations and im using SQLite for the database. im a beginner on java/android studio and have taken a crash course on how to make a project through vids on youtube.
i've placed the create database code on a function, and is being called on create. im able to build the program with no errors but i keep getting the "Database Missing" toast. am i missing something?
#MainActivity.java
import android.database.sqlite.SQLiteDatabase;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;
import java.io.File;
public class MainActivity extends ActionBarActivity {
SQLiteDatabase recordedDB = null;
GPSLocation gps;
int ReadingCount = 0;
float oldAcc,newAcc;
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ReAcquireData();
CreateDB();
}
public void Save(View view) {
}
public void ReAcquireData(View view) {
ReAcquireData();
}
public void ReAcquireData(){
final TextView tvLat = (TextView) findViewById(R.id.tvLat);
final TextView tvLong = (TextView) findViewById(R.id.tvLong);
final TextView tvAcc = (TextView) findViewById(R.id.tvAcc);
final TextView tvRead = (TextView) findViewById(R.id.tvReadings);
gps = new GPSLocation(MainActivity.this);
if (gps.canGetLocation()) {
ReadingCount++;
if (ReadingCount == 1) {
oldAcc = gps.getAccuracy();
tvLat.setText(Double.toString(gps.getLatitude()));
tvLong.setText(Double.toString(gps.getLongitude()));
tvAcc.setText(Float.toString(oldAcc) + "m");
}
else {
newAcc = gps.getAccuracy();
if (newAcc < oldAcc) {
oldAcc = newAcc;
tvLat.setText(Double.toString(gps.getLatitude()));
tvLong.setText(Double.toString(gps.getLongitude()));
tvAcc.setText(Float.toString(oldAcc) + "m");
}
}
tvRead.setText(Integer.toString(ReadingCount));
} else gps.showSettingsAlert();
}
public void CreateDB(){
try{
recordedDB = this.openOrCreateDatabase("GeoLocator",MODE_PRIVATE,null);
recordedDB.execSQL("CREATE TABLE IF NOT EXISTS database ("+
"entry integer primary key,"+
"operatorID VARCHAR,"+
"municipality VARCHAR,"+
"barangay VARCHAR,"+
"longitude DOUBLE,"+
"latitude DOUBLE,"+
"accuracy FLOAT,"+
"landcover VARCHAR,"+
"remarks VARCHAR);"
);
File database = getApplicationContext().getDatabasePath("GeoLocator.db");
if(database.exists())
Toast.makeText(this,"Database Exists", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this,"Database Missing", Toast.LENGTH_SHORT).show();
} catch(Exception e){
Log.e("GeoLocator ERROR","Error Creating Database");
}
}
}
Just make sure that you pass in the same string name you used to create the database to the getDatbasePath() method.
Replace
File database = getApplicationContext().getDatabasePath("GeoLocator.db");
With
File database = getApplicationContext().getDatabasePath("GeoLocator");
Related
i passing data keyword search with intent for get result in other activity. the keyword search use to search data from database sqlite, but i can't display the result with textView, there is no error in logcat. what problem with my code?
there is my code to display output
OutputSuccess.java
package com.mjusuf.halal;
import android.support.v7.app.ActionBarActivity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
public class OutputSuccess extends ActionBarActivity {
// Objects And Variables
private String select;
// User Information Variables
String c2, c3, c4, c5, c6;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_outputsuccess);
TextView certificate_no = (TextView) findViewById(R.id.textView3);
TextView valid_from = (TextView) findViewById(R.id.textView6);
TextView valid_to = (TextView) findViewById(R.id.textView9);
TextView company = (TextView) findViewById(R.id.textView12);
TextView product_name = (TextView) findViewById(R.id.textView15);
// name.setText(getIntent().getExtras().getString("search"));
DatabaseHandler db = new DatabaseHandler(this);
SQLiteDatabase db1 = db.getReadableDatabase();
select = "SELECT * FROM certificate WHERE Certificate_No='"
+ getIntent().getExtras().getString("search") + "'";
Cursor c1 = db1.rawQuery(select, null);
if (c1 != null && c1.moveToFirst())
do {
certificate_no.setText(c1.getString(c1.getColumnIndex("Certificate_No")));
valid_from.setText(c1.getString(c1.getColumnIndex("Valid_From")));
valid_to.setText(c1.getString(c1.getColumnIndex("Valid_To")));
company.setText(c1.getString(c1.getColumnIndex("Company")));
product_name.setText(c1.getString(c1.getColumnIndex("Product_Name")));
} while (c1.moveToNext());
};
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.output_success, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
I have written this code for searching a text file for a string. The problem is, it says that the string is not found even if it is present. Process is to receive the text from the EditText and then start the searching process. But it shows that string is found every time.
package com.example.demo;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button;
final EditText obedittext;
button =(Button)findViewById(R.id.button1);
obedittext =(EditText)findViewById(R.id.editText1);
button.setOnClickListener(
new View.OnClickListener()
{
boolean textfound;
public void onClick(View view)
{
textfound = searchtext(obedittext.getText().toString());
if(textfound)
maketoast(obedittext.getText().toString());
else
maketoast("Unsuccessfull");
}
});
}
protected boolean searchtext(String string) {
// TODO Auto-generated method stub
BufferedReader br = null;
try {
String sCurrentLine;
br = new BufferedReader(new InputStreamReader(getAssets().open("mneumo.txt")));
while ((sCurrentLine = br.readLine()) != null) {
if(sCurrentLine.equals(string)) {
return true;
}
}
br.close();
} catch (IOException e) {
e.printStackTrace();
}
finally{
}
return false;
}
private void maketoast(String string) {
// TODO Auto-generated method stub
Context context = getApplicationContext();
Toast toast = Toast.makeText(context, string , Toast.LENGTH_SHORT);
toast.show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
So when i tried to give the string inside the code itself instead of getting it from the edittext,it works fine. Like this,
string = "SPINAL ANESTHESIA AGENTS";
The sample text file is,
SPINAL ANESTHESIA AGENTS
XYLOCAINE: WHERE NOT TO USE WITH EPINEPHRINE
GENERAL ANAESTHESIA: EQUIPMENT CHECK PRIOR TO INDUCING
So how can i rectify this problem? Can anyone say why i am getting this problem?
Should i any other method to compare the strings?
The text file is correctly placed in the assets folder. And i accessed it using the assetmanager. And i am a total newbie to android development.
May be your editText contain some white space already, To get text from your editText try this:
obedittext.getText().toString().trim();
and inside your searchtext() method, replace your if condition with:
if(sCurrentLine.equalsIgnoreCase(string))
I am currently attempting to generate a user profile in an Android application through the users existing social network data. I am using the SocialAuth library to login and pull the data out of the application and populate some text fields in a fragment.
I am currently using Facebook and Twitter for this but I am having trouble reciving the "Location" of the profile through Facebook. Twitter is able to get location successfully but Facebook simply comes up "Null" when the get request is sent out.
To complicate things when I access the Facebook account I am testing on with the example application that SocialAuth provides it is able to get the location without any problems but despite my code being identical and Twitter running the same code it won't work within my application.
Can anyone shed some light on why I am unable to retrieve the location through Facebook in my application? I will provide my relevant classes below:
LoginActivity.java
import android.content.Intent;
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 org.brickred.socialauth.android.DialogListener;
import org.brickred.socialauth.android.SocialAuthAdapter;
import org.brickred.socialauth.android.SocialAuthError;
import org.brickred.socialauth.android.SocialAuthListener;
import org.brickred.socialauth.Profile;
public class LoginActivity extends ActionBarActivity {
private static SocialAuthAdapter adapter;
private Button facebook_button;
private Button twitter_button;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
adapter = new SocialAuthAdapter(new ResponseListener());
facebook_button = (Button)findViewById(R.id.fbSignUp);
twitter_button = (Button)findViewById(R.id.twitSignUp);
facebook_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
adapter.authorize(LoginActivity.this, SocialAuthAdapter.Provider.FACEBOOK);
}
});
twitter_button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
adapter.authorize(LoginActivity.this, SocialAuthAdapter.Provider.TWITTER);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_login, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
private class ResponseListener implements DialogListener {
#Override
public void onComplete(Bundle bundle) {
adapter.getUserProfileAsync(new ProfileDataListener());
}
#Override
public void onError(SocialAuthError socialAuthError) {
}
#Override
public void onCancel() {
}
#Override
public void onBack() {
}
}
private class ProfileDataListener implements SocialAuthListener<Profile> {
#Override
public void onExecute(String provider, Profile t) {
Profile profileMap = t;
Intent intent = new Intent(LoginActivity.this, HubPage.class);
intent.putExtra("provider", provider);
intent.putExtra("profile", profileMap);
startActivity(intent);
}
#Override
public void onError(SocialAuthError socialAuthError) {
}
}
}
Profile Fragment.java
import android.os.Bundle;
import android.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.brickred.socialauth.Profile;
import org.brickred.socialauth.android.SocialAuthAdapter;
public class ProfileFragment extends Fragment {
SocialAuthAdapter adapter;
Profile profileMap;
// Android Components
TextView name;
TextView location;
ImageView image;
// Variables
String provider_name;
//ImageLoader imageLoader;
public ProfileFragment() {
// Required empty public constructor
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_hub_page, container, false);
profileMap = (Profile) getActivity().getIntent().getSerializableExtra("profile");
Log.d("Profile", "Validate ID = " + profileMap.getValidatedId());
Log.d("Profile", "First Name = " + profileMap.getFirstName());
Log.d("Profile", "Last Name = " + profileMap.getLastName());
Log.d("Profile", "Location = " + profileMap.getLocation());
Log.d("Profile", "Profile Image URL = " + profileMap.getProfileImageURL());
provider_name = getActivity().getIntent().getStringExtra("provider");
// Set title
name = (TextView) rootView.findViewById(R.id.profileName);
location = (TextView) rootView.findViewById(R.id.profileLocation);
image = (ImageView) rootView.findViewById(R.id.profilePic);
//imageLoader = new ImageLoader(ProfileActivity.this);
//imageLoader.DisplayImage(profileMap.getProfileImageURL(), image);
// Name
if (profileMap.getFullName() == null)
name.setText(profileMap.getFirstName() + profileMap.getLastName());
else
name.setText(profileMap.getFullName());
// Location
location.setText(profileMap.getLocation());
return rootView;
}
}
Any help would be much appreciated as I can't seem to find any solution despite hours of trying.
I work simple android app for sending sms. I have 2 activities. One is main for sending 2 different messages with 2 different content but messages send to same number. On secund activity i have 3 fields: one is for input number to send messages, and other two are for message content. When I click save button app save user input and go back to main activity. And here start my problem. How can i send users input for number to send messages and messages content to main activity to send sms with saved user input? I am totally beginner with android developing so please help! Here is my MainActivity.java:
package com.example.davor.light;
import android.content.Intent; import
android.support.v7.app.ActionBarActivity; import android.os.Bundle;
import android.telephony.SmsManager; import
android.telephony.SmsMessage; import android.view.Menu; import
android.view.MenuItem; import android.view.View; import
android.widget.Button; import android.widget.ImageView; import
android.widget.TextView; import android.widget.Toast;
public class MainActivity extends ActionBarActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// GUMBI INFORMACIJE
Button ukljuci = (Button) findViewById(R.id.ukljuci);
Button iskljuci = (Button) findViewById(R.id.iskljuci);
Button postavke = (Button) findViewById(R.id.postavke);
final ImageView slika = (ImageView) findViewById(R.id.slika);
// INFORMACIJA O PORUCI
final String broj = "097";
final String ukljuciPoruka = "Uključi";
final String iskljuciPoruka = "Isključi";
// KLIK NA GUMB ISKLJUČI
iskljuci.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(broj, null, iskljuciPoruka, null, null);
Toast.makeText(getApplicationContext(), "Isključeno! poslano na broj " + broj, Toast.LENGTH_LONG).show();
slika.setImageResource(R.drawable.off);
} catch (Exception e) {
Toast.makeText(getApplicationContext(),"Nemoguće isključiti!",Toast.LENGTH_LONG).show();
}
}
});
postavke.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent PostavkeActivity = new Intent(MainActivity.this,
Postavke.class);
startActivity(PostavkeActivity);
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
} }
And here is code for my second activity from witch I want to pull users input to MainActivity:
package com.example.davor.light;
import android.app.Activity; import android.content.Intent; import
android.content.SharedPreferences; import
android.preference.PreferenceManager; 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.EditText; import android.widget.TextView; import
android.widget.Toast;
public class Postavke extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_postavke);
gumbZaPovratak();
SharedPreferences loadSettings = PreferenceManager.getDefaultSharedPreferences(this);
String ucitajBroj = loadSettings.getString("spremiBroj", "");
String ucitajUkljuci = loadSettings.getString("spremiUkljuci", "");
String ucitajIskljuci = loadSettings.getString("spremiIskljuci", "");
final EditText postavkeBroj = (EditText) findViewById(R.id.postavkeBroj);
postavkeBroj.setText(ucitajBroj);
final EditText postavkeUkljuci = (EditText) findViewById(R.id.postavkeUkljuci);
postavkeUkljuci.setText(ucitajUkljuci);
final EditText postavkeIskljuci = (EditText) findViewById(R.id.postavkeIskljuci);
postavkeIskljuci.setText(ucitajIskljuci);
Button spremi = (Button) findViewById(R.id.postavkeSpremi);
spremi.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
spremiPostavke("spremiBroj", postavkeBroj.getText().toString());
spremiPostavke("spremiUkljuci", postavkeUkljuci.getText().toString());
spremiPostavke("spremiIskljuci", postavkeIskljuci.getText().toString());
Toast.makeText(getApplicationContext(), "Spremljeno", Toast.LENGTH_LONG).show();
finish();
}
});
}
private void postavkeBroj() {
EditText postavkeBroj = (EditText) findViewById(R.id.postavkeBroj);
}
private void spremiPostavke (String ključ, String vrijednost) {
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(ključ, vrijednost);
editor.commit();
}
private void gumbZaPovratak(){
Button nazad = (Button) findViewById(R.id.nazad);
nazad.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_postavke, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
} }
You can use startActivityForResult()
You can refer this link:
http://hmkcode.com/android-startactivityforresult/
In Activity1
Intent myIntent = new Intent(this,Activity2.class);
myIntent.putExtra("var", variable_to_pass);
startActivity(myIntent);
In Activity2
Bundle extras = getIntent().getExtras();
if (extras != null) {
intentExtra = extras.getString("var"); // retrieving variable
}
You can add data to an intent like this :
String messageContent = (EditText) findViewById(yourMessageContentId).getText().toString();
String messageNumber = (EditText) findViewById(yourMessageNumberId).getText().toString();
intent.putExtra("com.example.davor.light.MESSAGE_CONTENT", messageContent);
intent.putExtra("com.example.davor.light.MESSAGE_NUMBER", messageNumber);
And then get it on the MainActivity :
Intent intent = getIntent();
String messageNumber = intent.getStringExtra("com.example.davor.light.MESSAGE_NUMBER");
String messageContent = intent.getStringExtra("com.example.davor.light.MESSAGE_CONTENT");
you can send information from one activity to other activity like bellow
Intent postavkeActivity = new Intent(MainActivity.this,
Postavke.class);
Bundle bundle=new Bundle();
bundle.putString(|"messageKey1", "message content1");
bundle.putString(|"messageKey2", "message content2");
postavkeActivity.putExtras(bundle);
startActivity(PostavkeActivity);
in main activity get bundle data like bellow
Bundle b=getIntent.getExtras();
String smsContent=b.getString("messageKey1");
Hi I am a total newb to Android Development and I have been banging my head against the wall about this for weeks. Basically I have a SeekBar and I want to have it do something whenever the SeekBar moves. I tried to set up an onSeekBarChange event handler and as soon as I added that the app will not run anymore, and crashes at launch. I have looked all over the place online, and all the examples I find match my code EXACTLY, so I'm just wondering if I am putting it in the wrong place or something. Here is my entire MainActivity class file.
package com.slistersoft.scottlisterlab11;
import java.text.DecimalFormat;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Fragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends Activity {
String custName, phoneNum, carChoice;
double miles, costBeforeTip, tipPercentage, tipAmount, totalCost;
private SeekBar tipBar = null;
public void MsgBox(String message){
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message)
.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
public void showToast(String message, int durationMS){
Toast.makeText(getApplicationContext(), message, durationMS).show();
}
public void calculateCost(View v){
final EditText nameBox = (EditText)findViewById(R.id.nameBox);
final EditText phoneBox = (EditText)findViewById(R.id.phoneNumber);
final EditText milesBox = (EditText)findViewById(R.id.milesBox);
final Spinner car = (Spinner)findViewById(R.id.carPickerDropDown);
final SeekBar tipBar = (SeekBar)findViewById(R.id.tipBar);
if(nameBox.getText().toString().equals(""))
showToast("Please enter your name", 5000);
else if(phoneBox.getText().toString().equals("") )
showToast("Please enter your phone number",5000);
else if(milesBox.getText().toString().equals(""))
showToast("Please enter the amount of miles you need to travel",5000);
else{
custName = nameBox.getText().toString();
phoneNum = phoneBox.getText().toString();
miles = Double.parseDouble(milesBox.getText().toString());
carChoice = car.getSelectedItem().toString();
costBeforeTip = (3.25 * miles) + 3.00;
tipPercentage = tipBar.getProgress();
tipAmount = (tipPercentage/100) * costBeforeTip;
totalCost = costBeforeTip + tipAmount;
DecimalFormat currency = new DecimalFormat("$###,###.##");
MsgBox("Hello " + custName + ",\n\n" +
"Your estimated cost will be " + currency.format(costBeforeTip) +
"\n\nWith a " + tipPercentage + "% tip of " + currency.format(tipAmount) + " that brings your total cost to " + currency.format(totalCost) +
"\n\nA " + carChoice + " will pick you up ASAP. \n\nWe will call you at " + phoneNum + " when we are getting close. \n\nThank you for using CrAzY TaXi.");
}
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tipBar = (SeekBar)findViewById(R.id.tipBar);
tipBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
// TODO Auto-generated method stub
}
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// TODO Auto-generated method stub
}
});
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
If anybody has any ideas on this I would greatly appreciate it.
does the seekbar belong to fragment_main.xml? I am guess it does. So move initialization to onCreateView of fragment. use rootView.findViewById – Raghunandan 10 hours ago