How do i scan multiple QR codes and get the addition? - java

I have n QR codes containing price in integers. I want to scan each qr code and add its price to the total amount. Here is MainActivity.java
eg. If i scan a qr code containing price 40, 40 gets displayed in TextView2. how do i add n qr codes and update the total each time i scan a qrcode?
package com.mycompany.smartshoppingcart;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends Activity {
private static final int ACTIVITY_RESULT_QR_DRDROID = 0;
TextView report;
Button scan;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
report = (TextView) findViewById(R.id.textView2);
scan = (Button) findViewById(R.id.button1);
scan.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent i = new Intent("la.droid.qr.scan");
try {
startActivityForResult(i, ACTIVITY_RESULT_QR_DRDROID);
}
catch (ActivityNotFoundException activity) {
MainActivity.qrDroidRequired(MainActivity.this);
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if( ACTIVITY_RESULT_QR_DRDROID == requestCode
&& data != null && data.getExtras() != null ) {
String result = data.getExtras().getString("la.droid.qr.result");
report.setText(result);
report.setVisibility(View.VISIBLE);
}
}
/*
*
* If we don't have QRDroid Application in our Device,
* It will call below method (qrDroidRequired)
*
*/
protected static void qrDroidRequired(final MainActivity activity) {
// TODO Auto-generated method stub
AlertDialog.Builder AlertBox = new AlertDialog.Builder(activity);
AlertBox.setMessage("QRDroid Missing");
AlertBox.setPositiveButton("Direct Download", new OnClickListener() {
#Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub
activity.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://droid.la/apk/qr/")));
}
});
AlertBox.setNeutralButton("From Market", new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
activity.startActivity(new Intent(Intent.ACTION_VIEW,
Uri.parse("http://market.android.com/details?id=la.droid.qr")));
}
});
AlertBox.setNegativeButton("Cancel", new OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
dialog.cancel();
}
});
AlertBox.create().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.menu_main, menu);
return true;
}
}

You should just store this value in a global variable for the class.
at top of class add int totalCost = 0; (below Button scan; line)
Then in onActivityResult, once you get the result back from the qrcode you should cast this variable to an integer
via int cost = Integer.parseInt(result);
Once you have the integer value of the cost just add it to the total cost
totalCost += cost;
Then update the text label
report.setText("" + totalCost);

Related

maketext is not applicable for arguments

