onClick method keeps telling me "Unfortunately,myapp has stopped" - android

I am using a startActivityForResult method to get a string from an activity,the activity has an editview and a button to return the inputted value of the editview,but when i click on the button,it keeps telling me "Unfortunately,myapp has stopped",dont know where the problem is coming from?
This is the line calling the activity
startActivityForResult(new Intent("com.dreama.trafic.SearchActivity"),request_Code);
and this is the xml file for the activity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editSearch"
android:layout_centerHorizontal="true"
android:layout_marginBottom="60dp"
android:text="#string/searchLocation"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#f00" />
<EditText
android:id="#+id/editSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10" />
<Button
android:id="#+id/searchButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp"
android:onClick="click"
android:text="#string/search" />
</RelativeLayout>
and this is the click method
public void click(View view) {
Intent data = new Intent();
EditText editSearch = (EditText) findViewById(R.id.editSearch);
data.setData(Uri.parse(editSearch.getText().toString()));
setResult(RESULT_OK, data);
finish();
}

Try this..
I guess you are getting ActivityNotFoundException
Change this..
startActivityForResult(new Intent("com.dreama.trafic.SearchActivity"),request_Code);
to
startActivityForResult(new Intent(currentActivity.this,SearchActivity.class),request_Code);

it also may be because you have not declared SearchActivity.java in your manifest file as
<activity android:name=".SearchActivity"/>

Related

get popup valus and send it to mail in android

i have an app which has a form values..
Title...
username...
email...
send(Button)
and this form is shown as popup window
my popup xml code is
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="#+id/compose_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C0000000"
android:visibility="visible"
android:gravity="center"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:id="#+id/popup"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#f47d7d"
android:layout_gravity="center"
android:paddingLeft="20sp"
android:paddingRight="60sp"
android:paddingTop="20sp"
android:paddingBottom="20sp"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Popup"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/topicname"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Topic Name" />
<EditText
android:id="#+id/topiccontent"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Topic Headings" />
<EditText
android:id="#+id/usermail"
android:layout_marginTop="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your mail" />
<Button
android:id="#+id/close"
android:layout_marginTop="10dp"
android:layout_gravity=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send" />
</LinearLayout>
</RelativeLayout>
firstly,my popup window form is not editable..please suggest something to make it editable
secondly, i want to get these values(title,username and email) and send it to specified email address on send button click.
Thanks in advance
BackgroundMail.newBuilder(getActivity())
.withUsername("Your newly created Gmail account")
.withPassword("your password")
.withMailto(email.getText().toString())
.withSubject("TEST ANDROID STUDIO")
.withBody("ELOWWWWW")
.withOnSuccessCallback(new BackgroundMail.OnSuccessCallback() {
#Override
public void onSuccess() {
//do some magic
Log.d(TAG,"MAI SENDED");
}
})
.withOnFailCallback(new BackgroundMail.OnFailCallback() {
#Override
public void onFail() {
Log.d(TAG,"MAI FAILED");
}
})
.send();
Call the above method inside your send button clicklistner
to import the library as module get it from this link https://github.com/yesidlazaro/GmailBackground

Calling a phone number from TextView in Android

I am testing this little code snippet on a tablet. So i am not sure if it is not working because of that. Nothing happens when i click the number. No error message or log shown in LogCat. Please look at my implementation below.:
MainActivity.java
public void callPolice(View view){
TextView tv = (TextView) findViewById(R.id.policeno);
String val = tv.getText().toString();
Intent intent = new Intent(Intent.ACTION_DIAL);
intent.setData(Uri.parse("tel:"+val));
startActivity(intent);
Log.v("Calling", "Calling..... "+val);
}
activity_main.xml
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="999"
android:textColor="#000000"
android:textSize="13pt"
android:textStyle="bold"
android:id="#+id/policeno"
android:layout_alignTop="#+id/textView2"
android:layout_alignRight="#+id/textView5"
android:layout_alignEnd="#+id/textView5"
android:onClick="callPolice"/>
AndroidManifest.xml
<uses-permission android:name = "andriod.permission.CALL_PHONE" />
Just put android:clickable="true" in textview.
<TextView
android:id="#+id/policeno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="87dp"
android:onClick="callPolice"
android:text="999"
android:textColor="#000000"
android:textSize="13pt"
android:clickable="true"
android:textStyle="bold" />
if you want to call you should use
Intent.setAction(Intent.ACTION_CALL);
If you are using fragments the xml onclick may not work. So try implementing onclick listner. Put the log before starting activity.

Android: opening activity from widget as dialog and disabling the background

