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
Related
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");
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 want to make a button appear in the MenuActivity layout but the deciding if statement is in the CapitalReceiver class. I've tried adding 'static' to various variables but it didn't work. Please help!
import android.support.v4.app.Fragment;
import android.support.v4.content.LocalBroadcastManager;
import android.text.format.DateFormat;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.TextView;
public class MenuActivity extends Activity {
String status;
Boolean verified = false;
String textColour = "#000000";
TextView mTvCapital;
ArrayAdapter<String> mAdapter;
Intent mServiceIntent;
CapitalReceiver mReceiver;
IntentFilter mFilter;
String country = "7ec47294ff3d8b74";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.menu_layout);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Button IDButton = (Button) findViewById(R.id.getIt);
Button RefreshButton = (Button) findViewById(R.id.refresh);
long updateTimeMillis = System.currentTimeMillis();
String updateTime = (String) DateFormat.format("hh:mm", updateTimeMillis);
//If application has been submitted//
if(preferences.contains("first_middle_store") & !(verified)) {
status = "Status: Application pending. Last updated: " + updateTime;
IDButton.setVisibility(View.GONE);
RefreshButton.setVisibility(View.VISIBLE);
textColour = "#000000";
}
//If application has not been submitted
else {
status = "Status: Application not yet submitted";
IDButton.setVisibility(View.GONE);
RefreshButton.setVisibility(View.GONE);
textColour = "#000000";
}
TextView text=(TextView)findViewById(R.id.application_status);
text.setTextColor(Color.parseColor(textColour));
text.setText(status);
Button btnNextScreen = (Button) findViewById(R.id.verify);
//Listening to verify event
btnNextScreen.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent nextScreen = new Intent(getApplicationContext(), VerifyActivity.class);
startActivity(nextScreen);
}
});
Button btnNextScreen2 = (Button) findViewById(R.id.how);
//Listening to HowItWorks event
btnNextScreen2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent nextScreen2 = new Intent(getApplicationContext(), HowItWorksActivity.class);
startActivity(nextScreen2);
}
});
//Listening to IDbutton event
IDButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent nextScreen3 = new Intent(getApplicationContext(), IDActivity.class);
startActivity(nextScreen3);
}
});
}
#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, 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.menu_layout, container, false);
return rootView;
}
}
public void refresh(View view) {
// Getting reference to TextView
mTvCapital = (TextView) findViewById(R.id.tv_capital);
mTvCapital.setText("hello");
// Creating an intent service
mServiceIntent = new Intent(getApplicationContext(), CapitalService.class);
mServiceIntent.putExtra(Constants.EXTRA_ANDROID_ID, country);
// Starting the CapitalService to fetch the capital of the country
startService(mServiceIntent);
// Instantiating BroadcastReceiver
mReceiver = new CapitalReceiver();
// Creating an IntentFilter with action
mFilter = new IntentFilter(Constants.BROADCAST_ACTION);
// Registering BroadcastReceiver with this activity for the intent filter
LocalBroadcastManager.getInstance(getApplicationContext()).registerReceiver(mReceiver, mFilter);
}
// Defining a BroadcastReceiver
private static class CapitalReceiver extends BroadcastReceiver{
#Override
public void onReceive(Context context, Intent intent) {
String capital = intent.getStringExtra(Constants.EXTRA_APPROVAL);
if(capital == "YES") {
//status = "Status: Application Approved";//
//IDButton.setVisibility(View.VISIBLE);//
}
else if(capital == "NO"){
//status = "Status: Application Denied";//
}
}
}
}
Just glancing over your code, a possible solution (and perhaps not the best) would be to make the ID Button variable global. You would then instantiate it in the onCreate whilst still allowing it to be manipulated in other classes in this MenuActivity.
I hope this helps.
I am new to android development. I need a solution for the new app I am developing which takes voice input and gives output in voice by mapping with a mapping database. Current program takes voice input with onlick on button . I need a soultion which can take voice input without clicking of any button simliar to Talking Tom application . Here is my code.My main code is in speakToMe which is method called on onclick & onActivityResult
package com.example.secondprog;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
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.TextView;
import android.widget.Toast;
import android.os.Build;
import com.example.secondprog.*;
//import com.example.secondprog.DatabaseHelper;
public class MainActivity extends Activity {
private static final int VOICE_RECOGNITION_REQUEST = 0;
//private static final int VOICE_RECOGNITION_REQUEST = 0x10101;
TextToSpeech ttobj;
String resulttxt ;
TestDBClass db;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
db = new TestDBClass(this, null, null, 1);
try {
db.loadWords();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ttobj=new TextToSpeech(getApplicationContext(),
new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR){
ttobj.setLanguage(Locale.UK);
Toast.makeText(getApplicationContext(), "No error",
Toast.LENGTH_LONG).show();
}
}
});
//DatabaseHelper db = DatabaseHelper(this);
//dbdtls dbdtlsresult = new dbdtls();
//String message3 = db.getdtls("how are");
//String output = dbdtlsresult.new_name();
//EditText editText = (EditText) findViewById(R.id.edit_message);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
public void sendMessage(View view) {
EditText editText = (EditText) findViewById(R.id.edit_message);
String txt = editText.getText().toString();
// Toast.makeText(getApplicationContext(), txt.toUpperCase(),
// Toast.LENGTH_LONG).show();
DictonaryDAO dictonaryDAO =
db.findname(txt.toUpperCase());
if (dictonaryDAO != null) {
resulttxt = String.valueOf(dictonaryDAO.getnewname());
Toast.makeText(getApplicationContext(), resulttxt.toUpperCase(),
Toast.LENGTH_LONG).show();
}
ttobj.speak(resulttxt, TextToSpeech.QUEUE_FLUSH, null);
}
/*#Override
public void onPause(){
if(ttobj !=null){
ttobj.stop();
ttobj.shutdown();
}
super.onPause();
}
*/
**public void speakToMe(View view) {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
"Please speak slowly and enunciate clearly.");
startActivityForResult(intent, VOICE_RECOGNITION_REQUEST);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == VOICE_RECOGNITION_REQUEST && resultCode == RESULT_OK) {
ArrayList<String> matches = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
// TextView textView = (TextView) findViewById(R.id.speech_io_text);
String firstMatch = matches.get(0);
// textView.setText(firstMatch);
DictonaryDAO dictonaryDAO =
db.findname(firstMatch.toUpperCase());
if (dictonaryDAO != null) {
resulttxt = String.valueOf(dictonaryDAO.getnewname());
Toast.makeText(getApplicationContext(), resulttxt.toUpperCase(),
Toast.LENGTH_LONG).show();
ttobj.speak(resulttxt, TextToSpeech.QUEUE_FLUSH, null);
}
}
}**
#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;
}
}
}
Voice Recognition not working for talking tom app so you try to use noise detection with sound meter. below here link for voice/ noise detection with audio recording without click.
http://androidexample.com/Detect_Noise_Or_Blow_Sound_-_Set_Sound_Frequency_Thersold/index.php?view=article_discription&aid=108&aaid=130
Please change SoundMeter.java File
mRecorder.setOutputFile(Environment.getExternalStorageDirectory().
getAbsolutePath() + "/test.3ggp");
I designed a custom keyboard using ImageButtons for Android (using Eclipse). I want to click on a button to write on the text, but every time I click a button, it resets the text, erasing what I previously wrote.
How can I get it to continue writing from the previous text?
This is a basic bit of my code, using two buttons and a text field.
package com.example.nonachan;
import android.R.string;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
public class MainActivity extends Activity {
char g;
char h;
int i = 0;
//char buf[] = new char[10];
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText t =(EditText)findViewById(R.id.t1);
ImageButton n = (ImageButton)findViewById(R.id.b1);
n.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
g = 'd';
// buf[i] = 'd';
t.setText( "" + g);
i++;
}
});
ImageButton a = (ImageButton)findViewById(R.id.b2);
a.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// buf[i] = 'h';
h = 'h' ;
t.setText( "" +h);
i++;
}
});
Button l = (Button)findViewById(R.id.b3);
l.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
});
}
#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;
}
}
t.setText( "" + g);
The above line in your code says to set t's text to "" + g which is equal to "d". It will never append the text since you don't tell it to.
Try adding the existing text in the text field:
t.setText(t.getText().toString() + g);
And you'll have to do the same with t.setText( "" +h); as well.