I am writing one app to display user's current address based on latitude and longitude but i am getting one error in this code on line Toast.makeText(this, "No address found try again", Toast.LENGTH_SHORT).show(); It's saying makeText in the type toast is not applicable for arguments. I am unbable to resolve this error.
Any help??
I am trying to display user address in a TextView, but i am not sure whether i am doing good or some runtime error may occur in future.
Here is my Main activity java code:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.common.api.GoogleApiClient.ConnectionCallbacks;
import com.google.android.gms.common.api.GoogleApiClient.OnConnectionFailedListener;
import com.google.android.gms.location.LocationServices;
import android.app.Activity;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentSender.SendIntentException;
import android.location.Geocoder;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.ResultReceiver;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnItemSelectedListener, ConnectionCallbacks, OnConnectionFailedListener{
private static final int REQUEST_RESOLVE_ERROR = 1001;
private static final String DIALOG_ERROR = "dialog_error";
private static final String STATE_RESOLVING_ERROR = "resolving_error";
GoogleApiClient mGoogleApiClient;
protected Location mLastLocation;
private boolean mResolvingError=false;
private AddressResultReceiver mResultReceiver;
// Request code to use when launching the resolution activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Spinner spinner = (Spinner) findViewById(R.id.shop_category);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.shop_category, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
if (mGoogleApiClient == null) {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();
}
mResolvingError = savedInstanceState != null
&& savedInstanceState.getBoolean(STATE_RESOLVING_ERROR, false);
}
#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);
}
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// TODO Auto-generated method stub
TextView mytext = (TextView) view;
Toast.makeText(this,"You selected "+mytext.getText(),Toast.LENGTH_SHORT).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
protected void startIntentService() {
Intent intent = new Intent(this, FetchAddressIntentService.class);
intent.putExtra(Constants.RECEIVER, mResultReceiver);
intent.putExtra(Constants.LOCATION_DATA_EXTRA, mLastLocation);
startService(intent);
}
#Override
public void onConnected(Bundle arg0) {
boolean mAddressRequested=false;
// TODO Auto-generated method stub
TextView myLatitude = (TextView)findViewById(R.id.lat_value);
TextView myLongitude = (TextView)findViewById(R.id.lang_value);
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
myLatitude.setText(String.valueOf(mLastLocation.getLatitude()));
myLongitude.setText(String.valueOf(mLastLocation.getLongitude()));
if (!Geocoder.isPresent()) {
Toast.makeText(this, R.string.no_geocoder_available,
Toast.LENGTH_LONG).show();
return;
}
else{
mAddressRequested=true;
if (mAddressRequested) {
startIntentService();
}
}
}
}
#Override
public void onConnectionSuspended(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void onConnectionFailed(ConnectionResult result) {
// TODO Auto-generated method stub
if (mResolvingError) {
Toast.makeText(this, "Resolving errors", Toast.LENGTH_SHORT).show();
return;
} else if (result.hasResolution()) {
try {
mResolvingError = true;
result.startResolutionForResult(this, REQUEST_RESOLVE_ERROR);
} catch (SendIntentException e) {
// There was an error with the resolution intent. Try again.
mGoogleApiClient.connect();
}
} else {
// Show dialog using GoogleApiAvailability.getErrorDialog()
showErrorDialog(result.getErrorCode());
mResolvingError = true;
}
}
private void showErrorDialog(int errorCode) {
// Create a fragment for the error dialog
ErrorDialogFragment dialogFragment = new ErrorDialogFragment();
// Pass the error that should be displayed
Bundle args = new Bundle();
args.putInt(DIALOG_ERROR, errorCode);
dialogFragment.setArguments(args);
dialogFragment.show(getFragmentManager(), "errordialog");
}
public void onDialogDismissed() {
mResolvingError = false;
}
public static class ErrorDialogFragment extends DialogFragment {
public ErrorDialogFragment() { }
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Get the error code and retrieve the appropriate dialog
int errorCode = this.getArguments().getInt(DIALOG_ERROR);
return GoogleApiAvailability.getInstance().getErrorDialog(
this.getActivity(), errorCode, REQUEST_RESOLVE_ERROR);
}
#Override
public void onDismiss(DialogInterface dialog) {
((MainActivity) getActivity()).onDialogDismissed();
}
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_RESOLVE_ERROR) {
mResolvingError = false;
if (resultCode == RESULT_OK) {
if (!mGoogleApiClient.isConnecting() &&
!mGoogleApiClient.isConnected()) {
mGoogleApiClient.connect();
}
}
}
}
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(STATE_RESOLVING_ERROR, mResolvingError);
}
protected void onStart() {
mGoogleApiClient.connect();
super.onStart();
}
protected void onStop() {
mGoogleApiClient.disconnect();
super.onStop();
}
class AddressResultReceiver extends ResultReceiver {
public AddressResultReceiver(Handler handler) {
super(handler);
}
#Override
protected void onReceiveResult(int resultCode, Bundle resultData) {
// Display the address string
// or an error message sent from the intent service.
String mAddressOutput = resultData.getString(Constants.RESULT_DATA_KEY);
// Show a toast message if an address was found.
if (resultCode == Constants.SUCCESS_RESULT) {
TextView myaddress=(TextView) findViewById(R.id.myaddress);
myaddress.setText(mAddressOutput);
}
else{
Toast.makeText(this, "No address found try again", Toast.LENGTH_SHORT).show();
}
}
}
}
Thank you in advance.
Replace this with MainActivity.this as the first parameter to your makeText() call. this is an instance of your AddressResultReceiver inner class. It is not your activity, and makeText() needs a Context, like an Activity.
Use getApplicationContext() instead of this. Use:
Toast.makeText(getApplicationContext(), "message", Toast.LENGTH_SHORT).show();
this refers to AddressResultReceiver which is not subclass of Context.
Toast.makeText() needs Context.

“Cannot make a static reference to a non-static method” in Android. Simply case [duplicate]

