androit text view Mysql - android

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>

Related

How to click button inside listview

I know this problem already asked many times but i still can't get effective way for solving this. I try for use ListView with clickable/editable widget and Android : How to set onClick event for Button in List item of ListView as reference but the result is i need click button several time for executing my program. Here my program
LeadActivity.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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".LeadSalesActivity">
<LinearLayout
android:background="#E9ECEB"
android:layout_margin="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/b_menusamping2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="20dp"
android:background="#drawable/menu_button"
android:backgroundTint="#27D01B"/>
</LinearLayout>
<LinearLayout
android:layout_marginTop="10dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome,"
android:textSize="20sp"
android:textStyle="italic"
android:textColor="#android:color/black"/>
<TextView
android:id="#+id/t_username3"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="Rizaldi"
android:textColor="#android:color/black"
android:textSize="25sp"
android:textStyle="bold"
android:fontFamily="#font/action_man_bold"/>
</LinearLayout>
<LinearLayout
android:id="#+id/linear_refresh2"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white">
<ImageView
android:backgroundTint="#27D01B"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_margin="10dp"
android:background="#drawable/icon_update"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_marginLeft="20dp"
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="("
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:textStyle="bold"
android:id="#+id/count_lead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=")"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<Button
android:id="#+id/btn_add"
android:layout_marginRight="20dp"
android:backgroundTint="#android:color/holo_blue_light"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tambah Lead"
android:textAllCaps="false"/>
</LinearLayout>
<LinearLayout
android:padding="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Tanggal"
android:textColor="#android:color/black"
android:textSize="20sp"/>
<TextView
android:layout_marginLeft="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lead"
android:textSize="20sp"
android:textColor="#android:color/black"/>
<TextView
android:layout_marginLeft="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telp"
android:textColor="#android:color/black"
android:textSize="20sp"/>
</LinearLayout>
<ListView
android:id="#+id/listviewlead"
tools:listitem="#layout/c_lead"
android:layout_width="match_parent"
android:layout_height="400dp"
android:layout_weight="1" />
</LinearLayout>
</ScrollView>
</LinearLayout>
<LinearLayout
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<Button
android:id="#+id/back6"
android:layout_marginRight="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="back"/>
</LinearLayout>
c_lead.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_tgl"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Tgl"
android:textSize="15sp"
android:textStyle="italic"
android:textColor="#000000" />
<TextView
android:id="#+id/t_lead4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Lead"
android:textSize="15sp"
android:textColor="#000000" />
<TextView
android:id="#+id/t_numberphone"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:gravity="right"
android:text="No.Telp"
android:textSize="15sp"
android:textColor="#android:color/black"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<LinearLayout
android:id="#+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/pencil_icon"/>
</LinearLayout>
<LinearLayout
android:id="#+id/btn_delete"
android:layout_marginLeft="3dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#drawable/kotak_abu"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp">
<ImageButton
android:layout_margin="10dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#drawable/delete_icon"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/t_alamat"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="8dp"
android:text="Alamat"
android:textColor="#android:color/black"
android:textSize="15sp"
android:layout_marginLeft="20dp"/>
</LinearLayout>
MyAdapter
public View getView(final int _position, View _v, ViewGroup _container) {
LayoutInflater _inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _view = _v;
if (_view == null) {
_view = _inflater.inflate(R.layout.c_lead, null);
}
final HashMap<String, Object> hashMap = _data.get(_position);
final TextView t_tanggal = (TextView) _view.findViewById(R.id.t_tgl);
final TextView t_lead = (TextView) _view.findViewById(R.id.t_lead4);
final TextView t_alamat = (TextView) _view.findViewById(R.id.t_alamat);
final TextView t_numberphone = (TextView) _view.findViewById(R.id.t_numberphone);
final LinearLayout btn_edit = (LinearLayout) _view.findViewById(R.id.btn_edit);
final LinearLayout btn_delete = (LinearLayout) _view.findViewById(R.id.btn_delete);
String dateString = _data.get(_position).get("create_date").toString().replace("-","");
SimpleDateFormat format1 = new SimpleDateFormat("yyyyMMddHHmm");
format1.setTimeZone(TimeZone.getTimeZone("GMT+7"));
SimpleDateFormat format2 = new SimpleDateFormat("dd-MM-yyyy");
try {
Date date = format1.parse(dateString);
String dateFinal = format2.format(date);
t_tanggal.setText(String.valueOf((long)(_position + 1)).concat(".").concat(dateFinal));
} catch (ParseException e) {
e.printStackTrace();
}
t_lead.setText(_data.get((int)_position).get("type").toString());
t_alamat.setText(_data.get((int)_position).get("street").toString());
if (_data.get((int)_position).get("mobile").toString().equals(true)){
t_numberphone.setText("Tanpa Nomor");
} else {
t_numberphone.setText(_data.get((int)_position).get("phone").toString());
}
btn_edit.setFocusable(false);
btn_edit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
i.setClass(getApplicationContext(), AddLeadSalesActivity.class);
startActivity(i);
}
});
btn_delete.setFocusable(false);
btn_delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(getApplicationContext(), "Data Tidak Bisa Dihapus", Toast.LENGTH_SHORT).show();
}
});
return _view;
}
Is there any mistake inside my program? How to solve this?

