I wrote an activity to send an email in the app. However, i can't find a way to set the recipient and subject in the edittext fill. How should I set the email at the beginning ??
my activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feedback_email);
emailAddress = (EditText) findViewById(R.id.email);
emailSubject = (EditText) findViewById(R.id.subject);
message = (EditText) findViewById(R.id.message);
sendEmailButton = (Button) findViewById(R.id.send_button);
sendEmailButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String toemailAddress = emailAddress.getText().toString();
String msubject = emailSubject.getText().toString();
String mmessage = message.getText().toString();
Intent emailApp = new Intent(Intent.ACTION_SEND);
emailApp.putExtra(Intent.EXTRA_EMAIL, new String[]{toemailAddress});
emailApp.putExtra(Intent.EXTRA_SUBJECT, msubject);
emailApp.putExtra(Intent.EXTRA_TEXT, mmessage);
emailApp.setType("message/rfc822");
startActivity(Intent.createChooser(emailApp, "Send Email Via"));
}
});
}
my xml file
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subject"
android:textStyle="bold" />
<EditText
android:id="#+id/subject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toEndOf="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:hint="Subject"
android:inputType="text" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView"
android:layout_marginTop="43dp"
android:text="To"
android:textStyle="bold" />
<EditText
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView2"
android:layout_toEndOf="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:hint="Email"
android:inputType="textEmailAddress" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/email"
android:layout_marginTop="15dp"
android:text="Message:"
android:textStyle="bold" />
<EditText
android:id="#+id/message"
android:layout_width="wrap_content"
android:layout_height="150dp"
android:gravity="top"
android:hint="Your message here..."
android:inputType="textMultiLine"
android:layout_centerVertical="true"
android:layout_alignParentStart="true"
android:layout_alignEnd="#+id/email" />
<Button
android:id="#+id/send_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#498b24"
android:paddingTop="50dp"
android:padding="5dp"
android:text="Send Message "
android:textColor="#fff"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="46dp" />
How should I set the email at the beginning ??
I am not sure if this is what you want but you can set it in the xml as android:text="example#gmail.com" For example:
<EditText
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView2"
android:layout_toEndOf="#+id/textView3"
android:layout_toRightOf="#+id/textView3"
android:text="example#gmail.com"
android:inputType="textEmailAddress" />
Related
While running this code error is coming in the logact section.I guess its minor error so its difficult for me to search the error.I tried various things but it didn't worked for me.I don't know where my code went wrong.
this is my NewUserActivity .java code
public class NewUserActivity extends AppCompatActivity {
EditText name;
EditText email;
EditText phone;
EditText usname;
EditText passsword;
Button register;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_user_login);
name = (EditText) findViewById(R.id.name);
email = (EditText) findViewById(R.id.email);
phone = (EditText) findViewById(R.id.phone);
usname = (EditText) findViewById(R.id.usname);
passsword = (EditText) findViewById(R.id.passsword);
register= (Button) findViewById(R.id.textView2);
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String NAME = name.getText().toString().trim();
String EMAIL = email.getText().toString().trim();
String PHONENO =phone.getText().toString().trim();
String username = usname.getText().toString().trim();
String password = passsword.getText().toString().trim();
if (NAME.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter name",Toast.LENGTH_SHORT).show();
else if(EMAIL.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter correct email address",Toast.LENGTH_SHORT).show();
else if(PHONENO.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter correct phone number",Toast.LENGTH_SHORT).show();
else if(username.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter Username",Toast.LENGTH_SHORT).show();
else if(username.length()<8|| username.length()>15)
Toast.makeText(getApplicationContext(),"Username must contain atleast 8 characters",Toast.LENGTH_SHORT).show();
else if(password.isEmpty())
Toast.makeText(getApplicationContext(),"Please enter Password",Toast.LENGTH_SHORT).show();
else if(password.length()<6|| password.length()>10)
Toast.makeText(getApplicationContext(),"Password must contain 6 characters",Toast.LENGTH_SHORT).show();
else {
}
}
});
}
}
this is my xnl file for the same.
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout
tools:context=".NewUserActivity"
android:background="#drawable/ic_launcher_background"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="#+id/textView4"
android:layout_width="276dp"
android:layout_height="38dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="106dp"
android:layout_marginBottom="581dp"
android:text="REGISTRATION "
android:textColor="#color/WhiteSmoke"
android:textSize="30dp" />
<EditText
android:layout_height="26dp"
android:layout_width="297dp"
android:layout_marginBottom="487dp"
android:layout_marginEnd="65dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="#+id/name"/>
<TextView
android:id="#+id/textView5"
android:layout_width="218dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="135dp"
android:layout_marginBottom="530dp"
android:drawableLeft="#drawable/ic_action_name"
android:text="NAME"
android:textColor="#color/WhiteSmoke"
android:textSize="20dp" />
<TextView
android:id="#+id/textView6"
android:layout_width="195dp"
android:layout_height="30dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="161dp"
android:layout_marginBottom="439dp"
android:drawableLeft="#drawable/ic_action_mail"
android:text="EMAIL ID"
android:textColor="#color/WhiteSmoke"
android:textSize="20dp" />
<EditText
android:layout_height="26dp"
android:layout_width="297dp"
android:layout_marginBottom="399dp"
android:layout_marginEnd="67dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="#+id/email"/>
<TextView
android:id="#+id/textView7"
android:layout_width="147dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="209dp"
android:layout_marginBottom="351dp"
android:drawableLeft="#drawable/ic_action_phone"
android:text="PHONE NO."
android:textColor="#color/WhiteSmoke"
android:textSize="20dp" />
<EditText
android:layout_width="297dp"
android:layout_height="26dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="63dp"
android:layout_marginBottom="306dp"
android:id="#+id/phone"/>
<TextView
android:layout_height="30dp"
android:layout_width="195dp"
android:textSize="20dp"
android:textColor="#color/WhiteSmoke"
android:text="USERNAME"
android:layout_marginBottom="256dp"
android:layout_marginEnd="160dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="#+id/textView8"
android:drawableLeft="#drawable/ic_action_username"/>
<EditText
android:layout_height="26dp"
android:layout_width="297dp"
android:layout_marginBottom="205dp"
android:layout_marginEnd="63dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:id="#+id/usname"/>
<TextView android:layout_height="30dp" android:layout_width="195dp"
android:textSize="20dp" android:textColor="#color/WhiteSmoke"
android:text="PASSWORD" android:layout_marginBottom="160dp"
android:layout_marginEnd="156dp" android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true" android:id="#+id/textView9"
android:drawableLeft="#drawable/ic_action_password"/>
<EditText
android:layout_width="297dp"
android:layout_height="26dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="62dp"
android:layout_marginBottom="113dp"
android:id="#+id/passsword"/>
<androidx.cardview.widget.CardView
android:layout_height="56dp" android:layout_width="348dp"
android:layout_marginBottom="40dp" android:layout_marginEnd="20dp"
android:layout_alignParentBottom="true" android:layout_alignParentEnd="true"
app:cardElevation="10dp" app:cardCornerRadius="30dp"
app:cardBackgroundColor="#color/DeepPink" android:layout_marginRight="28dp"
android:layout_marginStart="20dp"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true">
<RelativeLayout android:layout_height="73dp" android:layout_width="373dp"
android:layout_marginBottom="100dp" android:layout_marginEnd="50dp">
<Button
android:id="#+id/register"
android:layout_width="132dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="129dp"
android:layout_marginBottom="17dp"
android:fontFamily="sans-serif"
android:freezesText="true"
android:text="REGISTER"
android:background="#android:color/transparent"
android:textColor="#color/Black"
android:textSize="24dp" />
</RelativeLayout>
</androidx.cardview.widget.CardView>
</RelativeLayout>
There is error in this section of my code.
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String NAME = name.getText().toString().trim();
String EMAIL = email.getText().toString().trim();
String PHONENO =phone.getText().toString().trim();
String username = usname.getText().toString().trim();
String password = passsword.getText().toString().trim();
You are using Wrong id of button which will led to the null pointer exception
Change this
register= (Button) findViewById(R.id.textView2);
to
register= (Button) findViewById(R.id.register);
To know about null pointer exception check this
What is a NullPointerException, and how do I fix it?
You can use View binding to replaces all findviewbyId
https://developer.android.com/topic/libraries/view-binding
name = (EditText) findViewById(R.id.name);
email = (EditText) findViewById(R.id.email);
phone = (EditText) findViewById(R.id.phone);
usname = (EditText) findViewById(R.id.usname);
passsword = (EditText) findViewById(R.id.passsword);
register= (Button) findViewById(R.id.textView2);
here check the register button id you add textView2 id here your mistake
Hello I am developing an application android, I have a problem with a text view that retrieves the data via web service, the data retrieve appears but infringe on the other text view of the page, Here is my code from my xml page:
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="#+id/tvd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Détail de l'établissement"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:text="Libelle :"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/tvd"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Code postal :"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Ville :"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/tvl"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView3"
android:layout_alignParentEnd="true"
android:hint="libelle"
android:textSize="20dp"
/>
<TextView
android:id="#+id/tvcp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvl"
android:layout_alignStart="#+id/tvl"
android:layout_alignTop="#+id/textView4"
android:hint="Code postal"
android:textSize="20dp" />
<TextView
android:id="#+id/tvv"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/tvcp"
android:layout_alignStart="#+id/tvcp"
android:layout_alignTop="#+id/textView5"
android:hint="Ville"
android:textSize="20dp" />
<Button
android:id="#+id/btnMa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Matériel numérique associé"
android:textSize="20dp"
android:textStyle="bold|italic"
/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="20dp"
android:textStyle="bold"
android:layout_below="#+id/textView5"
android:layout_marginTop="39dp"
android:text="Présentation" />
<TextView
android:id="#+id/tvp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView"
android:layout_alignLeft="#+id/tvv"
android:layout_alignStart="#+id/tvv"
android:hint="Presentation"
android:textSize="20dp" />
Then my code that says or go data :
public class DetailEtab extends Activity {
private TextView tv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.etabdetail);
tv = (TextView) findViewById(R.id.tvl);
tv.setText(search_ville.etabSELECT.getLibelle());
tv = (TextView) findViewById(R.id.tvcp);
tv.setText(search_ville.etabSELECT.getCp());
tv = (TextView) findViewById(R.id.tvv);
tv.setText(search_ville.etabSELECT.getVille());
tv = (TextView) findViewById(R.id.tvp);
tv.setText(search_ville.etabSELECT.getPresentation());
Button btnSa = (Button) findViewById(R.id.btnMa);
btnSa.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DetailEtab.this, MaterielAssocie.class);
startActivity(intent);
Log.i("ETAB", "servcies associes");
Toast toast = Toast.makeText(getApplicationContext(), "services associes", Toast.LENGTH_SHORT);
toast.show();
}
});
}
}
If anyone can tell me why it does that thanks
[screenshot][1] [1]: https://i.stack.imgur.com/ImHxk.png
You have problems with your layouts. I recommend you to wrap every line into separate LinearLayout and then use LinearLayout to wrap all new LinearLayouts. Also due to long text it's better to wrap parent LinearLayout into Scroll.
NOTE: This is just example that was written inside text box that simply shows main idea and may contain mistakes
Something like this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/tvd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Détail de l'établissement"
android:textSize="20dp"
android:textStyle="bold"/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="42dp"
android:text="Libelle :"
android:textSize="20dp"
android:textStyle="bold"
/>
<TextView
android:id="#+id/tvl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="libelle"
android:textSize="20dp"
/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Code postal :"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvcp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Code postal"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:text="Ville :"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/tvv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Ville"
android:textSize="20dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginTop="39dp"
android:text="Présentation" />
<TextView
android:id="#+id/tvp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Presentation"
android:textSize="20dp" />
</LinearLayout>
<Button
android:id="#+id/btnMa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Matériel numérique associé"
android:textSize="20dp"
android:textStyle="bold|italic"
/>
</LinearLayout>
</ScrollView>
You are assigning tv to multiple different TextViews and then you are assigning multiple values to the last TextView you assign it to.
public class DetailEtab extends Activity {
private TextView tv,tv1,tv2,tv3;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.etabdetail);
tv = (TextView) findViewById(R.id.tvl);
tv.setText(search_ville.etabSELECT.getLibelle());
tv1 = (TextView) findViewById(R.id.tvcp);
tv1.setText(search_ville.etabSELECT.getCp());
tv2 = (TextView) findViewById(R.id.tvv);
tv2.setText(search_ville.etabSELECT.getVille());
tv3 = (TextView) findViewById(R.id.tvp);
tv3.setText(search_ville.etabSELECT.getPresentation());
Button btnSa = (Button) findViewById(R.id.btnMa);
btnSa.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(DetailEtab.this, MaterielAssocie.class);
startActivity(intent);
Log.i("ETAB", "servcies associes");
Toast toast = Toast.makeText(getApplicationContext(), "services associes", Toast.LENGTH_SHORT);
toast.show();
}
});
}
}
Try this layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<TextView
android:id="#+id/tvd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="Détail de l'établissement"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/tvd"
android:layout_marginTop="42dp"
android:text="Libelle :"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView3"
android:layout_marginTop="64dp"
android:text="Code postal :"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView4"
android:layout_marginTop="64dp"
android:text="Ville :"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvl"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignParentEnd="true"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:layout_alignTop="#+id/textView3"
android:hint="libelle"
android:textSize="20dp"
/>
<TextView
android:id="#+id/tvcp"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignLeft="#+id/tvl"
android:layout_alignStart="#+id/tvl"
android:layout_alignTop="#+id/textView4"
android:hint="Code postal"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:textSize="20dp"/>
<TextView
android:id="#+id/tvv"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_alignLeft="#+id/tvcp"
android:layout_alignStart="#+id/tvcp"
android:layout_alignTop="#+id/textView5"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:hint="Ville"
android:textSize="20dp"/>
<Button
android:id="#+id/btnMa"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Matériel numérique associé"
android:textSize="20dp"
android:textStyle="bold|italic"
/>
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView5"
android:layout_marginTop="39dp"
android:text="Présentation"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:id="#+id/tvp"
android:layout_width="200dp"
android:layout_height="80dp"
android:layout_below="#+id/tvv"
android:layout_toRightOf="#id/textView"
android:layout_alignLeft="#+id/tvv"
android:layout_alignStart="#+id/tvv"
android:text="hfdgsjfhgadsjfgajsdfhgggdsjfgsdjafhgjsdafhgjdhfgjsdhgfjdshfgjdshfgjhdgfjdshgfjhdgfjsdhgafjahgsdfjdshgfjhdsagfjhdsgafjhsdagfjhdsgafjhsadgfjfdgjshfgjhfgjhsdgfhsgdfjhdsgfjhgdsjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjfhgsdjhfgjsdhgfjsdhgfjsdhfgjsdhfgjdsfhgjsdhgfjdshgfjsdhgfjhsgdfjhsdgjfhdgfjhgdsf"
android:hint="Presentation"
android:textSize="20dp"/>
</RelativeLayout>
I have been trying to resolve this issue for a while now have tried to follow a few examples on here but i seem to be missing something. this is the main post i've been looking at Passing an Object from an Activity to a Fragment
UPDATE: error message i get
1900-1900/com.chris.cv10aajproject E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.chris.cv10aajproject, PID: 1900
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.chris.cv10aajproject/com.chris.cv10aajproject.editProperty}: android.view.InflateException: Binary XML file line #121: Error inflating class fragment
UPDATE 2
code to activity Axml
<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="com.chris.cv10aajproject.editProperty">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="address"
android:id="#+id/tvAddress"
android:ems="10"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TOWN"
android:id="#+id/tvTown"
android:ems="10"
android:layout_below="#+id/tvAddress"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="County"
android:ems="10"
android:id="#+id/tvCounty"
android:layout_below="#+id/tvTown"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Post code"
android:id="#+id/tvPostCode"
android:ems="10"
android:layout_below="#+id/tvCounty"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Asking Price"
android:id="#+id/tvAskingPrice"
android:layout_below="#+id/tvPostCode"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Property Summary"
android:textStyle="bold"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/tvAddress"
android:layout_alignEnd="#+id/tvAddress" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Current Offer"
android:id="#+id/tvCurrentOffer"
android:layout_below="#+id/tvAskingPrice"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DoneUpValue"
android:id="#+id/textView3"
android:layout_below="#+id/tvCurrentOffer"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Notes"
android:id="#+id/tvNotes"
android:minHeight="200px"
android:background="#276bffd0"
android:scrollbars = "vertical"
android:layout_below="#+id/textView3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
android:layout_width="match_parent"
android:layout_height="match_parent" >
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/tvNotes"
android:layout_alignEnd="#+id/tvNotes"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/fragBTL"
class="com.chris.cv10aajproject.BtlFragment"
android:layout_below="#+id/tvNotes"
android:layout_alignBottom="#+id/fragFlip" />
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/tvNotes"
android:layout_alignRight="#+id/tvNotes"
android:layout_alignEnd="#+id/tvNotes"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/fragFlip"
class="com.chris.cv10aajproject.FlipFragment"
android:layout_above="#+id/toggleFlipBtl" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="Change to Flip"
android:textOn="Change to BTL"
android:id="#+id/toggleFlipBtl"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:checked="false"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/tvAskingPrice"
android:layout_toEndOf="#+id/tvAskingPrice" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/firstLine"
android:layout_below="#+id/textView"
android:layout_toRightOf="#+id/textView3"
android:layout_toEndOf="#+id/textView3"
android:layout_marginLeft="40dp"
android:layout_marginStart="40dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Schedule"
android:id="#+id/btnSchedule"
android:onClick="GoToSchedule"
android:layout_below="#+id/fragBTL"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calc Refurb"
android:id="#+id/btnCalcRefurb"
android:onClick="GoToRefurb"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/town23"
android:layout_below="#+id/firstLine"
android:layout_alignLeft="#+id/firstLine"
android:layout_alignStart="#+id/firstLine"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/county"
android:layout_below="#+id/town23"
android:layout_alignLeft="#+id/town23"
android:layout_alignStart="#+id/town23" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/postCode123"
android:layout_below="#+id/county"
android:layout_alignLeft="#+id/county"
android:layout_alignStart="#+id/county" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/currentOffer123"
android:layout_below="#+id/askingPrice123"
android:layout_alignLeft="#+id/askingPrice123"
android:layout_alignStart="#+id/askingPrice123" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/askingPrice123"
android:layout_below="#+id/postCode123"
android:layout_alignLeft="#+id/postCode123"
android:layout_alignStart="#+id/postCode123" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:id="#+id/doneUpValue123"
android:layout_below="#+id/currentOffer123"
android:layout_alignLeft="#+id/currentOffer123"
android:layout_alignStart="#+id/currentOffer123" />
Code for fragmentxml
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<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"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Flip Strategy"
android:id="#+id/textView21"
android:textStyle="bold"
android:textSize="20sp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Maxium Offer"
android:id="#+id/textView22"
android:textSize="15sp"
android:layout_below="#+id/textView21"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Max Offer "
android:textSize="15sp"
android:id="#+id/MaxOfferFlip"
android:layout_below="#+id/textView21"
android:layout_centerHorizontal="true"
android:background="#47ff4620" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Buyer Incentive"
android:id="#+id/textView23"
android:textSize="15sp"
android:layout_below="#+id/textView22"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="4"
android:id="#+id/IncentivePer"
android:hint="Percent"
android:textSize="15sp"
android:layout_below="#+id/MaxOfferFlip"
android:layout_alignLeft="#+id/MaxOfferFlip"
android:layout_alignStart="#+id/MaxOfferFlip"
android:background="#3409f6ff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Incentive "
android:textSize="15sp"
android:id="#+id/textIncentive"
android:background="#47ff4620"
android:layout_below="#+id/MaxOfferFlip"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="23dp"
android:layout_marginEnd="23dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Refurb Cost"
android:textSize="15sp"
android:id="#+id/textView24"
android:layout_below="#+id/textView23"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Refurb "
android:textSize="15sp"
android:id="#+id/refurb"
android:background="#47ff4620"
android:layout_below="#+id/IncentivePer"
android:layout_alignRight="#+id/MaxOfferFlip"
android:layout_alignEnd="#+id/MaxOfferFlip" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Holding Time cost"
android:textSize="15sp"
android:id="#+id/textView25"
android:layout_below="#+id/textView24"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Time "
android:textSize="15sp"
android:id="#+id/holdingTime"
android:background="#47ff4620"
android:layout_below="#+id/refurb"
android:layout_alignRight="#+id/refurb"
android:layout_alignEnd="#+id/refurb" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Profit required"
android:textSize="15sp"
android:id="#+id/textView26"
android:layout_below="#+id/textView25"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="4"
android:id="#+id/profit"
android:hint="Profit"
android:textSize="15sp"
android:background="#3409f6ff"
android:layout_below="#+id/holdingTime"
android:layout_alignLeft="#+id/IncentivePer"
android:layout_alignStart="#+id/IncentivePer" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Buyiing Selling Fee"
android:id="#+id/textView27"
android:textSize="15sp"
android:layout_below="#+id/textView26"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number"
android:ems="4"
android:id="#+id/buySellFee"
android:hint="Fee"
android:textSize="15sp"
android:background="#3409f6ff"
android:layout_below="#+id/profit"
android:layout_alignLeft="#+id/profit"
android:layout_alignStart="#+id/profit" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Monthly Mortage Cost"
android:id="#+id/textView7"
android:textSize="15sp"
android:layout_below="#+id/textView27"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:hint=" Mortage Cost "
android:textSize="15sp"
android:id="#+id/MonthMortFlip"
android:background="#47ff4620"
android:layout_alignParentBottom="true"
android:layout_alignLeft="#+id/holdingTime"
android:layout_alignStart="#+id/holdingTime" />
Fragment javaClass
public static FlipFragment newInstance(Property property ){
FlipFragment fragment = new FlipFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(PROPERTY_KEY,property);
fragment.setArguments(bundle);
return fragment ;
}
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_flip,container,false);
mProperty =(Property) getArguments().getParcelable(PROPERTY_KEY);
refurbCost = (TextView) getView().findViewById(R.id.refurb);
String refurbCost2 =" " + mProperty.getRefurbCost();
refurbCost.setText(refurbCost2);
// return view;
// mProperty = editActivity.getProperty();
//if (getActivity().getIntent().getExtras() != null) {
// mProperty = getActivity().getIntent().getParcelableExtra(editProperty.PAR_KEY3);
//}
return view;
}
#Override
public void onAttach(Activity myActivity) {
super.onAttach(myActivity);
this.editActivity = (editProperty) myActivity;
}
}
i have a activity A that has two fragments one is hidden and one is displayed depending on a toggle button.
i have a custom object that is passed to my activity A using parcelable. from another activity B. i want to pass this object to both fragments from activity A the user will input some data on the fragments which will call methods in the object class, then once this is done i want to pass the object back.
my application keeps crashing when i try to open activity A ( this has only started to happen after i've tried to pass the object to the fragments if i comment it out it opens fine)
This is the code i added to my setupView method in activity A
android.support.v4.app.FragmentTransaction ft =
getSupportFragmentManager().beginTransaction();
Fragment fragment = FlipFragment.newInstance(mProperty);
ft.replace(R.id.flip_fragment,fragment);
ft.commit();
this is the code i have in my fragment java class
public static FlipFragment newInstance(Property property ){
FlipFragment fragment = new FlipFragment();
Bundle bundle = new Bundle();
bundle.putParcelable(PROPERTY_KEY,property);
fragment.setArguments(bundle);
return fragment ;
}
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_flip,container,false);
mProperty =(Property) getArguments().getParcelable(PROPERTY_KEY);
refurbCost = (TextView) getView().findViewById(R.id.refurb);
String refurbCost2 =" " + mProperty.getRefurbCost();
refurbCost.setText(refurbCost2);
You cannot use getView() within the onCreateView method, it will return null. The view that you return at the end of onCreateView() becomes the view that will be returned by getView(). Instead, the view you inflated should be used.
View view = inflater.inflate(R.layout.fragment_flip,container,false);
refurbCost = (TextView) view.findViewById(R.id.refurb);
Hi i want to inflate an xml layout in another layout. Iam doing it correctly but it is not properly coming. Because the page in which i inflating the layout contains 2 relative layouts. I give different id'sandroid:id="#+id/stocklist" and android:id="#+id/gifts" for the two relative layouts. The stocklist layout contains a + button and when we click the + button it has to inflate the layout below to it.When iam inflating another layout inside the stocklist layout, the inflated xml is not properly alligned and it is not coming below the parent layout. Please help me if anybody knows. I added my code and layout here.
My parent layout code:
<?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" >
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="704dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView8"
android:layout_alignBottom="#+id/textView8"
android:layout_toRightOf="#+id/textView7"
android:text="Quantity"
android:textAppearance="?android:attr/textAppearanceSmall" />
<RelativeLayout
android:id="#+id/stocklist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView8"
android:layout_below="#+id/textView8"
android:layout_marginTop="11dp"
android:orientation="vertical" >
<Spinner
android:id="#+id/spinproducts"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginTop="13dp"
android:ems="10"
android:hint="Stocklist Name" >
</Spinner>
<EditText
android:id="#+id/editText1"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignTop="#+id/spinproducts"
android:layout_marginLeft="146dp"
android:layout_toRightOf="#+id/spinproducts"
android:ems="10"
android:inputType="number"
android:hint="Qty" />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_marginRight="136dp"
android:layout_toLeftOf="#+id/spindetail" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="11dp"
android:onClick="onAddNewClicked"
android:text="+" />
<Spinner
android:id="#+id/spindetail"
android:layout_width="180dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="50dp"
android:layout_toLeftOf="#+id/button1"
android:ems="10"
android:hint="Remarks" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/gifts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView8"
android:layout_below="#+id/textView12"
android:layout_marginTop="11dp"
android:orientation="vertical" >
<Spinner
android:id="#+id/spingift"
android:layout_width="375dp"
android:layout_height="40dp"
android:layout_marginTop="13dp"
android:ems="10"
android:hint="Stocklist Name" >
</Spinner>
<EditText
android:id="#+id/etgiftqty"
android:layout_width="500dp"
android:layout_height="40dp"
android:layout_alignBottom="#+id/spingift"
android:layout_marginLeft="33dp"
android:layout_toRightOf="#+id/spingift"
android:ems="10"
android:inputType="number"
android:hint="Qty" >
</EditText>
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:text="+" />
</RelativeLayout>
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView12"
android:layout_below="#+id/gifts"
android:layout_marginTop="33dp"
android:text="Call Outcome :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView14"
android:layout_below="#+id/textView14"
android:layout_marginTop="20dp"
android:text="Follow Up:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/stocklist"
android:layout_marginLeft="10dp"
android:layout_marginTop="16dp"
android:text="Gifts / Others :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView12"
android:layout_below="#+id/textView7"
android:layout_marginTop="12dp"
android:text="Product"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignLeft="#+id/textView13"
android:layout_alignRight="#+id/editText8"
android:layout_below="#+id/textView13"
android:layout_marginTop="12dp"
android:ems="10" >
</EditText>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner4"
android:layout_alignParentBottom="true"
android:layout_marginLeft="13dp"
android:text="Dr.Not Available" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText6"
android:layout_alignParentBottom="true"
android:layout_marginLeft="16dp"
android:text="Add Call" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="51dp"
android:layout_toRightOf="#+id/button3"
android:text="Cancel" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/spinner1"
android:layout_toLeftOf="#+id/textView9"
android:text="In Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<MultiAutoCompleteTextView
android:id="#+id/multiAutoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/spinner3"
android:layout_marginRight="17dp"
android:ems="10" >
</MultiAutoCompleteTextView>
<EditText
android:id="#+id/editText8"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/editText7"
android:layout_alignBottom="#+id/editText7"
android:layout_alignRight="#+id/multiAutoCompleteTextView1"
android:ems="10"
android:hint="Notes">
</EditText>
<EditText
android:id="#+id/editText6"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/spinner3"
android:layout_alignTop="#+id/spinner4"
android:ems="10"
android:hint="Amount">
</EditText>
<EditText
android:id="#+id/editText7"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/editText6"
android:layout_alignBottom="#+id/editText6"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/editText8"
android:ems="10"
android:hint="date"/>
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView15"
android:layout_toLeftOf="#+id/editText7"
android:text="Spon.Req"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView8"
android:layout_below="#+id/spinner1"
android:text="Detailing and Samples Dispensed :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="180dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/textView7"
android:layout_below="#+id/textView2" />
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText3"
android:layout_below="#+id/editText3"
android:layout_marginTop="20dp"
android:text="Schedule Follow"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/textView1"
android:layout_marginTop="12dp"
android:text="Location of Visit"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignParentTop="true"
android:text="Doctor Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#008000"
android:textSize="35dp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/textView15"
android:layout_alignBottom="#+id/textView15"
android:layout_alignLeft="#+id/editText5"
android:ems="10" >
</EditText>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/multiAutoCompleteTextView1"
android:layout_marginLeft="41dp"
android:layout_toRightOf="#+id/button4"
android:text="Work with"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView9"
android:layout_alignBottom="#+id/textView9"
android:layout_marginRight="38dp"
android:layout_toLeftOf="#+id/textView17"
android:text="Detailed"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="123dp"
android:layout_height="38dp"
android:layout_alignLeft="#+id/textView9"
android:layout_alignTop="#+id/textView5"
android:layout_marginLeft="22dp" />
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_below="#+id/editText4"
android:layout_marginLeft="29dp"
android:layout_marginTop="11dp"
android:layout_toRightOf="#+id/spinner1"
android:ems="10" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText5"
android:layout_alignBottom="#+id/editText5"
android:layout_alignLeft="#+id/textView15"
android:text="Follow Up Actions:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/stocklist"
android:layout_alignLeft="#+id/editText7"
android:layout_marginLeft="25dp"
android:text="Discussion Topics"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView10"
android:layout_below="#+id/textView2"
android:text="Out Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="123dp"
android:layout_height="38dp"
android:layout_above="#+id/textView7"
android:layout_toLeftOf="#+id/textView11" />
<Spinner
android:id="#+id/spinner4"
android:layout_width="145dp"
android:layout_height="40dp"
android:layout_alignRight="#+id/textView10"
android:layout_alignTop="#+id/editText5" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/spinner3"
android:layout_alignLeft="#+id/spinner4"
android:text="Duration of Visit"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Layout which has to be inflated:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView8"
android:layout_below="#+id/textView8"
android:layout_marginTop="11dp"
android:orientation="vertical" >
<Spinner
android:id="#+id/inflatespinproducts"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginTop="13dp"
android:ems="10"
android:hint="Stocklist Name" >
</Spinner>
<EditText
android:id="#+id/inflateeditText1"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignTop="#+id/inflatespinproducts"
android:layout_marginLeft="146dp"
android:layout_toRightOf="#+id/inflatespinproducts"
android:ems="10"
android:inputType="number"
android:hint="Qty" />
<CheckBox
android:id="#+id/inflatecheckBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/inflateeditText1"
android:layout_marginRight="136dp"
android:layout_toLeftOf="#+id/inflatespindetail" />
<Button
android:id="#+id/inflatebutton1"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="11dp"
android:onClick="onDeleteClicked"
android:text="-" />
<Spinner
android:id="#+id/inflatespindetail"
android:layout_width="180dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="50dp"
android:layout_toLeftOf="#+id/inflatebutton1"
android:ems="10"
android:hint="Remarks" />
</RelativeLayout>
</LinearLayout>
After inflating the layout my page looks like:
http://i.stack.imgur.com/SOWBJ.png">
My source code:
package abts.medismo.e_detailing;
import abts.medismo.e_detailing.Model.Spinmodel;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.MultiAutoCompleteTextView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
public class addcall extends Activity {
CheckBox chkdetailed;
TextView txtdocname, txtdisctopic;
MultiAutoCompleteTextView autoWorkwith;
Spinner spinlocation, intime, outtime, spinproducts, spingift, spindetail,
spinSponsorship;
String docid, docname, addid, addname, straddid, straddname, spaddid,
spaddname, dbcatid, dbcatname;
String strcatid, strcatname, spcatid, spcatname;
String spinlocationvalue, spingiftvalue, spinintimevalue, spinouttimevalue,
spinproductvalue, spinworkwithvalue, spindetailvalue,
spinsponsorshipvalue;
Intent bgIntent;
EditText etprodqty,etgiftqty;
RelativeLayout relStocklist;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dupaddcall);
autoWorkwith = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
autoWorkwith
.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
etprodqty=(EditText)findViewById(R.id.editText1);
etgiftqty=(EditText)findViewById(R.id.etgiftqty);
relStocklist=(RelativeLayout)findViewById(R.id.stocklist);
spinlocation = (Spinner) findViewById(R.id.spinner1);
spindetail = (Spinner) findViewById(R.id.spindetail);
spinSponsorship = (Spinner) findViewById(R.id.spinner4);
chkdetailed = (CheckBox) findViewById(R.id.checkBox1);
chkdetailed.setChecked(true);
intime = (Spinner) findViewById(R.id.spinner2);
outtime = (Spinner) findViewById(R.id.spinner3);
spinproducts = (Spinner) findViewById(R.id.spinproducts);
spingift = (Spinner) findViewById(R.id.spingift);
txtdocname = (TextView) findViewById(R.id.textView1);
txtdisctopic = (TextView) findViewById(R.id.textView11);
spindetail.setEnabled(false);
bgIntent = getIntent();
docid = bgIntent.getStringExtra("docid");
docname = bgIntent.getStringExtra("docname");
txtdocname.setText(docname);
DatabaseHandler dbh = new DatabaseHandler(addcall.this);
SQLiteDatabase db = dbh.getWritableDatabase();
addid = null;
addname = null;
}
public void onAddNewClicked(View v) {
inflateEditRow(null);
//v.setVisibility(View.VISIBLE);
}
private void inflateEditRow(String name) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.inflateaddproduct, null);
// A TextWatcher to control the visibility of the "Add new" button and
// handle the exclusive empty view.
// Inflate at the end of all rows but before the "Add new" button
relStocklist.addView(rowView, relStocklist.getChildCount());
}
public void onDeleteClicked(View v) {
relStocklist.removeView((View) v.getParent());
}
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(addcall.this, DCR.class);
intent.putExtra("planid", bgIntent.getStringExtra("planid"));
intent.putExtra("tourdate", bgIntent.getStringExtra("tourdate"));
final int result = 1;
startActivityForResult(intent, result);
finish();
}
}
You should change your relative stocklist layout to a linear layout, so the inflated layouts automatically arrange below each other.
<LinearLayout
android:id="#+id/stocklist"
android:orientation="vertical"
... >
...
</LinearLayout>
I know this is kinda silly and weird question, but its really bugging me. As my post subject says, when I enter a letter in the edit text its printing twice. I tried to find the issue, but couldn't. Here is my code,
changecode.xml
<EditText
android:id="#+id/oldcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/changecodetxt"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:hint="Enter Old Pass Code"
android:inputType="number"
android:password="true" />
<EditText
android:id="#+id/newcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/oldcode"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:hint="Enter New Pass code"
android:inputType="number"
android:password="true" />
<EditText
android:id="#+id/renewcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/newcode"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="25dp"
android:hint="Re-Enter New Pass code"
android:inputType="number"
android:password="true" />
<Button
android:id="#+id/savenewcode"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:background="#drawable/button_style"
android:text="Update Code" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/savenewcode"
android:layout_below="#id/renewcode"
android:gravity="center" >
<ToggleButton
android:id="#+id/cc_togglebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:textOff="123"
android:textOn="ABC!##" />
</LinearLayout>
In MainActivity.java
oldcode = (EditText) findViewById(R.id.oldcode);
newcode = (EditText) findViewById(R.id.newcode);
renewcode = (EditText) findViewById(R.id.renewcode);
savenewcode = (Button) findViewById(R.id.savenewcode);
cc_toggle = (ToggleButton) findViewById(R.id.cc_togglebutton);
cc_toggle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
boolean on = cc_toggle.isChecked();
if (on) {
oldcode.setInputType(InputType.TYPE_CLASS_TEXT);
newcode.setInputType(InputType.TYPE_CLASS_TEXT);
renewcode.setInputType(InputType.TYPE_CLASS_TEXT);
}
else {
oldcode.setInputType(InputType.TYPE_CLASS_NUMBER);
newcode.setInputType(InputType.TYPE_CLASS_NUMBER);
renewcode.setInputType(InputType.TYPE_CLASS_NUMBER);
}
}
});
Any kind of help or suggestion is much appreciated.