This question already has answers here:
Cannot make a static reference to the non-static method
(8 answers)
Closed 8 years ago.
I am trying to call a method after clicking on a Button but I'm getting this error:
"Cannot make a static reference to a non-static method”
here is the code, the only problematic thing in the code is when I try to call reakcja(); in button Intencja. Can you please help me?
package com.example.buttonwork;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
public class MainActivity extends ActionBarActivity {
public void reakcja(){
Intent i = new Intent(this, Intencja.class);
startActivity(i);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.i("click", "On create!");
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
Log.i("click","Teraz chyba pierwszy zapis instancji");
}
}
#Override
public void onStop(){
Log.i("click","onStop");
super.onStop();
}
#Override
public void onPause(){
Log.i("click","onPause");
super.onPause();
}
#Override
public void onResume(){
Log.i("click","onResume");
super.onResume();
}
#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);
Log.i("click","Pierwsze tworzenie 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) {
//Toast.makeText(item.getContext(), "elo", Toast.LENGTH_SHORT).show();
Log.i("click", "menu");
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
Button but1;
Button Intencja;
TextView tv1;
EditText et1;
Button raf,kas;
ToggleButton off;
SeekBar sk1;
int kto;
CheckBox cb1,cb2;
RatingBar rb1;
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
Log.i("click","Tutaj wszystko sie dzieje");
rb1 = (RatingBar) (rootView.findViewById(R.id.rb1));
/*rb1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(v.getContext(), String.valueOf(rb1.getProgress()), Toast.LENGTH_SHORT).show();
}
});*/
rb1.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
#Override
public void onRatingChanged(RatingBar ratingBar, float rating,
boolean fromUser) {
// TODO Auto-generated method stub
Toast.makeText(ratingBar.getContext(), String.valueOf(rating), Toast.LENGTH_SHORT).show();
}
});
Intencja = (Button) (rootView.findViewById(R.id.Intencja));
Intencja.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
reakcja();
}
});
cb1 = (CheckBox) (rootView.findViewById(R.id.cb1));
cb2 = (CheckBox) (rootView.findViewById(R.id.cb2));
off = (ToggleButton) (rootView.findViewById(R.id.toggleButton1));
off.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(v.getContext(), off.getText(), Toast.LENGTH_SHORT).show();
}
});
sk1 = (SeekBar) (rootView.findViewById(R.id.seekBar1));
sk1.setOnSeekBarChangeListener(new SeekBar.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
//Toast.makeText(seekBar.getContext(), String.valueOf(progress), Toast.LENGTH_SHORT).show();
tv1.setText(String.valueOf(progress));
return;
}
});
/*sk1.setOnSeekBarChangeListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(v.getContext(), sk1.getProgress(), Toast.LENGTH_SHORT).show();
}
});*/
tv1 = (TextView) (rootView.findViewById(R.id.tv1));
et1 = (EditText) (rootView.findViewById(R.id.et1));
raf = (Button) (rootView.findViewById(R.id.button1));
raf.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(v.getContext(), "Ralfo jest miszczem", Toast.LENGTH_SHORT).show();
kto = 1;
sk1.setProgress(50);
}
});
kas = (Button) (rootView.findViewById(R.id.button2));
kas.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(v.getContext(), "Nie, to Ralfo jest miszczem", Toast.LENGTH_SHORT).show();
kto =2;
sk1.setProgress(50);
}
});
but1 = (Button) (rootView.findViewById(R.id.b1));
but1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
tv1.setText(et1.getText().toString());
Toast.makeText(v.getContext(), String.valueOf(cb1.isChecked() && cb2.isChecked()), Toast.LENGTH_SHORT).show();
// wyświetla Toasta true albo false sprawdzając CheckBoxy i robiąc na nich koniunkcję
}
});
return rootView;
}
}
}
PlaceholderFragment is a static class, so you cannot call non-static method reakcja() from it. Make reakcja() static or PlaceholderFragment non-static.

Set OnclickListener For ListView Such that line selected in list is used as edit text in another class