NullPointerException in dialog - Strange case

I have a stupid problem but i couldnt solve it yet. I have an activity with a button in toolbar, this button open one dialog with some filter params.
Here is what a i did..
Spinner spinner_categoria;
Spinner spinner_vendedor;
SeekBar seek_preco;
TextView tv_filtro;
onCreate method {
...
}
onClickEvent{
dialogFiltro();
}
public void dialogFiltro() {
Context context = SalesActivity.this;
final Dialog dialog;
dialog = new Dialog(context);
//dialog.setContentView(R.layout.dialog_filtro);
// dialog.setTitle("Filtro");
//dialog.show();
VendedorDAO auxVendedor = new VendedorDAO();
final List<String> listVendedor = auxVendedor.getVendedorList();
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_filtro, null, false);
CardView bt_cancelar = (CardView) dialogView.findViewById(R.id.cb_filtro_cancelar);
CardView bt_aceitar = (CardView) dialogView.findViewById(R.id.cb_filtro_aceitar);
seek_preco = (SeekBar) dialogView.findViewById(R.id.sb_preco_max);
tv_filtro = (TextView) dialogView.findViewById(R.id.tv_filtro_preco);
spinner_categoria = (Spinner) dialogView.findViewById(R.id.spinner_categoria);
spinner_vendedor = (Spinner) dialogView.findViewById(R.id.spinner_vendedor);
spinner_categoria.setAdapter(ArrayAdapter.createFromResource(
this, R.array.categoria_array, android.R.layout.simple_spinner_item));
spinner_vendedor.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, listVendedor));
String oi = "oi";
tv_filtro.setText(oi);
dialog.setContentView(dialogView);
dialog.show();
seek_preco.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// tv_filtro.setText("R$ " + progress);
// Log.i("RS " , String.valueOf(progress));
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
bt_cancelar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
bt_aceitar.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
categoria = (String) spinner_categoria.getSelectedItem();
vendedor = (Integer) spinner_vendedor.getFirstVisiblePosition();
Log.e("id vendedor ", String.valueOf(vendedor));
if (vendedor == 0) {
vendedor = -1;
}
int precoAux = seek_preco.getProgress();
precoMax = (float) precoAux;
}
});
}
I have this in dialog_filtro.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_margin="8dp"
android:foreground="#drawable/border_card"
card_view:cardElevation="2dp"
card_view:cardMaxElevation="8dp">
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/cb_filtro_cancelar"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="#color/colorPrimary"
android:elevation="2dp"
android:text="X"
android:textColor="#android:color/white" />
<Button
android:id="#+id/cb_filtro_aceitar"
android:layout_width="70dp"
android:layout_height="30dp"
android:layout_gravity="end"
android:background="#color/colorPrimary"
android:elevation="2dp"
android:text="Aceitar"
android:textColor="#android:color/white" />
</FrameLayout>
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Filtrar por"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorPrimary" />
<TextView
android:id="#+id/tv_label_categoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:gravity="center"
android:text="Categoria"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner_categoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:id="#+id/tv_label_vendedor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:gravity="center"
android:text="Supermercado"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner_vendedor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preço máximo"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<SeekBar
android:id="#+id/sb_preco_max"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:indeterminate="false"
android:max="100"
android:progress="0" />
<TextView
android:id="#+id/tv_filtro_preco"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="5"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<View
android:id="#+id/rv_shoppingcart_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/tv_label_oerdenar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:text="Ordenar por"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorPrimary" />
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Preço:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/group_preco"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:layout_marginTop="10dp"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb_preco_maior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Maior" />
<RadioButton
android:id="#+id/rb_preco_menor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Menor" />
</RadioGroup>
<TextView
android:id="#+id/tv_label_data_Validade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Data de validade:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/group_validade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb_validade_maior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Maior" />
<RadioButton
android:id="#+id/rb_validade_menor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Menor" />
</RadioGroup>
<LinearLayout
android:id="#+id/linear_isoffer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="#+id/tv_label_ofertas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Apenas ofertas:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/cb_offer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:checked="false"
android:text="Selecionar apenas ofertas" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</android.support.v7.widget.CardView>
</LinearLayout>
Everything works fine (spinner, cardview etc) but i always get NullPointerException because the TextView and i don't know why. Here goes my log:
FATAL EXCEPTION: main
Process: com.catafeira.catafeira, PID: 2419
Theme: themes:{default=overlay:system, iconPack:system, fontPkg:system, com.android.systemui=overlay:system, com.android.systemui.navbar=overlay:system}
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.CharSequence)' on a null object reference
at com.catafeira.catafeira.SalesActivity.dialogFiltro(SalesActivity.java:281)
at com.catafeira.catafeira.SalesActivity.onOptionsItemSelected(SalesActivity.java:432)
at android.app.Activity.onMenuItemSelected(Activity.java:2914)
at android.support.v4.app.FragmentActivity.onMenuItemSelected(FragmentActivity.java:403)
at android.support.v7.app.AppCompatActivity.onMenuItemSelected(AppCompatActivity.java:189)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.view.WindowCallbackWrapper.onMenuItemSelected(WindowCallbackWrapper.java:100)
at android.support.v7.app.ToolbarActionBar$2.onMenuItemClick(ToolbarActionBar.java:69)
at android.support.v7.widget.Toolbar$1.onMenuItemClick(Toolbar.java:169)
at android.support.v7.widget.ActionMenuView$MenuBuilderCallback.onMenuItemSelected(ActionMenuView.java:760)
at android.support.v7.view.menu.MenuBuilder.dispatchMenuItemSelected(MenuBuilder.java:811)
at android.support.v7.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:152)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:958)
at android.support.v7.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:948)
at android.support.v7.widget.ActionMenuView.invokeItem(ActionMenuView.java:618)
at android.support.v7.view.menu.ActionMenuItemView.onClick(ActionMenuItemView.java:139)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21158)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5461)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
EDIT: I know what is a NullPointerException, I already checked the previous posts on the subject, but no problem is the same as mine
I think the problem is with findViewByID. The documentation says
findViewById
Added in API level 1
View findViewById (int id)
Finds a child view with the given identifier. Returns null if the specified child view does not exist or the dialog has not yet been fully created (for example, via show() or create()).
It is just possible that since you are calling show() later the textView might not be created. I would do this
View dialogView = LayoutInflater.from(context).inflate(R.layout.dialog_filtro, null);
Button bt_cancelar = (Button) dialogView.findViewById(R.id.cb_filtro_cancelar);
Button bt_aceitar = (Button) dialogView.findViewById(R.id.cb_filtro_aceitar);
seek_preco = (SeekBar) dialogView.findViewById(R.id.sb_preco_max);
tv_filtro = (TextView) dialogView.findViewById(R.id.tv_filtro_preco);
spinner_categoria = (Spinner) dialogView.findViewById(R.id.spinner_categoria);
spinner_vendedor = (Spinner) dialogView.findViewById(R.id.spinner_vendedor);
dialog.setContentView(dialogView)
dialog.show();
spinner_categoria.setAdapter(ArrayAdapter.createFromResource(
this, R.array.categoria_array, android.R.layout.simple_spinner_item));
spinner_vendedor.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item,listVendedor));
tv_filtro.setText("oi");
Change the XML to the following
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:foreground="#drawable/border_card"
android:layout_margin="8dp"
card_view:cardElevation="2dp"
card_view:cardMaxElevation="8dp">
<ScrollView
android:id="#+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:orientation="vertical">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/cb_filtro_cancelar"
android:layout_width="70dp"
android:layout_height="30dp"
android:background="#color/colorPrimary"
android:elevation="2dp"
android:text="X"
android:textColor="#android:color/white" />
<Button
android:id="#+id/cb_filtro_aceitar"
android:layout_width="70dp"
android:layout_height="30dp"
android:layout_gravity="end"
android:background="#color/colorPrimary"
android:elevation="2dp"
android:text="Aceitar"
android:textColor="#android:color/white" />
</FrameLayout>
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:text="Filtrar por"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorPrimary" />
<TextView
android:id="#+id/tv_label_categoria"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:gravity="center"
android:text="Categoria"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner_categoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:id="#+id/tv_label_vendedor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:gravity="center"
android:text="Supermercado"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner_vendedor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:spinnerMode="dialog" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Preço máximo"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<SeekBar
android:id="#+id/sb_preco_max"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:indeterminate="false"
android:max="100"
android:progress="5" />
<TextView
android:id="#+id/tv_filtro_preco"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="5"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<View
android:id="#+id/rv_shoppingcart_separator"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginBottom="2dp"
android:layout_marginTop="10dp"
android:background="#android:color/darker_gray" />
<TextView
android:id="#+id/tv_label_oerdenar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:text="Ordenar por"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/colorPrimary" />
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Preço:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/group_preco"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_marginLeft="5dp"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb_preco_maior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Maior" />
<RadioButton
android:id="#+id/rb_preco_menor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Menor" />
</RadioGroup>
<TextView
android:id="#+id/tv_label_data_Validade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:text="Data de validade:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/group_validade"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="horizontal">
<RadioButton
android:id="#+id/rb_validade_maior"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Maior" />
<RadioButton
android:id="#+id/rb_validade_menor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="false"
android:text="Menor" />
</RadioGroup>
<TextView
android:id="#+id/tv_label_ofertas"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="10dp"
android:text="Apenas ofertas:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<CheckBox
android:id="#+id/cb_offer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:checked="false"
android:text="Selecionar apenas ofertas" />
</LinearLayout>
</ScrollView>
</android.support.v7.widget.CardView>
Hope this helps!
SOLVED
The problem was something related android material design, I didn't note before that some layouts has 2 files, so some files were outdated -.-
Thanks for everyone that tried to help.

