Button not respond to on click event - android

I'm trying for hours to make the button click but for some weird reason it doesnt work.
I have the main activity and from there I set the content view to first run activity and this is the code of the first run activity
import android.app.Activity;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class FirstRun extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first_run);
final Button button = (Button) findViewById(R.id.nextBtn);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Log.d("Test","test");
System.out.println("Button one is pressed");
button.setText("Test");
//Get edit text values
EditText nameET = (EditText) findViewById(R.id.Name);
EditText ageET = (EditText) findViewById(R.id.Age);
EditText emailET = (EditText) findViewById(R.id.Email);
EditText phoneET = (EditText) findViewById(R.id.Phone);
//set data in the info
//info = new UserInfo(nameET.getText().toString(),emailET.getText().toString(),phoneET.getText().toString());
if (nameET.getText().toString() != "" && ageET.getText().toString() != "" && emailET.getText().toString() != "" && phoneET.getText().toString() != "") {
SharedPreferences settings = getSharedPreferences("UserInfo", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("Name", nameET.getText().toString());
editor.putString("Email", emailET.getText().toString());
editor.putString("Phone", phoneET.getText().toString());
editor.putInt("Age", Integer.parseInt(ageET.getText().toString()));
}
}
});
}
}
Xml Layout details about the layout of the app and the button
i tried to add to the button onclick event on xml but every time I did it the app just crush and didn't respond at all
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:layout_editor_absoluteY="0dp"
tools:layout_editor_absoluteX="8dp"
android:background="#drawable/backgroundimage">
<TextView
android:id="#+id/WelcomeText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="#string/welcome_to_my_app"
android:textColor="#android:color/background_dark"
android:textSize="24sp" />
<Space
android:layout_width="fill_parent"
android:layout_height="10dp" />
<TextView
android:id="#+id/info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:text="#string/please_fill_the_information"
android:textColor="#android:color/holo_blue_dark"
android:textSize="20sp" />
<Space
android:layout_width="fill_parent"
android:layout_height="10dp" />
<GridLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnCount="3"
android:rowCount="7">
<TextView
android:id="#+id/nameTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="2"
android:text="#string/name"
android:textColor="#color/colorAccent"
android:textSize="18sp" />
<EditText
android:id="#+id/Name"
style="#style/Widget.AppCompat.EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="2"
android:capitalize="sentences"
android:ems="14"
android:inputType="textPersonName"
android:visibility="visible" />
<TextView
android:id="#+id/phoneTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="3"
android:text="#string/phone"
android:textColor="#color/colorAccent"
android:textSize="18sp" />
<EditText
android:id="#+id/Phone"
style="#style/Widget.AppCompat.EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="3"
android:ems="14"
android:inputType="phone"
android:visibility="visible" />
<TextView
android:id="#+id/emailTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="4"
android:text="#string/email"
android:textColor="#color/colorAccent"
android:textSize="18sp" />
<EditText
android:id="#+id/Email"
style="#style/Widget.AppCompat.EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="4"
android:ems="14"
android:inputType="textEmailAddress"
android:visibility="visible" />
<TextView
android:id="#+id/ageTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_row="5"
android:text="#string/age"
android:textColor="#color/colorAccent"
android:textSize="18sp" />
<EditText
android:id="#+id/Age"
style="#style/Widget.AppCompat.EditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="5"
android:ems="14"
android:inputType="number"
android:visibility="visible" />
</GridLayout>
<Button
android:id="#+id/nextBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="#android:color/holo_blue_dark"
android:text="#string/next" />
</LinearLayout>

Related

Fragment is not Covering the entire screen even the layout width and height is match parent