I have two classes for my translation app. One(Voice.java) in which we speak and RecognizerIntent gets our speech and displays it in form of a list. This is voice.java
package com.example.testing;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
public class Voice extends Activity implements OnClickListener{
ListView lv;
static final int check=1111;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.voice);
lv=(ListView)findViewById(R.id.lvVoiceReturn);
Button b=(Button)findViewById(R.id.bVoice);
b.setOnClickListener(this);
lv.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.bVoice:
Intent i=new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
i.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
i.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak Up");
startActivityForResult(i, check);
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if(requestCode == check && resultCode==RESULT_OK){
ArrayList<String> results=data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,results));
}
super.onActivityResult(requestCode, resultCode, data);
}
}
And another class TranslateActivity which has one button and two edit text. Button works as translator of text from 1st edit text to translated text in second edit Text and speaks the translated text also . Code is as follows:
package com.example.testing;
import java.util.Locale;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import com.memetix.mst.language.Language;
import com.memetix.mst.translate.Translate;
public class TranslateActivity extends Activity implements OnClickListener {
EditText etInput
;
EditText etOutput;
TextToSpeech tts;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_translate);
Translate.setClientId("d6159b31-37ba-4668-a31f-de0de6c47a38");
Translate.setClientSecret("UMjSB3cHaSkLE+2xw4+a4dLIFahLdQQqh1YOhXdqfh4");
Button Trans = (Button)findViewById(R.id.translate);
etInput = (EditText)findViewById(R.id.input);
etOutput = (EditText)findViewById(R.id.output);
Trans.setOnClickListener(this);
tts =new TextToSpeech(TranslateActivity.this, new TextToSpeech.OnInitListener() {
#Override
public void onInit(int status) {
// TODO Auto-generated method stub
if(status !=TextToSpeech.ERROR){
tts.setLanguage(Locale.US);
}
}
});
}
#Override
public void onClick(View v) {
//get the text entered
String In =etInput.getText().toString();
String s[]=In.split(" ");
//String out[]= new String[3];
String str=new String();
String outString=new String();
//String Out;
try {
for(int i=0;i<s.length;i++){
if(s[i].equals("who")){
str="whoa";
//etOutput.setText("whoa");
//str=etOutput.getText().toString();
//tts.speak(str,TextToSpeech.QUEUE_FLUSH, null);
}else if(s[i].equals("are")){
// etOutput.setText("arey");
str="arey";
//str=etOutput.getText().toString();
//tts.speak(str,TextToSpeech.QUEUE_FLUSH, null);
}else if(s[i].equals("you")){
str="ram";
//etOutput.setText("your");
//str=etOutput.getText().toString();
//tts.speak(str,TextToSpeech.QUEUE_FLUSH, null);
}
outString+=str ;
outString+=" ";
}
tts.speak(outString,TextToSpeech.QUEUE_FLUSH, null);
// String Out = Translate.execute(In, Language.AUTO_DETECT, Language.FRENCH);
// etInput.setText(Out);
// etOutput.setText(Out);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Now I want an on click listener for list view such that whatever line I click on list View, it gets used as edit Text of 2nd class(TranslateActivity.java) and gets translated without clicking the button on 2nd class. That is functionality of button in 2nd class is done by just clicking on list view in 1st class.Anyone who knows how to do this?

Android application Error passing data

I keep getting an error that shows:
(04-04 23:26:29.557: E/dalvikvm(716): Unable to open stack trace file '/data/anr/traces.txt': Permission denied).
Please help. I'm trying to pass Data for an android app.
public class Data extends Activity implements OnClickListener{
Button start, startFor;
EditText sendET;
TextView gotAnswer;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.get);
initialize();
}
private void initialize(){
start = (Button) findViewById(R.id.bSA);
startFor = (Button) findViewById(R.id.bSAFR);
sendET = (EditText) findViewById(R.id.etSend);
gotAnswer = (TextView) findViewById(R.id.tvGot);
start.setOnClickListener(this);
startFor.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.bSA:
String bread = sendET.getText().toString();
Bundle basket = new Bundle();
basket.putString("key", bread);
Intent a = new Intent(Data.this,OpenedClass.class);
a.putExtras(basket);
startActivity(a);
break;
case R.id.bSAFR:
Intent i = new Intent(Data.this,OpenedClass.class);
startActivityForResult(i,0);
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
}
}
package com.Christian.Amaro;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class OpenedClass extends Activity implements OnClickListener,
OnCheckedChangeListener {
TextView question, test;
Button returnData;
RadioGroup selectionList;
String gotBread,setData;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.send);
inilialize();
Bundle gotBasket = getIntent().getExtras();
gotBread = gotBasket.getString("key");
question.setText(gotBread);
}
private void inilialize() {
// TODO Auto-generated method stub
question = (TextView) findViewById(R.id.tvQuestion);
test = (TextView) findViewById(R.id.tvText);
returnData = (Button) findViewById(R.id.bReturn);
returnData.setOnClickListener(this);
selectionList = (RadioGroup) findViewById(R.id.rgAnswers);
selectionList.setOnCheckedChangeListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
#Override
public void onCheckedChanged(RadioGroup arg0, int arg1) {
// TODO Auto-generated method stub
switch (arg1) {
case R.id.rCrazy:
setData = "Probably right!";
break;
case R.id.rSexy:
setData = "Definitely Probably right!";
break;
case R.id.rBoth:
setData = "Spot On!";
break;
}
test.setText(setData);
}
}
adb shell
root#android: # cd /data/anr
root#android:/data/anr # ls -l traces.txt
-rw-rw-rw- system system 76808 2013-04-05 13:03 traces.txt
root#android:/data/anr #
-rw-rw-rw is what you should see (it means permissions to read and write)
If you see something different, do
root#android:/data/anr # chmod 666 traces.txt
PS Your device must be rooted, but otherwise you would be unable to get this problem :)

Retrieve item from Spinner and put Some conditions