how to set button below while creating textview programatically?

I have one button to create textview and edittext programmatically,everything works fine but the issue is when textview and edittext generated button is appear above the textview and edittext,i want to set button below of them,following is my code can any one tell what is the issue?
addnewdata.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
LayoutInflater li = LayoutInflater.from(MainActivity.this);
View promptsView = li.inflate(R.layout.prompts, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainActivity.this);
alertDialogBuilder.setView(promptsView);
final EditText userInput = (EditText) promptsView
.findViewById(R.id.editTextDialogUserInput);
alertDialogBuilder
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
totalFields++;
lnr = (LinearLayout) findViewById(R.id.addnewlinear);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(25, 0, 0, 0);
valueTV = new TextView(MainActivity.this);
// valueTV.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
valueTV.setText(userInput.getText());
valueTV.setLayoutParams(lp);
valueTV.setTextSize(18);
valueTV.setTag("tv_" + totalFields);
valueTV.setId(totalFields);
valueTV.setTextColor(Color.parseColor("#2d6cae"));
LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
lp1.setMargins(25, 0, 25, 0);
lp1.height = 50;
EditText edtvalues = new EditText(MainActivity.this);
edtvalues.setBackgroundResource(R.drawable.rect_edt);
edtvalues.setLayoutParams(lp1);
edtvalues.setTag("ed_" + totalFields);
lnr.addView(valueTV);
lnr.addView(edtvalues);
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
});
xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
>
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#000000"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="IT ADD$"
android:id="#+id/itaddestxt"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="UP"
android:textColor="#ffffff"
android:layout_toRightOf="#+id/itaddestxt"
android:textSize="20sp" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:id="#+id/addnewlinear"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD NEW EVENT"
android:layout_marginTop="10dp"
android:textSize="15dp"
android:id="#+id/txtaddnewevent"
android:textColor="#73b5fa"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtaddnewevent"
android:layout_marginTop="10dp"
android:id="#+id/bluelines"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name of Event:*"
android:layout_below="#+id/bluelines"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:textSize="18dp"
android:textColor="#2d6cae"
android:id="#+id/txtnameofevent"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/edtnameofevent"
android:layout_below="#+id/txtnameofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="15dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Event:*"
android:layout_below="#+id/edtnameofevent"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:textSize="18dp"
android:textColor="#2d6cae"
android:id="#+id/txtdateofevent"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtdateofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:id="#+id/reledtdate"
>
<EditText
android:layout_width="250dp"
android:layout_height="30dp"
android:id="#+id/edtdateofevent"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_toRightOf="#+id/edtdateofevent"
android:layout_marginLeft="10dp"
android:id="#+id/calndrdat"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time of Event:*"
android:layout_below="#+id/reledtdate"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:textSize="18dp"
android:textColor="#2d6cae"
android:id="#+id/txttimeofevent"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txttimeofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:id="#+id/reledttime"
>
<EditText
android:layout_width="250dp"
android:layout_height="30dp"
android:id="#+id/edttimeofevent"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_toRightOf="#+id/edttimeofevent"
android:layout_marginLeft="10dp"
android:id="#+id/timepickrs"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Duration of Event:*"
android:layout_below="#+id/edttimeofevent"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:textSize="18dp"
android:textColor="#2d6cae"
android:id="#+id/txtdurationofevent"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/edtdurationofevent"
android:layout_below="#+id/txtdurationofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="15dp"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/edtdurationofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"
android:id="#+id/addnewdata"
android:text="Add"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textColor="#android:color/white"
android:layout_gravity="center"
android:id="#+id/btnsubmit"
/>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Add a new layout (linear or relative) above the button.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
>
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#000000"
android:gravity="center"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="IT ADD$"
android:id="#+id/itaddestxt"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="UP"
android:textColor="#ffffff"
android:layout_toRightOf="#+id/itaddestxt"
android:textSize="20sp" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/header"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:orientation="vertical"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD NEW EVENT"
android:layout_marginTop="10dp"
android:textSize="15dp"
android:id="#+id/txtaddnewevent"
android:textColor="#73b5fa"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtaddnewevent"
android:layout_marginTop="10dp"
android:id="#+id/bluelines"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name of Event:*"
android:layout_below="#+id/bluelines"
android:layout_marginTop="20dp"
android:layout_marginLeft="15dp"
android:textSize="18dp"
android:textColor="#2d6cae"
android:id="#+id/txtnameofevent"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/edtnameofevent"
android:layout_below="#+id/txtnameofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="15dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date of Event:*"
android:layout_below="#+id/edtnameofevent"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:textSize="18dp"
android:textColor="#2d6cae"
android:id="#+id/txtdateofevent"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txtdateofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:id="#+id/reledtdate"
>
<EditText
android:layout_width="250dp"
android:layout_height="30dp"
android:id="#+id/edtdateofevent"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_toRightOf="#+id/edtdateofevent"
android:layout_marginLeft="10dp"
android:id="#+id/calndrdat"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time of Event:*"
android:layout_below="#+id/reledtdate"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:textSize="18dp"
android:textColor="#2d6cae"
android:id="#+id/txttimeofevent"
/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/txttimeofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:id="#+id/reledttime"
>
<EditText
android:layout_width="250dp"
android:layout_height="30dp"
android:id="#+id/edttimeofevent"
/>
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_toRightOf="#+id/edttimeofevent"
android:layout_marginLeft="10dp"
android:id="#+id/timepickrs"
/>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Duration of Event:*"
android:layout_below="#+id/edttimeofevent"
android:layout_marginTop="5dp"
android:layout_marginLeft="15dp"
android:textSize="18dp"
android:textColor="#2d6cae"
android:id="#+id/txtdurationofevent"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="30dp"
android:id="#+id/edtdurationofevent"
android:layout_below="#+id/txtdurationofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="5dp"
android:layout_marginRight="15dp"
/>
<!--Empty layout-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="#+id/addnewlinear"
android:orientation="vertical"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/edtdurationofevent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
android:paddingBottom="10dp"
android:id="#+id/addnewdata"
android:text="Add"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:textColor="#android:color/white"
android:layout_gravity="center"
android:id="#+id/btnsubmit"
/>
</LinearLayout>
</ScrollView>

Passing a object from my activity to my fragment

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);

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>

Categories

Resources