I have an activity and when I click on the "Register" TextView a fragment will open and in that fragment all the Registration detail is there.But when I click on the textview the Fragment is loaded successfully but it did'nt cover up the entire screen.
Here is my code:
MainActivity.java
Register.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
android.support.v4.app.FragmentManager fragmentManager=getSupportFragmentManager();
android.support.v4.app.FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
Fragments fragments=new Fragments();
fragmentTransaction.replace(R.id.Fragment_Register,fragments);
fragmentTransaction.commit();
fragmentTransaction.addToBackStack(null);
}
});
}
MainActivity.xml
<?xml version="1.0" encoding="utf-8"?>
<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="com.example.user.attendance.MainActivity"
android:background="#drawable/blurbackgound"
android:padding="10dp"
android:focusableInTouchMode="true"
>
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:text="WELCOME"
android:textColor="#color/white"
android:textStyle="bold"
android:fontFamily="monospace"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"/>
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="#id/title"
android:id="#+id/login_mobile_number"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:background="#drawable/edit_text_border"
android:padding="15dp"
android:textColor="#color/white"
android:inputType="number"
android:hint="Enter mobile number"
android:gravity="center"
android:maxLength="10"
android:textColorHint="#color/hint_color"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_local_phone_black_24dp"
android:layout_below="#id/title"
android:layout_marginLeft="30dp"
android:layout_marginTop="73dp"
android:id="#+id/phonelogo"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/mb_counter"
android:layout_below="#id/title"
android:layout_marginLeft="300dp"
android:layout_alignBaseline="#id/login_mobile_number"
android:text="abssh"
android:textColor="#color/white"
/>
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_below="#id/login_mobile_number"
android:layout_marginTop="25dp"
android:background="#drawable/edit_text_border"
android:paddingRight="50dp"
android:hint="Password"
android:gravity="center"
android:textColorHint="#color/hint_color"
android:inputType="textPassword"
android:textColor="#color/white"
android:id="#+id/login_password"
/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:layout_margin="1dp"
android:layout_below="#id/login_password"
android:orientation="horizontal"
>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="#color/white"
android:text="Student"
android:textColor="#color/white"
android:id="#+id/Radio_button_student"
android:layout_marginLeft="19dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:buttonTint="#color/white"
android:text="Teacher"
android:textColor="#color/white"
android:id="#+id/Radio_button_teacher"/>
</RadioGroup>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SHOW"
android:textColor="#color/white"
android:textStyle="bold"
android:layout_alignRight="#id/login_password"
android:layout_alignBaseline="#id/login_password"
android:id="#+id/password_visibility"
android:layout_marginRight="10dp"
/>
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:src="#drawable/ic_lock_outline_black_50dp"
android:layout_marginLeft="30dp"
android:layout_below="#id/phonelogo"
android:layout_marginTop="39dp"
/>
<Button
android:stateListAnimator="#null"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:hint="Login"
android:id="#+id/login"
android:background="#drawable/login_buttom"
android:textColorHint="#color/hint_color"
android:layout_below="#id/login_password"
android:layout_marginTop="50dp"
android:layout_marginLeft="35dp"
android:layout_centerHorizontal="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="FORGOT PASSWORD"
android:textColor="#color/white"
android:layout_below="#id/login"
android:layout_marginTop="18dp"
android:layout_marginLeft="48dp"
android:id="#+id/forgot_password"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="|"
android:textColor="#color/white"
android:layout_alignBaseline="#id/forgot_password"
android:layout_marginLeft="170dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="REGISTER"
android:textColor="#color/white"
android:layout_below="#id/login"
android:layout_marginLeft="185dp"
android:layout_marginTop="20dp"
android:id="#+id/Register"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/Fragment_Register"></RelativeLayout>
</RelativeLayout>
Fragments.java
package com.example.user.attendance;
import android.app.FragmentManager;
import android.text.Editable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import de.hdodenhof.circleimageview.CircleImageView;
public class Fragments extends Fragment {
Button Register_Cancel_fullname, Register_Cancel_email, Register_Cancel_phone,
Register_Cancel_password, Sign_up,Register_Cancel_Confirm_Password;
String Passcode,Confirm_Passcode;
EditText Full_Name, Email_Address, Phone_number, Password_register,Confirm_Password_register;
CircleImageView Register_add_photo;
LinearLayout select_photo_from_camera,select_photo_from_gallery;
TextView textView,hint_textview_circular_image_view;
// RadioButton Category_teacher,Category_student;
RadioGroup Teacher_student;
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View myfragmentVieew = inflater.inflate(R.layout.fragment_signup, container, false);
//Edit Text
Full_Name = (EditText) myfragmentVieew.findViewById(R.id.Register_name_and_surname);
Email_Address = (EditText) myfragmentVieew.findViewById(R.id.Register_Email_address);
Phone_number = (EditText) myfragmentVieew.findViewById(R.id.Register_Phone);
Password_register = (EditText) myfragmentVieew.findViewById(R.id.Register_Password);
Confirm_Password_register=(EditText)myfragmentVieew.findViewById(R.id
.Confirm_Password_Register);
//Button
Sign_up = (Button) myfragmentVieew.findViewById(R.id.Register_Signup);
Register_Cancel_fullname = (Button) myfragmentVieew.findViewById(R.id.Register_First_Cancel_Button);
Register_Cancel_email = (Button) myfragmentVieew.findViewById(R.id.Register_Second_Cancel_Button);
Register_Cancel_phone = (Button) myfragmentVieew.findViewById(R.id.Register_Third_Cancel_Button);
Register_Cancel_password = (Button) myfragmentVieew.findViewById(R.id.Register_fourth_Cancel_Button);
Register_Cancel_Confirm_Password=(Button)myfragmentVieew.findViewById(R.id
.Register_Cancel_Confirm_Password_Button);
Register_add_photo=(CircleImageView)myfragmentVieew.findViewById(R.id.Register_add_photo);
//TextView
textView = (TextView) myfragmentVieew.findViewById(R.id.Register_textview);
hint_textview_circular_image_view=(TextView)myfragmentVieew.findViewById(R.id
.hint_of_image_view);
return myfragmentVieew;
}
}
Here is what I am getting:
Remove this line from root layout.
android:padding="10dp"
This will solve the problem.