I am working on widget project and when I touch the widget a new activity that is styled like a dialog box. The main activity opens and the dialog styled activity appears and when I touch the main activity the dialog styled activity disappears.
1) Is there a way to disable the activity? or
2) Is there away to open the dialog styled activity without opening the activity?
Here is my onReceive Class in my BroadcastReceiver
public void onReceive(Context context, Intent intent)
{
Log.i(TAG,"In onReceive");
if(intent.getAction().equals(INTENT_ACTION))
{
Intent mIntent = new Intent(context,sendActivity.class);
mIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mIntent);
}
}
Dialog Styled Actvity
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
android:focusableInTouchMode="true">
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp" />
<TextView
android:id="#+id/tvdialogTitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:layout_toRightOf="#+id/image"/>
<TextView
android:id="#+id/tvStatus01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF" />
<TextView
android:id="#+id/tvStatus02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"/>
<Button
android:id="#+id/btnWidgetDialogCancel"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text="Cancel"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/image"
/>
</RelativeLayout>
Part of my Manifest
<activity
android:name="com.example.widget.sendActivity"
android:theme="#android:style/Theme.Dialog"
android:excludeFromRecents="true">
</activity>
Thanks in advance.
I used this line if anyone else is interested
this.setFinishOnTouchOutside(false);

Change layout_bellow attribute field to another field programmatically

Given the following code:
<RelativeLayout
android:id="#+id/rel"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textPersonalInfoEmpty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="20dp"
android:hint="Edit to set your personal info"
android:textSize="16sp"
android:visibility="gone" />
<EditText
android:id="#+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginTop="15dp"
android:hint="Name"
android:visibility="gone"
android:textSize="16sp" />
<Button
android:id="#+id/insertGameId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/editName"
android:layout_marginTop="20dp"
android:text="Insert" />
</RelativeLayout>
The TextView and the EditText are visible depending the user interaction and both will never be visible at the same time. One per time only!
The problem is the third component(Button) need to change the attribute android:layout_below depending on which component is visible.
I need to this programmatically.
Any help?
Use Relativelayout for your textview and edittext. And relativelayout's height:wrap-content
Then give an id to your relativelayout
and then add this line your xml file for your button
<Button
android:layout_below="#id/RealtiveLayoutid" />
Thats all
First, use a ToggleButton instead of Button. It can have all the attributes that you assigned to it.
Next add this to the ToggleButton:
<ToggleButton
....
android:textOn="#string/ifTextView"
android:textOff="#string/ifTextBox"
android:onClick="onToggleClicked"
/>
Then this for the activity
public void onToggleClicked(View v) {
boolean on = ((ToggleButton) v).isChecked();
if(on) {
theTextView.setVisibility(View.VISIBLE);
theTextBox.setVisibility(View.INVISIBLE);
} else {
theTextBox.setVisibility(View.VISIBLE);
theTextView.setVisibility(View.INVISIBLE);
}
}
Remember to import the required classes.

Filter some Switch element from list of other elements from XML file

I am creating an android application in which i have a activity which contain several elements like Switch, TextView etc.
I need to get the values from all Switch elements whether it is checked or not.
it will be great if anyone show me the proper way to transfer multiple values to different activity for further calculation.
Thanks
here is my XML code:
<LinearLayout
android:id="#+id/configSwitchHldr"
android:layout_marginTop="10dp"
android:layout_span="2"
android:gravity="center"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp" >
<TextView
android:text="#string/coreHardware"
android:layout_width="fill_parent"
android:layout_height="20dp"
android:textColor="#color/green"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#363636" />
<Switch
android:id="#+id/switch1"
android:layout_width="fill_parent"
android:layout_height="14.5sp"
android:textOn="ON"
android:textOff="OFF"
android:text="CPU"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#363636" />
<Switch
android:id="#+id/switch2"
android:layout_width="fill_parent"
android:layout_height="14.5sp"
android:textOn="ON"
android:textOff="OFF"
android:text="Memory"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#363636" />
<Switch
android:id="#+id/switch3"
android:layout_width="fill_parent"
android:layout_height="14.5sp"
android:textOn="ON"
android:textOff="OFF"
android:text="Storage"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#363636" />
</LinearLayout>
Ok, so based on your comment this is how it could be done:
In your first Activity, you would need a method, that gathers all the switches states and pass them along to the next activity. Passing parameters along to other Activities can be achieved by putting them inside the Intent you send to open the new Activity.
The method for getting the Switches states and passing them to a new Activity would roughly look something like this:
Intent i = new Intent(MainActivity.this, NewActivity.class);
i.putExtra("switch1", switch1.isChecked());
i.putExtra("switch2", switch2.isChecked());
i.putExtra("switch3", switch3.isChecked());
startActivity(i);
Put this inside the onClickListener for a Button for instance like so:
button1 = (Button) findViewById(R.id.button1);
button1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, NewActivity.class);
i.putExtra("switch1", switch1.isChecked());
i.putExtra("switch2", switch2.isChecked());
i.putExtra("switch3", switch3.isChecked());
startActivity(i);
}
});
Now when you click the Button you'll be sent to NewActivity.
To retrieve the parameters passed on from the MainActivity, you should do something like this in you onCreate method of the NewActivity:
boolean bool1 = getIntent().getExtras().getBoolean("switch1");
boolean bool2 = getIntent().getExtras().getBoolean("switch2");
boolean bool3 = getIntent().getExtras().getBoolean("switch3");
You could pass the variables on from MainActivity by putting them inside a boolean array, but that is overkill in my opinion.
Also take a look at this SO post: How do I pass data between Activities in Android application? - there's a lot of these.

Categories

Resources