How to send Picture taken from Camera through email Android - java

I am writting an application for educational purposes in which user takes a picture from camera and sends it via email. I wrote almost all the code except the code whi But I don't know how to do it as I am learning android. Here is my code, What should I add in this code:
package com.umer.practice2;
import java.io.IOException;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
public class SendPhoto extends Activity implements View.OnClickListener{
TextView tv1,tv2;
EditText e1,e2;
ImageView pi;
ImageButton pb;
Button pb1,pb2;
Intent photo;
Bitmap bmp;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sendphoto);
pb1.setOnClickListener(this);
pb2.setOnClickListener(this);
pb.setOnClickListener(this);
initializeView();
}
private void initializeView() {
// TODO Auto-generated method stub
tv1= (TextView) findViewById(R.id.pt1);
tv2= (TextView) findViewById(R.id.pt2);
e1= (EditText) findViewById(R.id.pe1);
e2= (EditText) findViewById(R.id.pe2);
pi= (ImageView) findViewById(R.id.p1);
pb= (ImageButton) findViewById(R.id.pib2);
pb1= (Button) findViewById(R.id.pbut1);
pb2= (Button) findViewById(R.id.pbut2);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.pbut1:
String email[]={e2.getText().toString()};
Intent emailIntent= new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, email);
emailIntent.setType("image/jpeg");
startActivityForResult(emailIntent, 1);
break;
case R.id.pib2:
photo= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(photo,2);
break;
case R.id.pbut2:
try {
getApplicationContext().setWallpaper(bmp);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
pi.setImageBitmap(bmp);
}
}

In you onActivityResult method you should save the bitmap into a file on your SD-Card, next you should attach a file to the email intent.
how to save image to a file on sd-card
How to save a bitmap into phone's gallery?
how to attach file to an email intent:
Trying to attach a file from SD Card to email

Related

Android camera application. Two activities

I am trying to deveolp an Android application. I am learning Android so there I go.
My aplication is similar to this one: http://www.tutorialspoint.com/android/android_camera.htm ;
Except I have two activities.. One is called Report.java and the other one is called Form.java.
In Report.java, I have a button, when I click the button, I want to open the camera and take a picture. After I took the picture, I want to start the second activity (Form.java) and my image to be saved in an ImageView.
How can I do that? Thank you in advance.
Report.java
package com.example.harta;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class Report extends Activity implements View.OnClickListener{
ImageView iv;
Button report;
final static int cameraData = 0;
Bitmap bmp;
Intent i;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.report);
initialize();
report.setOnClickListener(this);
}
private void initialize() {
// TODO Auto-generated method stub
report = (Button) findViewById(R.id.bReport);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.bReport:
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(i, cameraData);
break;
}
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
Intent i = new Intent(Report.this, Formular.class);
startActivity(i);
}
}
}
Form.java
package com.example.harta;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
public class Formular extends Activity{
Button button;
ImageView iv;
int cameraResults;
final static int cameraData = 0;
Bitmap bmp;
TextView tvAdress, tvAmpers, tvCommunication, tvCoordinates;
TextView tvName, tvInformations, tvDataIntro, tvPhone, tvLatitude;
TextView tvLongitude, tvInstalledPower, tvContor, tvNetwork;
EditText etAdress, etAmpers, etCommunication, etCoordinates;
EditText etName, etInformations, etDataIntro, etPhone, etLatitude;
EditText etLongitude, etInstalledPower, etContor, etNetwork;
Spinner spinNetwork;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.formular);
initialize();
}
private void initialize() {
// TODO Auto-generated method stub
tvAdress = (TextView) findViewById(R.id.tvAdresa);
tvAmpers = (TextView) findViewById(R.id.tvAmperaj);
tvCommunication = (TextView) findViewById(R.id.tvComunicatie);
tvCoordinates = (TextView) findViewById(R.id.tvCoord);
tvName = (TextView) findViewById(R.id.tvDenumire);
tvInformations = (TextView) findViewById(R.id.tvInfo);
tvDataIntro = (TextView) findViewById(R.id.tvIntroducereDate);
tvPhone = (TextView) findViewById(R.id.tvIPtelefon);
tvLatitude = (TextView) findViewById(R.id.tvLat);
tvLongitude = (TextView) findViewById(R.id.tvLong);
tvInstalledPower = (TextView) findViewById(R.id.tvPutereInstalata);
tvContor = (TextView) findViewById(R.id.tvSerieContor);
tvNetwork = (TextView) findViewById(R.id.tvTipulRetelei);
etAdress = (EditText) findViewById(R.id.etAdresa);
etAmpers = (EditText) findViewById(R.id.etAmperaj);
etCommunication = (EditText) findViewById(R.id.etComunicatie);
etName = (EditText) findViewById(R.id.etDenumire);
etPhone = (EditText) findViewById(R.id.etIPtelefon);
etInstalledPower = (EditText) findViewById(R.id.etPutereInstalata);
etContor = (EditText) findViewById(R.id.etSerieContor);
spinNetwork = (Spinner) findViewById(R.id.spinTipulRetelei);
button = (Button) findViewById(R.id.bTrimitere);
iv = (ImageView) findViewById(R.id.ivPic);
}
public void onClick(View v) {
// TODO Auto-generated method stub
}
}

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 :)

Turn on/off sound button not working

I have it in my settings activity that when a user clicks the ToggleButton it's supposed to mute the sound throughout my application but it's not working.The SoundPool onClick button sounds I putted in my Tutorial classes are still playing sound onClick.I already specified my Shared Preferences with the ToggleButton.
Here is my code,
package com.fullfrontalgames.numberfighter;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ToggleButton;
public class Settings extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
Button Notifications = (Button) findViewById(R.id.Notifications);
Button Done = (Button) findViewById(R.id.done);
Button AccountSettings = (Button) findViewById(R.id.AccountSettings);
final ToggleButton AT = (ToggleButton) findViewById(R.id.AudioToggle);
AT.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
SharedPreferences appPrefs =
getSharedPreferences("com.fullfrontalgames.numberfighter.Settings_preferences",
MODE_PRIVATE);
SharedPreferences.Editor editor = appPrefs.edit();
editor.putBoolean("atpref", AT.isChecked()); //value to store
editor.commit();
if ((AT.isChecked())) {
AT.setSoundEffectsEnabled(true);
} else {
AT.setSoundEffectsEnabled(false);
}
}
});
SharedPreferences appPrefs =
getSharedPreferences("com.fullfrontalgames.numberfighter.Settings_preferences",
MODE_PRIVATE);
boolean atpref = appPrefs.getBoolean("atpref", true); //default is true
AT.setChecked(atpref);
Done.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent Intent = new Intent(Settings.this,activity_main.class);
Intent.setFlags(android.content.Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(Intent);
}
});
Notifications.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fullfrontalgames.numberfighter.Notifications"));
}
});
AccountSettings.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
startActivity(new Intent("com.fullfrontalgames.numberfighter.AccountSettings"));
}
});
}
according to doc of setSoundEffectsEnabled
Set whether this view should have sound effects enabled for events
such as clicking and touching.
You may wish to disable sound effects for a view if you already play
sounds, for instance, a dial key that plays dtmf tones.
So this function is supposed to set on off of the sound effect of the view (like click or touch). Not to set on off of the device sound.
For your purpose check AudioManager

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