No Action onRadioButton click after reset

I'm an Android beginner and I have a little problem.
I have 2 radioButtons titled "Yes" and "No", 4 editTexts which are disabled and a button titled "Reset All".
Now, when I select the "No" radioButton, editTexts 1 and 2 become enabled and 1 gains focus. This is the desired behaviour. But When I select "Reset All" and again repeat the procedure, only editText 2 gets enabled and the "No" radioButton is still unchecked.
Following is my code:
MainActivity.java
package com.example.chris.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
public class MainActivity extends AppCompatActivity {
EditText e1;
EditText e2;
EditText e3;
EditText e4;
RadioButton yes;
RadioButton no;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1 = (EditText)findViewById(R.id.e1);
e2 = (EditText)findViewById(R.id.e2);
e3 = (EditText)findViewById(R.id.e3);
e4 = (EditText)findViewById(R.id.e4);
yes = (RadioButton)findViewById(R.id.yes);
no = (RadioButton)findViewById(R.id.no);
}
public void onClickreset(View v){
yes.setChecked(false);
no.setChecked(false);
e1.setEnabled(false);
e2.setEnabled(false);
e3.setEnabled(false);
e1.setText("");
e2.setText("");
e3.setText("");
e4.setText("");
};
public void onRadioButtonClicked(View v)
{
boolean checked = ((RadioButton) v).isChecked();
switch(v.getId()){
case R.id.yes:
if(checked)
e1.setEnabled(false);
e2.setEnabled(false);
e3.setEnabled(true);
e3.requestFocus();
break;
case R.id.no:
if(checked)
e1.setEnabled(true);
e2.setEnabled(true);
e2.requestFocus();
e2.clearFocus();
e3.setEnabled(false);
break;
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="#+id/LL"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.chris.myapplication.MainActivity">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:shrinkColumns="*"
android:stretchColumns="*">
<!-- Row 1 Starts From Here -->
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:checked="false"
android:onClick="onRadioButtonClicked"
android:text="yes" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:checked="false"
android:onClick="onRadioButtonClicked"
android:text="no" />
</RadioGroup>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="1:"
android:textColor="#000000" />
<EditText
android:id="#+id/e1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="2:"
android:textColor="#000000" />
<EditText
android:id="#+id/e2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="3:"
android:textColor="#000000" />
<EditText
android:id="#+id/e3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<TextView
android:id="#+id/t4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="10dp"
android:text="4:"
android:textColor="#000000" />
<EditText
android:id="#+id/e4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:enabled="false"
android:inputType="numberDecimal"
android:textColor="#000000" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="30dp" />
<Button
android:id="#+id/reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_span="3"
android:gravity="center"
android:onClick="onClickreset"
android:text="Reset"
android:textAllCaps="false"
android:textColor="#000000"
android:textStyle="normal" />
</TableLayout>
</LinearLayout>
It's better to use RadioGroup.OnCheckedChangeListener, first of all, get rid of android:onClick attributes and assign an id to RadioGroup in XML:
<RadioGroup
android:id="#+id/yes_no_radio_group"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_span="3"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="1dp"
android:checked="false"
android:text="yes" />
<RadioButton
android:id="#+id/no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:checked="false"
android:text="no" />
</RadioGroup>
Then make your Activity implements RadioGroup.OnCheckedChangeListener and move there code from onRadioButtonClicked(View v) method:
public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener {
//Some activity code
#Override
public void onCheckedChanged(RadioGroup radioGroup, int i) {
switch (radioGroup.getCheckedRadioButtonId()) {
case R.id.yes: //Not needed to
e1.setEnabled(false); //which RadioButton clicked
e2.setEnabled(false);
e3.setEnabled(true);
e3.requestFocus();
break;
case R.id.no:
e1.setEnabled(true);
e2.setEnabled(true);
e2.requestFocus();
e2.clearFocus();
e3.setEnabled(false);
break;
}
}
}
Then, assign OnCheckedChangeListener with RadioGroup:
yesNoGroup = findViewById(R.id.radio_group);
yesNoGroup.setOnCheckedChangeListener(this);
And change:
yes.setChecked(false);
no.setChecked(false);
To
yesNoGroup.clearCheck();

how to get cross button/image in custom dialog box border

I have used cutsom dialog box in my MainActivity for popup screen.I have added cross button to close
the popup screen. here in my code, that cross button is showing inside
the popup screen.
Now what i want is it has to show at the border of the popup screen.
please help me to get this..
Below is my code..any help would be appreciated...thanks in advance..
Java File
HomePage.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.support.v4.app.DialogFragment;
public class HomePage extends Activity {
final Context context = this;
Button b1;
Button b2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
b1 = (Button) findViewById(R.id.button6);
b2 = (Button) findViewById(R.id.button7);
b2.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(HomePage.this,RegisterPage.class);
startActivity(intent);
}
});
b1.setOnClickListener(new OnClickListener() {
#SuppressLint("NewApi")
#Override
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity_login_page);
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay(); // getting the screen size of device
Point size = new Point();
display.getSize(size);
int width = size.x - 20; // Set your heights
int height = size.y - 80; // set your widths
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = width;
lp.height = height;
dialog.getWindow().setAttributes(lp);
dialog.show();
ImageView image = (ImageView) dialog.findViewById(R.id.cancel_btn);
image.setImageResource(R.drawable.cancel2);
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
Button dialogButton = (Button) dialog.findViewById(R.id.button1);
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//dialog.dismiss();
Intent intent = new Intent(HomePage.this,CategoryPage.class);
startActivity(intent);
}
});
dialog.show();
}
});
}
}
XML File
activity_home_page.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:background="#fff"
tools:context=".MainActivity" >
<LinearLayout android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp"
android:src="#drawable/miiskylogo" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/header" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="163dp"
android:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin" >
<Button
android:id="#+id/button6"
android:layout_width="230dp"
android:layout_height="50dp"
android:background="#00b0ff"
android:layout_weight="0.1666"
android:textSize="18dp"
android:textColor="#fff"
android:paddingLeft="3dp"
android:layout_gravity="center"
android:layout_marginTop="32dp"
android:drawableLeft="#drawable/lock"
android:text="Login with SVAPP" />
<Button
android:id="#+id/button7"
android:layout_width="230dp"
android:layout_height="50dp"
android:background="#00b0ff"
android:layout_weight="0.1666"
android:textSize="18dp"
android:textColor="#fff"
android:paddingLeft="3dp"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/regis"
android:text="Register with SVAPP" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
activity_login_page.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:background="#fff"
tools:context="com.example.miiskyproject.Login" >
<ImageView
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/cancel2" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="130dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:src="#drawable/miiskylogo" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="190dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:background="#drawable/loginedit"
android:ems="6"
android:hint="User Name"
android:padding="8dp"
android:textColor="#000"
android:textStyle="bold"
android:textColorHint="#bdbdbd"
android:textSize="13dp" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="190dp"
android:layout_marginRight="15dp"
android:background="#drawable/loginedit"
android:ems="6"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="#000"
android:textStyle="bold"
android:textColorHint="#bdbdbd"
android:textSize="13dp" />
<Button
android:id="#+id/button1"
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginRight="20dp"
android:layout_marginTop="190dp"
android:background="#drawable/loginbutton"
android:ems="7"
android:text="Login"
android:textColor="#fff"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelInsurance7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:text="Forget Your Password?"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/textView2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="280dp"
android:padding="10dp"
android:layout_marginRight="20dp"
android:text="Lorem Ipsum dolor sit amet,"
android:background="#drawable/loginedit"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
I want cross button something like the image below.
Click Here
Try this solution:
<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:background="#fff"
tools:context="com.example.miiskyproject.Login" >
<LinearLayout
android:id="#+id/cancel_layuot"
android:layout_width="match_parent"
android:gravity="right"
android:background="#android:color/transparent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="130dp"
android:layout_height="90dp"
android:layout_below="#+id/cancel_layuot"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:src="#drawable/left_arrow" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/cancel_layuot" >
<EditText
android:id="#+id/editText1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="6"
android:hint="User Name"
android:padding="8dp"
android:textColor="#000"
android:textColorHint="#bdbdbd"
android:textSize="13dp"
android:textStyle="bold" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="6"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="#000"
android:textColorHint="#bdbdbd"
android:textSize="13dp"
android:textStyle="bold" />
<Button
android:id="#+id/button1"
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginRight="20dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="7"
android:text="Login"
android:textColor="#fff"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelInsurance7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:text="Forget Your Password?"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/cancel_layuot"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="280dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:text="Lorem Ipsum dolor sit amet,"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
You will see something like this:
Just replace image ic_launcher with the appropriated image.