i have 2 arrays first for Hours and second for minutes, this is my arrays declare it in string.xml
` <string-array name="feedbacktypelist">
<item>#string/hr0</item>
<item>#string/hr1</item>
<item>#string/hr2</item>
</string-array>
<string-array name="array2">
<item>#string/min5</item>
<item>#string/min10</item>
<item>#string/min15</item>
<item>#string/min20</item>
<item>#string/min25</item>
<item>#string/min30</item>
<item>#string/min35</item>
<item>#string/min40</item>
<item>#string/min45</item>
<item>#string/min50</item>
<item>#string/min55</item>
<item>#string/min59</item>
</string-array>`
and this is my code in java
package lmp.app.pkg;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
public class CreateNewForm extends Activity implements OnItemSelectedListener {
Button Browse;
ImageView CasePic;
Spinner CaseDurationH, CaseDurationM;
TextView tesst;
RadioGroup GenderSelection;
EditText CaseName, CaseClothes, CaseMoreInfo, CaseAge;
Button Next;
//For Browsering Picture
private static final int SELECT_PICTURE = 1;
private String selectedImagePath;
#Override
protected void onCreate(Bundle savedInstanceState)
{
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.create_new_form);
//To Call initializer Function
initializer();
//j list
// 1-For Uploading Picture
Browse.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
// in onCreate or any event where your want the user to
// select a file
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), SELECT_PICTURE);
}
});
// 1-Name
final MyCase case1 = new MyCase();
case1.setName(CaseName.getText().toString());
// 2-Gender For Group Radio
GenderSelection.clearCheck();
GenderSelection.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio0:
case1.setGender("Male");
break;
case R.id.radio1:
case1.setGender("Female");
break;
default:
break;
}
}
});
//3-Age
String age = CaseAge.getText().toString();
/*int tstnum =case1.getAge();
tesst.setText(tstnum); */
//4-Duration Time
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.feedbacktypelist, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
CaseDurationH.setAdapter(adapter);
//5-Case Clothes
case1.setClothes(CaseClothes.getText().toString());
//6-Case More Information
case1.setMoreInfo(CaseMoreInfo.getText().toString());
//Move to 2nd form page
Next= (Button)findViewById(R.id.Next2);
Next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
switch (v.getId()) {
case R.id.Next2:
try
{
Intent k = new Intent(CreateNewForm.this, CreateNewForm_2.class);
startActivity(k);
}catch(Exception e){
}
break;
}
}
});
//Spinner
CaseDurationH.setOnItemSelectedListener(new OnItemSelectedListener() {
int i =CaseDurationH.getSelectedItemPosition();
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
int i = CaseDurationH.getSelectedItemPosition();
if(i==2){
CaseDurationM.setEnabled(false);
}
String str = parent.getSelectedItem().toString();
if(str.equals("hr0"))
{
}
if(str.equals("hr1"))
{
}
if(str.equals("hr2"))
{
CaseDurationM.setEnabled(false);
}
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
} });
}
// To initialize the variables
private void initializer() {
// TODO Auto-generated method stub
//This information will be filled by a user
//CasePic = (ImageView) findViewById(R.id.imageView1);
CaseName= (EditText) findViewById(R.id.caseNm);
GenderSelection= (RadioGroup) findViewById(R.id.radioGroup1);
CaseAge= (EditText) findViewById(R.id.caseaage);
tesst= (TextView) findViewById(R.id.textView8);
CaseDurationH= (Spinner) findViewById(R.id.Shr);
CaseDurationM= (Spinner) findViewById(R.id.Smin);
CaseClothes= (EditText) findViewById(R.id.caseClothes);
CaseMoreInfo= (EditText) findViewById(R.id.caseMrInfo);
CasePic = (ImageView) findViewById(R.id.casepic);
Browse = (Button) findViewById(R.id.browseCasePic);
}
//For Uploading Picture
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == SELECT_PICTURE) {
Uri selectedImageUri = data.getData();
selectedImagePath = getPath(selectedImageUri);
}
}
}
//For Uploading Picture
public String getPath(Uri uri) {
String[] projection = { MediaStore.Images.Media.DATA };
Cursor cursor = managedQuery(uri, projection, null, null, null);
int column_index = cursor
.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// TODO Auto-generated method stub
}
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
i want:
1- retrieve the item in spinner that the user choose it, not the positon
2-if the user choose from spinner1 the item "hr02" then the spinner2 will disable
Thank you for help me, StackOverFlow members your my hero now! :")
use this
String str = parent.getSelectedItem().toString();
if(str.equals("hr2")
{
spinner2.setEnabled(false);
}
Try this:
String str = parent.getSelectedItem().toString();
if (str.equals("hr0")){
//retrieve the item as string
}
if (str.equals("hr1")){
//retrieve the item as string
}
if (str.equals("hr2")){
//retrieve the item as string
//make the 2nd spinner disable
}

Categories

Resources