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);
Related
JAVA
Spinner spinner;
ArrayAdapter<CharSequence> adapter;
//Spinner for No_of_persons
spinner=(Spinner)findViewById(R.id.spinner);
adapter=ArrayAdapter.createFromResource(getApplicationContext(),R.array.person_count,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner.setAdapter(adapter);
spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getBaseContext(),parent.getItemIdAtPosition(position)+"selected",Toast.LENGTH_LONG).show();
}
});
XML
<RelativeLayout
android:id="#+id/specificationrellay"
android:layout_below="#+id/droplocation"
android:layout_width="match_parent"
android:layout_marginTop="5dp"
android:layout_height="match_parent">
<TextView
android:id="#+id/tvseatingcapacity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Seating Capacity"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="18dp"
android:layout_marginLeft="5dp"
/>
<TextView
android:id="#+id/capacity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="20dp"
android:textColor="#color/black"
android:layout_marginTop="2dp"
android:layout_below="#+id/tvseatingcapacity"
android:gravity="center_horizontal"
android:layout_marginLeft="65dp"
/>
<TextView
android:id="#+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:layout_toRightOf="#+id/tvseatingcapacity"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="18dp"
android:layout_marginLeft="18dp"
android:layout_marginTop="2dp"/>
<TextView
android:id="#+id/realtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10:30 AM"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="20dp"
android:textColor="#color/black"
android:layout_marginTop="2dp"
android:layout_below="#+id/time"
android:layout_toRightOf="#+id/capacity"
android:gravity="center_horizontal"
android:layout_marginLeft="65dp"
/>
<TextView
android:id="#+id/noofperson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No.Of Persons"
android:layout_toRightOf="#+id/time"
android:textStyle="normal"
android:fontFamily="casual"
android:textSize="18dp"
android:layout_marginLeft="35dp"
android:layout_marginTop="2dp"/>
<TextView
android:id="#+id/tv_selectperson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/noofperson"
android:layout_toRightOf="#+id/realtime"
android:layout_marginLeft="10dp"
android:text="#string/select_person"
android:fontFamily="casual"
/>
<Spinner
android:id="#+id/spinner"
android:layout_below="#+id/noofperson"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/tv_selectperson">
</Spinner>
<Button
android:id="#+id/btn_closepopup"
android:layout_width="100dp"
android:layout_height="35dp"
android:layout_below="#+id/realtime"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="138dp"
android:layout_marginLeft="138dp"
android:layout_marginTop="11dp"
android:layout_marginEnd="153dp"
android:layout_marginRight="153dp"
android:background="#drawable/circle"
android:fontFamily="casual"
android:text="Book"
android:textSize="10dp" />
</RelativeLayout>
You are using Spinner Class to set adapter - Spinner.setAdapter(adapter);
Use spinner object instead of class spinner.setAdapter(adapter);
Hope this solves the issue!
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 am trying to add a relativelayout inside a fragment programmatically on button click.But it simply doesn't display the layout.below is the code:
I have edited and posted the xml layout.
HotelSearch.java:
public class HotelSearch extends Fragment {
Button button;RelativeLayout relativeLayout,relativeLayout1;int counter=0;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable final Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.hotel_search,container,false);
relativeLayout=((RelativeLayout) v.findViewById(R.id.roomlayout));
button=(Button) v.findViewById(R.id.addroom);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
relativeLayout1=new RelativeLayout(getContext());
RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,20);
layoutParams.addRule(RelativeLayout.BELOW,R.id.roomlayout);
relativeLayout1.setBackgroundColor(Color.parseColor("#000000"));
relativeLayout1.setLayoutParams(layoutParams);
Log.e("Counter",String.valueOf(counter+1));
}
});
return v;
}
}
hotel_search.xml:(Edited Xml layout)
<?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:background="#android:color/transparent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="60dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#80212121">
<TextView
android:id="#+id/locationtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:text="Location"
android:textColor="#BDBDBD"
android:textSize="15sp" />
<AutoCompleteTextView
android:id="#+id/autohotellocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/locationtext"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:background="#android:color/transparent"
android:text="Hotel Name/City/Code"
android:textColor="#ffffff" />
<View
android:id="#+id/view1"
android:layout_width="100dp"
android:layout_height="0.5dp"
android:layout_below="#+id/autohotellocation"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="#00838F"
android:foregroundGravity="center"></View>
<TextView
android:id="#+id/checkin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/view1"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:text="CheckIn"
android:textColor="#BDBDBD" />
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/locationtext"
android:layout_alignStart="#+id/locationtext"
android:layout_below="#+id/checkin"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp">
<TextView
android:id="#+id/checkindate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="18"
android:textColor="#fff"
android:textSize="23sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/checkindate"
android:text="Jun 2015"
android:textColor="#fff"
android:textSize="15sp" />
</RelativeLayout>
<View
android:id="#+id/view2"
android:layout_width="100dp"
android:layout_height="0.5dp"
android:layout_below="#+id/relativeLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="#00838F"
android:foregroundGravity="center"></View>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view2"
android:id="#+id/scrollView"
android:scrollbars="vertical">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/view2"
android:layout_marginTop="30dp"
android:scrollbars="vertical"
>
<RelativeLayout
android:id="#+id/roomlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:scrollbars="vertical">
<TextView
android:id="#+id/rooms"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/adults"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rooms"
android:layout_toEndOf="#+id/button3"
android:layout_toRightOf="#+id/button3"
android:text="Adults"
android:textColor="#BDBDBD" />
<Button
android:id="#+id/button3"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#+id/adults"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:layout_marginTop="10dp"
android:layout_toEndOf="#+id/rooms"
android:layout_toRightOf="#+id/rooms"
android:background="#90006064"
android:text="-"
android:textColor="#fff"
android:textSize="22sp" />
<Button
android:id="#+id/button4"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/adults"
android:layout_alignStart="#+id/adults"
android:layout_alignTop="#+id/button3"
android:layout_marginLeft="37dp"
android:layout_marginStart="37dp"
android:background="#90006064"
android:text="+"
android:textColor="#fff"
android:textSize="18sp" />
<TextView
android:id="#+id/children"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button3"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="38dp"
android:layout_marginRight="38dp"
android:text="Children"
android:textColor="#BDBDBD" />
<Button
android:id="#+id/button6"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="13dp"
android:layout_marginRight="13dp"
android:background="#90006064"
android:text="+"
android:textColor="#fff"
android:textSize="18sp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:id="#+id/button5"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#90006064"
android:text="-"
android:textColor="#fff"
android:textSize="22sp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/button6"
android:layout_toStartOf="#+id/button6"
android:layout_marginRight="41dp"
android:layout_marginEnd="41dp" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<TextView
android:id="#+id/checkout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/checkin"
android:layout_marginEnd="21dp"
android:layout_marginRight="21dp"
android:text="CheckOut"
android:textColor="#BDBDBD" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/checkout"
android:layout_alignStart="#+id/checkout"
android:layout_alignTop="#+id/relativeLayout"
android:id="#+id/relativeLayout2">
<TextView
android:id="#+id/checkoutdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="18"
android:textColor="#fff"
android:textSize="23sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/checkoutdate"
android:text="Jun 2015"
android:textColor="#fff"
android:textSize="15sp" />
</RelativeLayout>
<View
android:id="#+id/view3"
android:layout_width="100dp"
android:layout_height="0.5dp"
android:layout_marginTop="20dp"
android:background="#00838F"
android:foregroundGravity="center"
android:layout_below="#+id/scrollView"
android:layout_toRightOf="#+id/checkin"
android:layout_toEndOf="#+id/checkin"></View>
<Button
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="Add Room"
android:id="#+id/addroom"
android:textColor="#fff"
android:layout_marginLeft="20dp"
android:background="#50000000"
android:layout_marginTop="20dp"
android:layout_below="#+id/view3"/>
</RelativeLayout>
</RelativeLayout>
Use this xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginBottom="60dp"
android:layout_marginLeft="30dp"
android:layout_marginRight="30dp"
android:background="#80212121">
<TextView
android:id="#+id/locationtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:text="Location"
android:textColor="#BDBDBD"
android:textSize="15sp" />
<AutoCompleteTextView
android:id="#+id/autohotellocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/locationtext"
android:layout_marginLeft="30dp"
android:layout_marginTop="20dp"
android:background="#android:color/transparent"
android:text="Hotel Name/City/Code"
android:textColor="#ffffff" />
<View
android:id="#+id/view1"
android:layout_width="100dp"
android:layout_height="0.5dp"
android:layout_below="#+id/autohotellocation"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="#00838F"
android:foregroundGravity="center"></View>
<TextView
android:id="#+id/checkin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/view1"
android:layout_marginLeft="30dp"
android:layout_marginTop="10dp"
android:text="CheckIn"
android:textColor="#BDBDBD" />
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/locationtext"
android:layout_alignStart="#+id/locationtext"
android:layout_below="#+id/checkin"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp">
<TextView
android:id="#+id/checkindate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="18"
android:textColor="#fff"
android:textSize="23sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/checkindate"
android:text="Jun 2015"
android:textColor="#fff"
android:textSize="15sp" />
</RelativeLayout>
<View
android:id="#+id/view2"
android:layout_width="100dp"
android:layout_height="0.5dp"
android:layout_below="#+id/relativeLayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="#00838F"
android:foregroundGravity="center"></View>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/view2"
android:id="#+id/scrollView"
android:scrollbars="vertical">
<RelativeLayout
android:id="#+id/rootlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/view2"
android:layout_marginTop="30dp"
android:scrollbars="vertical"
>
<RelativeLayout
android:id="#+id/roomlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:scrollbars="vertical">
<TextView
android:id="#+id/rooms"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/adults"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rooms"
android:layout_toEndOf="#+id/button3"
android:layout_toRightOf="#+id/button3"
android:text="Adults"
android:textColor="#BDBDBD" />
<Button
android:id="#+id/button3"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_below="#+id/adults"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:layout_marginTop="10dp"
android:layout_toEndOf="#+id/rooms"
android:layout_toRightOf="#+id/rooms"
android:background="#90006064"
android:text="-"
android:textColor="#fff"
android:textSize="22sp" />
<Button
android:id="#+id/button4"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/adults"
android:layout_alignStart="#+id/adults"
android:layout_alignTop="#+id/button3"
android:layout_marginLeft="37dp"
android:layout_marginStart="37dp"
android:background="#90006064"
android:text="+"
android:textColor="#fff"
android:textSize="18sp" />
<TextView
android:id="#+id/children"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button3"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginEnd="38dp"
android:layout_marginRight="38dp"
android:text="Children"
android:textColor="#BDBDBD" />
<Button
android:id="#+id/button6"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginEnd="13dp"
android:layout_marginRight="13dp"
android:background="#90006064"
android:text="+"
android:textColor="#fff"
android:textSize="18sp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<Button
android:id="#+id/button5"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#90006064"
android:text="-"
android:textColor="#fff"
android:textSize="22sp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/button6"
android:layout_toStartOf="#+id/button6"
android:layout_marginRight="41dp"
android:layout_marginEnd="41dp" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
<TextView
android:id="#+id/checkout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/checkin"
android:layout_marginEnd="21dp"
android:layout_marginRight="21dp"
android:text="CheckOut"
android:textColor="#BDBDBD" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/checkout"
android:layout_alignStart="#+id/checkout"
android:layout_alignTop="#+id/relativeLayout"
android:id="#+id/relativeLayout2">
<TextView
android:id="#+id/checkoutdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="18"
android:textColor="#fff"
android:textSize="23sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/checkoutdate"
android:text="Jun 2015"
android:textColor="#fff"
android:textSize="15sp" />
</RelativeLayout>
<View
android:id="#+id/view3"
android:layout_width="100dp"
android:layout_height="0.5dp"
android:layout_marginTop="20dp"
android:background="#00838F"
android:foregroundGravity="center"
android:layout_below="#+id/scrollView"
android:layout_toRightOf="#+id/checkin"
android:layout_toEndOf="#+id/checkin"></View>
i just put a id on the layout that contains roomlayout.
Then just add the view to that layout instead
public class HotelSearch extends Fragment {
Button button;RelativeLayout relativeLayout,relativeLayout1;int counter=0;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable final Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.hotel_search,container,false);
relativeLayout=((RelativeLayout) v.findViewById(R.id.rootlayout));
button=(Button) v.findViewById(R.id.addroom);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
relativeLayout1=new RelativeLayout(getContext());
RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,20);
layoutParams.addRule(RelativeLayout.BELOW,R.id.roomlayout);
relativeLayout1.setBackgroundColor(Color.parseColor("#000000"));
relativeLayout.addView(relativeLayout1, layoutParams);
Log.e("Counter",String.valueOf(counter+1));
}
});
return v;
}
}
Hope this helps.
Try this:
public class HotelSearch extends Fragment {
Button button;RelativeLayout relativeLayout,relativeLayout1;int counter=0;
#Override
public View onCreateView(LayoutInflater inflater, #Nullable ViewGroup container, #Nullable final Bundle savedInstanceState) {
View v=inflater.inflate(R.layout.hotel_search,container,false);
relativeLayout=((RelativeLayout) v.findViewById(R.id.roomlayout));
button=(Button) v.findViewById(R.id.addroom);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
relativeLayout1=new RelativeLayout(getContext());
RelativeLayout.LayoutParams layoutParams=new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,20);
layoutParams.addRule(RelativeLayout.BELOW,R.id.roomlayout);
relativeLayout1.setBackgroundColor(Color.parseColor("#000000"));
relativeLayout1.setLayoutParams(layoutParams);
Log.e("Counter",String.valueOf(counter+1));
//this is added:
relativeLayout.addView(relativeLayout1);
}
});
return v;
}
}
I am generating a Listview from a Sqlite database using a SimpleAdapter. I want to delete the item on long pressing the row on the phone. But the listview row is not responding to anything on long pressing. Can anyone guide me in this matter?
My codes are as follows:
Lists.java
ListView l=(ListView)findViewById(R.id.listView1);
l.setLongClickable(true);
details=db.getlocationdetails();
if((details=db.getlocationdetails()).size()!=0)
{
ListAdapter k=new SimpleAdapter(Lists.this,details,R.layout.testviewnew,new String[]{"locname","profile"},new int[]{R.id.locationame,R.id.proname});
l.setAdapter(k);
}
l.setOnItemLongClickListener(new OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
String s=String.valueOf(arg2);
db.deleterow(s);
return true;
}
});
}
And this is my database code:
public void deleterow(String id) {
Log.d(LOGCAT,"delete");
SQLiteDatabase database = this.getWritableDatabase();
String deleteQuery = "DELETE FROM animals where savedlocation='"+ id +"'";
Log.d("query",deleteQuery);
database.execSQL(deleteQuery);
database.close();
}
And here are my xml files
activity_lists.xml
<ListView
android:id="#+id/listView1"
android:layout_width="fill_parent"
android:layout_height="250dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:longClickable="true"
android:layout_below="#+id/relativeLayout1" >
</ListView>
testviewnew.xml
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ishutup_pointer"
/>
<TextView
android:id="#+id/locationame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_toRightOf="#+id/imageButton1"
android:text="TextView"
android:textStyle="bold"
android:textSize="15dp"
android:textColor="#color/white"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageButton1"
android:layout_alignLeft="#+id/locationame"
android:textStyle="bold"
android:textSize="15dp"
android:textColor="#color/white"
android:text="Profile" />
<TextView
android:id="#+id/proname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/textView2"
android:textStyle="bold"
android:textSize="15dp"
android:textColor="#color/white"
android:text="TextView" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textStyle="bold"
android:textSize="15dp"
android:textColor="#color/white"
android:src="#drawable/ishutup_edit" />
you have two imageButton in your xml but you don't have any listener on those, so you can change that with imageView. so your code must be:
<ImageView
android:id="#+id/imageButton1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ishutup_pointer"
/>
<TextView
android:id="#+id/locationame"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="31dp"
android:layout_toRightOf="#+id/imageButton1"
android:text="TextView"
android:textStyle="bold"
android:textSize="15dp"
android:textColor="#color/white"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageButton1"
android:layout_alignLeft="#+id/locationame"
android:textStyle="bold"
android:textSize="15dp"
android:textColor="#color/white"
android:text="Profile" />
<TextView
android:id="#+id/proname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView2"
android:layout_alignBottom="#+id/textView2"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/textView2"
android:textStyle="bold"
android:textSize="15dp"
android:textColor="#color/white"
android:text="TextView" />
<ImageView
android:id="#+id/imageButton2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:textStyle="bold"
android:textSize="15dp"
android:textColor="#color/white"
android:src="#drawable/ishutup_edit" />
as your imageButton want to listen click as default, if you want don't change your code you can add android:descendantFocusability="blocksDescendants" on parrent of testviewnew like as i said on comment to remove listening on those
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>