Inflating layout in android

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>

How to inflate xml layout in android?

Hi Iam inflating a layout into another one. But it is overwriting the existing layout. Please do let me know to inflate a layout into another layout if anybody knows. When the plus button is pressed it should inflate a layout.
My xml:
<?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" >
<RelativeLayout
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="18dp"
android:layout_marginTop="14dp"
android:text="Daily Call Report"
android:textColor="#008000"
android:textSize="35dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="253dp"
android:text="Date"
android:textColor="#008000"
android:textSize="35dp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/dayworkcategory"
android:layout_width="wrap_content"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/linearLayout1"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="28dp"
android:layout_marginTop="10dp"
android:text="Day Work Plan:"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="175dp"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_marginLeft="101dp"
android:layout_toRightOf="#+id/spinner1" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/spinner2"
android:layout_alignLeft="#+id/spinner2"
android:text="Category:"
android:textSize="15dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="175dp"
android:layout_height="45dp"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/textView2" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/placeworkstation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/dayworkcategory"
android:layout_marginTop="12dp"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignLeft="#+id/textView5"
android:layout_below="#+id/textView5"
android:ems="10"
android:hint="STATION NAME" >
</AutoCompleteTextView>
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView4"
android:layout_alignBottom="#+id/textView4"
android:layout_marginLeft="27dp"
android:layout_toRightOf="#+id/textView4"
android:text="Actual Working :"
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_alignParentTop="true"
android:layout_marginLeft="30dp"
android:layout_marginTop="16dp"
android:text="Place of work(as per TP) :"
android:textSize="20dp"
android:textStyle="bold" />
</RelativeLayout>
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/placeworkstation"
android:layout_marginLeft="28dp"
android:text="Stockists Visited :"
android:textSize="20dp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/stocklist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView6"
android:layout_below="#+id/textView6"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView2"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="13dp"
android:ems="10"
android:hint="Stocklist Name" >
</AutoCompleteTextView>
<Spinner
android:id="#+id/spinner3"
android:layout_width="175dp"
android:layout_height="45dp"
android:layout_alignBottom="#+id/autoCompleteTextView2"
android:layout_marginLeft="33dp"
android:layout_toRightOf="#+id/autoCompleteTextView2" />
<EditText
android:id="#+id/editText1"
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignBaseline="#+id/autoCompleteTextView2"
android:layout_alignBottom="#+id/autoCompleteTextView2"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/spinner3"
android:ems="10"
android:hint="Qty" />
<EditText
android:id="#+id/editText2"
android:layout_width="145dp"
android:layout_height="45dp"
android:layout_alignTop="#+id/autoCompleteTextView2"
android:layout_marginLeft="31dp"
android:layout_toRightOf="#+id/editText1"
android:ems="10"
android:hint="Remarks" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_alignBaseline="#+id/editText2"
android:layout_alignBottom="#+id/editText2"
android:layout_marginLeft="13dp"
android:layout_toRightOf="#+id/editText2"
android:text="+" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/chemistlist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView6"
android:layout_below="#+id/textView7"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView3"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="13dp"
android:ems="10"
android:hint="Chemist Name" />
<EditText
android:id="#+id/editText4"
android:layout_width="145dp"
android:layout_height="45dp"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/button2"
android:layout_marginRight="63dp"
android:ems="10"
android:hint="Remarks" >
</EditText>
<Button
android:id="#+id/button2"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_alignBaseline="#+id/editText4"
android:layout_alignBottom="#+id/editText4"
android:layout_marginLeft="472dp"
android:layout_toRightOf="#+id/autoCompleteTextView3"
android:text="+" />
<EditText
android:id="#+id/editText3"
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignTop="#+id/button2"
android:layout_marginRight="16dp"
android:layout_toLeftOf="#+id/editText4"
android:ems="10"
android:hint="Qty" />
<Spinner
android:id="#+id/spinner4"
android:layout_width="175dp"
android:layout_height="45dp"
android:layout_alignTop="#+id/button2"
android:layout_marginRight="19dp"
android:layout_toLeftOf="#+id/editText3" />
</RelativeLayout>
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView7"
android:layout_below="#+id/chemistlist"
android:layout_marginTop="12dp"
android:text="Travel Expenses Detail :"
android:textSize="20dp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/travelexpenses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView6"
android:layout_below="#+id/textView8"
android:orientation="vertical" >
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView4"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="21dp"
android:ems="10"
android:hint="FROM" />
<Button
android:id="#+id/button3"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="43dp"
android:layout_alignBaseline="#+id/editText6"
android:layout_alignBottom="#+id/editText6"
android:layout_alignLeft="#+id/editText6"
android:layout_marginLeft="125dp"
android:text="+" />
<Spinner
android:id="#+id/spinner5"
android:layout_width="175dp"
android:layout_height="45dp"
android:layout_alignBottom="#+id/autoCompleteTextView5"
android:layout_marginLeft="13dp"
android:layout_toRightOf="#+id/autoCompleteTextView5" />
<AutoCompleteTextView
android:id="#+id/autoCompleteTextView5"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/autoCompleteTextView4"
android:layout_alignBottom="#+id/autoCompleteTextView4"
android:layout_marginLeft="37dp"
android:layout_toRightOf="#+id/autoCompleteTextView4"
android:ems="10"
android:hint="TO" >
</AutoCompleteTextView>
<EditText
android:id="#+id/editText6"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/editText5"
android:layout_alignBottom="#+id/editText5"
android:layout_marginLeft="42dp"
android:layout_toRightOf="#+id/editText5"
android:ems="10"
android:hint="Km" />
<EditText
android:id="#+id/editText5"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_alignBottom="#+id/spinner5"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/spinner5"
android:ems="10"
android:hint="AMOUNT" >
</EditText>
</RelativeLayout>
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView8"
android:layout_below="#+id/travelexpenses"
android:layout_marginTop="14dp"
android:text="Miscelleneous Expenses Detail :"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/chemistlist"
android:layout_centerVertical="true"
android:text="Chemists Visited :"
android:textSize="20dp"
android:textStyle="bold" />
<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_alignRight="#+id/travelexpenses"
android:layout_marginRight="34dp"
android:text="Daily Allowance Expenses Detail :"
android:textSize="20dp"
android:textStyle="bold" />
<RelativeLayout
android:id="#+id/miscelleneous"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView6"
android:layout_below="#+id/textView9"
android:orientation="vertical" >
<EditText
android:id="#+id/editText7"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_marginTop="21dp"
android:ems="10"
android:hint="Amount" />
<Button
android:id="#+id/button4"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_alignTop="#+id/editText7"
android:layout_marginLeft="276dp"
android:layout_toRightOf="#+id/editText7"
android:text="+" />
<EditText
android:id="#+id/editText8"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignTop="#+id/button4"
android:layout_marginLeft="40dp"
android:layout_toRightOf="#+id/editText7"
android:ems="10"
android:hint="Remarks" />
</RelativeLayout>
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignBottom="#+id/miscelleneous"
android:layout_alignLeft="#+id/textView10"
android:layout_marginBottom="10dp"
android:layout_marginLeft="35dp"
android:text="Total(INR):"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignBaseline="#+id/textView11"
android:layout_alignBottom="#+id/textView11"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/textView11"
android:text="TOTAL"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="#+id/button5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/dayworkcategory"
android:layout_marginRight="33dp"
android:text="UPGRADE DRAFT" />
<Button
android:id="#+id/button6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/placeworkstation"
android:text="SUBMIT LATER" />
</RelativeLayout>
My code for inflating the layout:
package abts.medismo.e_detailing;
import abts.medismo.e_detailing.Model.Spinmodel;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.Spinner;
public class DCR extends Activity {
Spinner spinworkplan, spincategory, spinstockproduct, spinchemistproduct,
spintravelmode;
Spinner autostation, autostock, autochemist;
String dbcatid, dbcatname, strcatname, spcatid, spcatname, strcatid;
RelativeLayout stocklist;
int i = 1;
int count = 0;
View rowView;
private View mExclusiveEmptyView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dcrdummo);
spinworkplan = (Spinner) findViewById(R.id.spinner1);
spincategory = (Spinner) findViewById(R.id.spinner2);
spinstockproduct = (Spinner) findViewById(R.id.spinner3);
spinchemistproduct = (Spinner) findViewById(R.id.spinner4);
spintravelmode = (Spinner) findViewById(R.id.spinner5);
stocklist = (RelativeLayout) findViewById(R.id.stocklist);
DatabaseHandler dbh = new DatabaseHandler(DCR.this);
SQLiteDatabase db = dbh.getWritableDatabase();
final ArrayAdapter<Spinmodel> adapterWorkPlan = new ArrayAdapter<Spinmodel>(
this, android.R.layout.simple_spinner_item);
adapterWorkPlan
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adapterWorkPlan.add(new Spinmodel("Doctor Visit", "Doctor Visit"));
adapterWorkPlan.add(new Spinmodel("Transit", "Transit"));
adapterWorkPlan.add(new Spinmodel("Meeting", "Meeting"));
adapterWorkPlan.add(new Spinmodel("Strike", "Strike"));
adapterWorkPlan.add(new Spinmodel("Head Quarters", "Head Quarters"));
adapterWorkPlan.add(new Spinmodel("Sales Closing", "Sales Closing"));
adapterWorkPlan.add(new Spinmodel("Others", "Others"));
spinworkplan.setAdapter(adapterWorkPlan);
final ArrayAdapter<Spinmodel> adapterCategory = new ArrayAdapter<Spinmodel>(
this, android.R.layout.simple_spinner_item);
String strquery1 = "SELECT * FROM category";
Cursor cursor = db.rawQuery(strquery1, null);
if (cursor.getCount() != 0) {
cursor.moveToFirst();
do {
dbcatid += "," + cursor.getString(0);
dbcatname += "," + cursor.getString(1);
} while (cursor.moveToNext());
}
System.out.println("dbCatid-->>" + dbcatid);
System.out.println("dbCatName-->>" + dbcatname);
if (dbcatname != null) {
int pos = dbcatname.indexOf(",");
int pos1 = dbcatid.indexOf(",");
if (pos == pos1) {
strcatid = dbcatid.substring(pos1 + 1);
strcatname = dbcatname.substring(pos + 1);
}
String delimiter = "\\,";
String[] catid = strcatid.split(delimiter);
String[] catname = strcatname.split(delimiter);
for (int i = 0; i < catid.length; i++) {
spcatid = catid[i];
spcatname = catname[i];
adapterCategory.add(new Spinmodel(spcatname, spcatid));
}
spincategory.setAdapter(adapterCategory);
}
dbcatid = null;
dbcatname = null;
final ArrayAdapter<Spinmodel> adapterStockProduct = new ArrayAdapter<Spinmodel>(
this, android.R.layout.simple_spinner_item);
String strproductquery = "SELECT * FROM product";
Cursor productcursor = db.rawQuery(strproductquery, null);
if (productcursor.getCount() != 0) {
productcursor.moveToFirst();
do {
dbcatid += "," + productcursor.getString(0);
dbcatname += "," + productcursor.getString(1);
} while (productcursor.moveToNext());
}
if (dbcatname != null) {
int pos = dbcatname.indexOf(",");
int pos1 = dbcatid.indexOf(",");
if (pos == pos1) {
strcatid = dbcatid.substring(pos1 + 1);
strcatname = dbcatname.substring(pos + 1);
}
String delimiter = "\\,";
String[] catid = strcatid.split(delimiter);
String[] catname = strcatname.split(delimiter);
for (int i = 0; i < catid.length; i++) {
spcatid = catid[i];
spcatname = catname[i];
adapterStockProduct.add(new Spinmodel(spcatname, spcatid));
}
spinstockproduct.setAdapter(adapterStockProduct);
spinchemistproduct.setAdapter(adapterStockProduct);
}
final ArrayAdapter<Spinmodel> adaptertravelmode = new ArrayAdapter<Spinmodel>(
this, android.R.layout.simple_spinner_item);
adaptertravelmode
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
adaptertravelmode.add(new Spinmodel("TwoWheeler", "TwoWheeler"));
adaptertravelmode.add(new Spinmodel("Bus", "Bus"));
adaptertravelmode.add(new Spinmodel("Car", "Car"));
adaptertravelmode.add(new Spinmodel("Train", "Train"));
adaptertravelmode.add(new Spinmodel("Airlines", "Airlines"));
spintravelmode.setAdapter(adaptertravelmode);
}
public void onAddNewClicked(View v) {
count++;
System.out.println("value of i: " + i);
inflateEditRow(count);
v.setVisibility(View.VISIBLE);
System.out.println("value of count " + count);
}
private void inflateEditRow(int id) {
i = id - 1;
for (int j = i; j < id; j++) {
System.out.println("value of j " + j);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.dummaa, null);
mExclusiveEmptyView = rowView;
rowView.setId(id);
stocklist.addView(rowView);
// stocklist.addView(rowView, stocklist.getChildCount());
}
}
public void onDeleteClicked(View v) {
stocklist.removeView((View) v.getParent());
}
}
I got a bit lost in your code, but if I understood right you may need to have the main view as a parameter in rowView = inflater.inflate(R.layout.dummaa, null); instead of passing null.

Categories

Resources