I have an app and want to have a contact us for where the user inputs their name, address, phone number, and a comment section. Then they will click on compose mail button and it will load the text into the email automaticlly. have some of the code worked out but not sure how to get the text from the edit text into my email msg. anyone have any suggestions on how i can do this. I have attached the code from my xml file and my java file.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Contactform extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.contactform);
Button email = (Button) findViewById(R.id.button30);
email.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
//TODO Auto-generated method stub
Intent email = new Intent(android.content.Intent.ACTION_SEND);
/* Fill it with Data */
email.setType("plain/text");
email.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"ladsoffice#lads-to-leaders.org"});
email.putExtra(android.content.Intent.EXTRA_SUBJECT, "Lads to Leaders/Leaderettes Questions and/or Comments");
email.putExtra(android.content.Intent.EXTRA_TEXT, "Sent from the Lads to Leaders/Leaderettes Android App");
/* Send it off to the Activity-Chooser */
startActivity(Intent.createChooser(email, "Send mail..."));
}
});
}
}
and here is the xml file
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#bf311a" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="18dp"
android:text="#string/name"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView1"
android:layout_alignBottom="#+id/textView1"
android:layout_marginLeft="37dp"
android:layout_toRightOf="#+id/textView1"
android:inputType="textPersonName" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText1"
android:layout_marginTop="35dp"
android:text="#string/addy"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000" />
<EditText
android:id="#+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_alignLeft="#+id/editText1"
android:layout_alignParentRight="true"
android:inputType="textPostalAddress" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/editText2"
android:layout_marginTop="30dp"
android:textColor="#000000"
android:text="#string/cell"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView3"
android:layout_alignBottom="#+id/textView3"
android:layout_alignLeft="#+id/editText2"
android:inputType="phone" >
<requestFocus />
</EditText>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText3"
android:layout_centerHorizontal="true"
android:layout_marginTop="40dp"
android:textColor="#000000"
android:text="#string/questions"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="#+id/editText4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView4"
android:layout_marginTop="25dp"
android:inputType="textMultiLine" />
<Button
android:id="#+id/button30"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/editText4"
android:layout_centerHorizontal="true"
android:layout_marginTop="47dp"
android:background="#drawable/composemail" />
</RelativeLayout>
and here is a ss of what my form looks like if that helps
Thank you for any help you can give. Still learning a bit on how to do some of this stuff so i apologize if this has been asked before but been searching for two days and can't seem to find what i need to do this.
Ok for those who want to know here is the corrected code. The only code i needed to modify was the code for the Java file so thats the only code i will post.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Contactform extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.contactform);
final EditText name = (EditText) findViewById(R.id.editText1);
final EditText addy = (EditText) findViewById(R.id.editText2);
final EditText cell = (EditText) findViewById(R.id.editText3);
final EditText questions = (EditText) findViewById(R.id.editText4);
Button email = (Button) findViewById(R.id.button30);
email.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v){
//TODO Auto-generated method stub
Intent email = new Intent(android.content.Intent.ACTION_SEND);
/* Fill it with Data */
email.setType("plain/text");
email.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"ladsoffice#lads-to-leaders.org"});
email.putExtra(android.content.Intent.EXTRA_SUBJECT, "Lads to Leaders/Leaderettes Questions and/or Comments");
email.putExtra(android.content.Intent.EXTRA_TEXT,
"name:"+name.getText().toString()+'\n'+"address:"+addy.getText().toString()+'\n'+"phone:"+cell.getText().toString()+'\n'+'\n'+questions.getText().toString()+'\n'+'\n'+"Sent from the Lads to Leaders/Leaderettes Android App.");
/* Send it off to the Activity-Chooser */
startActivity(Intent.createChooser(email, "Send mail..."));
}
});
}
}
Ok so just a quick explaintion. you have to declare your edit text in the code after your oncreate method. It must say final in front of it as well. Then you input your strings into the intent for EXTRA TEXT. also i added the '\n' in single quotes. this action will act as an enter button giving each item its own line so for example i only wanted name on one line so i did name+mystring+'\n'. this will make your name and string appear on one line and then go down one line for the next line. Hope this makes since and it helps someone else out.
You can put all data inside email.putExtra(android.content.Intent.EXTRA_TEXT, "Sent from the Lads to Leaders/Leaderettes Android App");
First Get all EditText by ID here in oncreate Like
EditText name = (EditText) findViewById(R.id.editext1);
EditText address = (EditText) findViewById(R.id.editext2);
EditText phone = (EditText) findViewById(R.id.editext3);
Then put all data
email.putExtra(android.content.Intent.EXTRA_TEXT,
"name:"+name.getText().toString()+"address:"+address.getText().toString()+"phone:
"+phone.getText().toString());
Enjoy :)
Related
I'm trying to play around with two activities. Edit and View activity. I would like to get the inputs from the edit activity and show in the view activity. In the edit activity I have the ok/submit button, which approves the changes and take back to the view activity, in this case the input text fields should be updated with the entered data. If the cancel button is pressed, then obviously no changes being done and the user is being taken back to the view activity.
I've most of the implementations done right, but I can't get the entered data to be shown on the view activity. What am I missing?
This is my codes for edit and view activities.
ViewActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class ViewActivity extends AppCompatActivity {
public static final String EXTRA_FNAME = "EXTRA_TEXT";
public static final String EXTRA_LNAME = "EXTRA_TEXT";
public static final String EXTRA_EMAIL = "EXTRA_TEXT";
String Fname, Lname, email;
EditText FNInput, LNInput, emailInput;
Button editButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view);
FNInput = (EditText) findViewById(R.id.FNInput);
LNInput = (EditText) findViewById(R.id.LNInput);
emailInput = (EditText) findViewById(R.id.emailInput);
editButton = (Button) findViewById(R.id.okButton);
editButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
openEditActivity();
}
});
Fname = FNInput.getText().toString();
Lname = LNInput.getText().toString();
email = emailInput.getText().toString();
}
public void openEditActivity(){
Intent intent = new Intent(this, EditActivity.class);
intent.putExtra(EXTRA_FNAME, Fname);
intent.putExtra(EXTRA_LNAME, Lname);
intent.putExtra(EXTRA_EMAIL, email);
startActivity(intent);
}
}
EditActivity.java
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class EditActivity extends AppCompatActivity {
public static final String EXTRA_FNAME = "EXTRA_TEXT";
public static final String EXTRA_LNAME = "EXTRA_TEXT";
public static final String EXTRA_EMAIL = "EXTRA_TEXT";
String Fname, Lname, email;
EditText FNInput, LNInput, emailInput;
Button okButton, cancelButton;
private static final String TAG = "EditActivity";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_edit);
FNInput = (EditText) findViewById(R.id.FNInput);
LNInput = (EditText) findViewById(R.id.LNInput);
emailInput = (EditText) findViewById(R.id.emailInput);
okButton = (Button) findViewById(R.id.okButton);
cancelButton = (Button) findViewById(R.id.cancelButton);
okButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
updateViewActivity();
}
});
cancelButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
FNInput.setText("");
LNInput.setText("");
emailInput.setText("");
finish();
}
});
}
public void updateViewActivity(){
Fname = FNInput.getText().toString();
Lname = LNInput.getText().toString();
email = emailInput.getText().toString();
FNInput.setText(Fname);
LNInput.setText(Lname);
emailInput.setText(email);
Intent intent = new Intent(this, ViewActivity.class);
intent.putExtra(EXTRA_FNAME, Fname);
intent.putExtra(EXTRA_LNAME, Lname);
intent.putExtra(EXTRA_EMAIL, email);
startActivity(intent);
}
}
activity_view.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ViewActivity">
<LinearLayout
android:layout_width="270dp"
android:layout_height="374dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="57dp"
android:layout_marginTop="75dp"
android:orientation="vertical">
<EditText
android:id="#+id/FNInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="First Name"
android:inputType="textPersonName" />
<EditText
android:id="#+id/LNInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Last Name"
android:inputType="textPersonName" />
<EditText
android:id="#+id/emailInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="info#mail.com"
android:inputType="textEmailAddress" />
<Button
android:id="#+id/okButton"
android:layout_width="153dp"
android:layout_height="wrap_content"
android:text="Edit" />
</LinearLayout>
<TextView
android:id="#+id/viewTV"
android:layout_width="134dp"
android:layout_height="33dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginEnd="135dp"
android:layout_marginBottom="18dp"
android:text="View Activity"
tools:layout_editor_absoluteX="15dp"
tools:layout_editor_absoluteY="687dp" />
</RelativeLayout>
activity_edit.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".EditActivity">
<LinearLayout
android:layout_width="270dp"
android:layout_height="374dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="57dp"
android:layout_marginTop="75dp"
android:orientation="vertical">
<EditText
android:id="#+id/FNInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="First Name"
android:inputType="textPersonName" />
<EditText
android:id="#+id/LNInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Last Name"
android:inputType="textPersonName" />
<EditText
android:id="#+id/emailInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="info#mail.com"
android:inputType="textEmailAddress" />
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="#+id/okButton"
style="#style/Widget.AppCompat.Button.Borderless.Colored"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="OK"
android:textColor="#03A9F4" />
<Button
android:id="#+id/cancelButton"
style="#style/Widget.AppCompat.Button.ButtonBar.AlertDialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:textAlignment="center" />
</TableRow>
</LinearLayout>
<TextView
android:id="#+id/viewTV"
android:layout_width="108dp"
android:layout_height="38dp"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="169dp"
android:layout_marginBottom="18dp"
android:text="Edit Activity" />
</RelativeLayout>
I'm sorry this post is going to be lengthy.
When you want to do something like this, you have to follow some steps and follow them properly. which are:-
First, making yourself clear what you want to do exactly, that mean your goal.
Secondly, try to understand what you should do to achieve that goal, like - what thing might have need to do that, resources, tutorial (for this scenario) etc.
Finally let's start searching and learn how to do that.
Here, I can tell you where the problem is, you started learning but didn't completed the learning. I can see you just copied and pasted into two different activities without a reason.
Well, I am sharing what problems I found out from the above code of yours :-
Your ViewActivity.java should be consist of some TextView where you're intended to show your data from your EditActivity.java, which is not there.
You're sending Data with same key every time (another proof of copy pasting, not knowing what is happening) which is -
public static final String EXTRA_FNAME = "EXTRA_TEXT"; // use it as EXTRA_FNAME public static final String EXTRA_LNAME = "EXTRA_TEXT"; // use it as EXTRA_LNAME public static final String EXTRA_EMAIL = "EXTRA_TEXT"; // use it as EXTRA_EMAIL
When you are sending data to your view activity, you need to receive what you were sending by using getIntent() something like :- String s = getIntent().getStringExtra("EXTRA_FNAME"); which will return the value assigned to this key from your previous activity while sending to the present activity.
After receiving the desired value populate your TextView in the next line like this :- textView.setText(s); // fetched from getIntent() previously
For more information you can check this tutorial, which has showed how to pass and view data from one activity to another. Hope you understand.
I want to develop a simple android app that has text view and few buttons.I have put 4 buttons on my app 2 whatsapp and 2 facebook.I want that whenever a person clicks on whatsapp button the text in text view is forwarded to contacts on whatsapp whoever user wants to send message to.Similarly I want that user is able to send private message in fb to his friends.The message would be the same as the text in textview.My MainActivity.java file is below
package com.example.shalabh.gratbites;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
public TextView textView;
public TextView textView2;
public Button button;
public Button button2;
public Button button3;
public Button button4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void onClickListenerButton2()
{
textView=(TextView)findViewById(R.id.textView);
button2=(Button)findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String fb = textView.getText().toString();
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, fb);
startActivity(Intent.createChooser(shareIntent,"Share gratitude"));
}
});
}
public void onClickListenerButton3()
{
textView2 = (TextView)findViewById(R.id.textView2);
button3= (Button)findViewById(R.id.button3);
button3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String whatsAppMessage = textView2.getText().toString();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
sendIntent.setType("text/plain");
// Do not forget to add this to open whatsApp App specifically
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
}
});
}
public void onClickListenerButton()
{
textView= (TextView)findViewById(R.id.textView);
button= (Button)findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String whatsAppMessage = textView.getText().toString();
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, whatsAppMessage);
sendIntent.setType("text/plain");
// Do not forget to add this to open whatsApp App specifically
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
}
});
}
}
My main_activity.xml file is
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity"
android:background="#ffffff">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="At times our own light goes out and is rekindled by a spark from another person. Each of us has cause to think with deep gratitude of those who have lighted the flame within us. "
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_marginTop="38dp"
android:editable="false"
android:elegantTextHeight="false"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Whatsapp"
android:id="#+id/button"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="40dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/button2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignRight="#id/button"
android:layout_alignTop="#+id/button"
android:text="Facebook" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="I wanted to say thanks... and share my gratitude for everything I've been blessed with. Family, friends, and continued support from everyone."
android:id="#+id/textView2"
android:layout_below="#+id/button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="74dp"
android:layout_alignRight="#+id/button2"
android:layout_alignEnd="#+id/button2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="whatsapp"
android:id="#+id/button3"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="40dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Facebook"
android:id="#+id/button4"
android:layout_alignTop="#+id/button3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
The problem is that all the buttons are unresponsive.I am unable to understand the reason.Kindly help me find solution to my problem if possible suggest alternative approach.
P.S. I have not done coding for button4
You have not call methods which you have created. So onClickListeners are not set. So just call this method in onCreate just like this and you are good to go.
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
onClickListenerButton2();
onClickListenerButton3();
onClickListenerButton();
}
I am implementing a program that uses database and interacts with different layouts of entries and editing users.
I'm working with RelativeLayout on all screens. In one of thelayouts, I insert a perfectly aligned button and give the command android:visibility="gone" for him to show upon request.
The problem is that when I need to use it at command editarBt.setVisibility(View.VISIBLE), the button appears out of alignment and overlaps the fields for entering information.
Is there any way to keep the position of command by button?
I will not put the entire code because it has 7 classes, so I'll just put the classes that interest.
EnterPatientActivity Class
package br.luizhmu.aulas_android_sqlite;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
* Created by LuizHMU on 2/17/15.
*/
public class EnterPatientActivity extends Activity {
private Paciente paciente = new Paciente();
private EditText nomeEt;
private EditText emailEt;
private EditText senhaEt;
private Button salvarBt;
private Button editarBt;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inserir_paciente);
nomeEt = (EditText) findViewById(R.id.editTextNome);
emailEt = (EditText) findViewById(R.id.editTextEmail);
senhaEt = (EditText) findViewById(R.id.editTextSenha);
salvarBt = (Button) findViewById(R.id.buttonSalvar);
editarBt = (Button) findViewById(R.id.buttonEditar);
Intent intent = getIntent();
if(intent != null){
Bundle bundle = intent.getExtras();
if(bundle != null){
paciente.setId(bundle.getLong("id"));
paciente.setNome(bundle.getString("nome"));
paciente.setEmail(bundle.getString("email"));
nomeEt.setText(paciente.getNome());
emailEt.setText(paciente.getEmail());
senhaEt.setVisibility(View.GONE);
salvarBt.setVisibility(View.GONE);
editarBt.setVisibility(View.VISIBLE);
}
}
}
public void salvar(View view){
paciente.setNome(nomeEt.getText().toString());
paciente.setEmail(emailEt.getText().toString());
paciente.setSenha(senhaEt.getText().toString());
DataBase bd = new DataBase(this);
bd.inserir(paciente);
Toast.makeText(this, "Paciente inserido com sucesso!", Toast.LENGTH_SHORT).show();
}
public void editar(View view){
paciente.setNome(nomeEt.getText().toString());
paciente.setEmail(emailEt.getText().toString());
DataBase bd = new DataBase(this);
bd.atualizar(paciente);
Toast.makeText(this, "Paciente \""+paciente.getNome()+"\" atualizado com sucesso.", Toast.LENGTH_SHORT).show();
}
}
activity_inserir_paciente.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:background="#ffffea0a"
tools:context=".EnterPatientActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Novo paciente"
android:id="#+id/textView3"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="#ff1727ff"
android:textSize="20dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="*Nome"
android:ems="10"
android:id="#+id/editTextNome"
android:layout_below="#+id/textView3"
android:layout_alignRight="#+id/buttonSalvar"
android:layout_alignEnd="#+id/buttonSalvar" />
<EditText
android:hint="Telefone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:ems="10"
android:id="#+id/editTextTelefone"
android:layout_below="#+id/editTextNome"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:hint="*E-mail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="#+id/editTextEmail"
android:layout_below="#+id/editTextTelefone"
android:layout_alignLeft="#+id/editTextTelefone"
android:layout_alignStart="#+id/editTextTelefone" />
<EditText
android:hint="*Senha"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:ems="10"
android:id="#+id/editTextSenha"
android:layout_below="#+id/editTextEmail"
android:layout_alignLeft="#+id/editTextEmail"
android:layout_alignStart="#+id/editTextEmail" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Salvar"
android:id="#+id/buttonSalvar"
android:onClick="salvar"
android:layout_below="#+id/textView4"
android:layout_alignRight="#+id/editTextSenha"
android:layout_alignEnd="#+id/editTextSenha" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Editar"
android:id="#+id/buttonEditar"
android:layout_alignTop="#+id/buttonSalvar"
android:layout_toLeftOf="#+id/buttonSalvar"
android:layout_toStartOf="#+id/buttonSalvar"
android:visibility="gone"
android:onClick="editar"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="* Campos de preenchimento obrigatório"
android:textColor="#000000"
android:id="#+id/textView4"
android:layout_below="#+id/editTextSenha"
android:layout_alignLeft="#+id/editTextSenha"
android:layout_alignStart="#+id/editTextSenha" />
</RelativeLayout>
In a RelativeLayout, you can prevent views from overlapping by using the layout_toLeftOf, layout_toRightOf, layout_above and layout_below attributes, which expect a view id as value.
Also, you might want to use View.INVISIBLE instead of View.GONE: The former will consider the view during layouting, but hide it. The latter will pretend the view does not exist, therefore altering your layout result.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have used two buttons and two edittexts in my code on clicking left button a new activity starts which is working properly. By clicking right it should show text entered in first edittext if it is present in array but it doesnt show anything in second edittext my code as follows
MainActivity.java
package com.example1.newactivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.text.Editable;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final int a;
Button b = (Button) findViewById(R.id.button1);
Button b1 = (Button) findViewById(R.id.button2);
final EditText e = (EditText) findViewById(R.id.editText1);
final EditText e1 = (EditText) findViewById(R.id.editText2);
final String values[] = new String[] { "Visual Basic", "C#", "C/C++",
"PHP", "Foxpro", "Delphi", "Java", "Perl",
"Ruby", "Cobol" };
a = values.length;
b.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this, Second.class));
}
});
b1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// startActivity(new Intent(MainActivity.this,Third.class));
String number = e.getText().toString();
number = number.toLowerCase();
for (int i=0 ; i<a ; i++){
if (number.equals(values[i].toLowerCase()))
{
e1.setText(values[i]);
}
}
}
});
}
#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;
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_marginLeft="46dp"
android:layout_toRightOf="#+id/button1"
android:text="Search"
tools:ignore="HardcodedText" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="36dp"
android:layout_marginTop="82dp"
android:text="Contacts"
tools:ignore="HardcodedText" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10"
android:inputType="textPersonName" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button2"
android:layout_alignLeft="#+id/editText2"
android:layout_marginBottom="26dp"
android:layout_marginLeft="18dp"
android:ems="10"
android:inputType="textPersonName" />
</RelativeLayout>
You are typing in the wrong EditText (the one below both the buttons as that has request focus to it).
<EditText
android:id="#+id/**editText2"**
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:ems="10"
android:inputType="textPersonName" >
**<requestFocus />**
</EditText>
Type your text in the top most EditText and you shall see the effect. I rn and checked it myself. Have fun. :)
i am very new to android i have created a form with 3 field. I want to display these field data in next screen or in the same screen in TextView but i failed....following are my xml code.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scrollbars="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/TextViewTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/feedbacktitle"
android:textSize="10pt">
</TextView>
<EditText
android:id="#+id/EditTextName"
android:layout_height="wrap_content"
android:hint="#string/feedbackname"
android:inputType="textPersonName"
android:layout_width="fill_parent">
</EditText>
<EditText
android:id="#+id/EditTextEmail"
android:layout_height="wrap_content"
android:hint="#string/feedbackemail"
android:inputType="textEmailAddress"
android:layout_width="fill_parent">
</EditText>
<EditText
android:id="#+id/EditTextFeedbackBody"
android:layout_height="wrap_content"
android:hint="#string/feedbackbody"
android:inputType="textMultiLine"
android:lines="5"
android:layout_width="fill_parent">
</EditText>
<Button
android:id="#+id/ButtonSendFeedback"
android:layout_height="wrap_content"
android:text="#string/feedbackbutton"
android:onClick="sendfeedback"
android:layout_width="fill_parent">
</Button>
<TextView
android:id="#+id/TextViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="10pt">
</TextView>
</LinearLayout>
</ScrollView>
and following are Activity class code
package com.Delegence.FormHandling;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class FormHandlingActivity extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
TextView Text = (TextView)findViewById(R.id.TextViewResult);
public void sendFeedback(View button) {
EditText nameField = (EditText) findViewById(R.id.EditTextName);
String name = nameField.getText().toString();
EditText emailField = (EditText) findViewById(R.id.EditTextEmail);
String email = emailField.getText().toString();
EditText feedbackField = (EditText) findViewById(R.id.EditTextFeedbackBody);
String feedback = feedbackField.getText().toString();
Text.setText(name);
}
}
please guide me how to see these form field value.
Thanks in Advance
to show in same acitivty it should work...
TextView text = (TextView)findViewById(R.id.TextViewResult);
EditText emailField = (EditText) findViewById(R.id.EditTextEmail);
String email = emailField.getText().toString();
text.setText(email );
to show in other activity you need to pass String like email to another activity by intent and set in textview similarly
1----------------
Use intent to send data to another activity .
Intent i = new Intent(this, ActivityTwo.class);
i.putExtra("Value1", "This value one for ActivityTwo ");
i.putExtra("Value2", "This value two ActivityTwo");
2-----------------------------------
Bundle extras = getIntent().getExtras();
if (extras == null) {
return;
}
// Get data via the key
String value1 = extras.getString(Intent.EXTRA_TEXT);
if (value1 != null) {
// Do something with the data
}
http://www.vogella.com/articles/AndroidIntent/article.html