I have toggle buttons inside linear layout and on click they do not show the ontext and offtext.I also have listener for all toggle buttons and inside onclick function i tried to set the ontext but it didn't work.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:orientation="vertical">
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.example.sharmila.eeeeeee.tryfragment"
android:id="#+id/fragment"
android:layout_centerHorizontal="true"
tools:layout="#layout/try_fragment" />
<LinearLayout android:id="#+id/linearlayout"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/fragment"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:weightSum="1">
<ToggleButton
android:layout_width="49dp"
android:layout_height="40dp"
android:id="#+id/wholenote"
android:layout_row="0"
android:layout_column="0"
android:background="#drawable/a"
android:textOff=""
android:textOn="S"
android:textSize="700dp"
android:textColor="#ff0000"
/>
<ToggleButton
android:layout_width="49dp"
android:layout_height="40dp"
android:id="#+id/halfnote"
android:layout_row="0"
android:layout_column="1"
android:background="#drawable/b"
android:textOff=""
android:textOn="S"
android:textSize="700dp"
android:textColor="#ff0000"/>
<ToggleButton
android:layout_width="49dp"
android:layout_height="40dp"
android:id="#+id/quarternote"
android:layout_row="0"
android:layout_column="2"
android:background="#drawable/c"
android:textOff=""
android:textOn="S"
android:textSize="700dp"
android:textColor="#ff0000"
/>
<ToggleButton
android:layout_width="49dp"
android:layout_height="40dp"
android:id="#+id/eightnote"
android:layout_row="0"
android:layout_column="3"
android:background="#drawable/d"
android:textOn="S"
android:textSize="700dp"
android:textColor="#ff0000"
android:textOff=""/>
<ToggleButton
android:layout_width="49dp"
android:layout_height="40dp"
android:id="#+id/sixteennote"
android:textOn="S"
android:textSize="700dp"
android:textColor="#ff0000"
android:textOff=""
android:layout_row="0"
android:layout_column="4"
android:background="#drawable/e"
/>
<ToggleButton
android:layout_width="49dp"
android:layout_height="40dp"
android:textOn="S"
android:textSize="700dp"
android:textColor="#ff0000"
android:id="#+id/thirtytwonote"
android:layout_row="0"
android:layout_column="5"
android:background="#drawable/g"
/>
<ToggleButton
android:layout_width="49dp"
android:layout_height="40dp"
android:textOn="S"
android:textSize="700dp"
android:textColor="#ff0000"
android:id="#+id/sixyfournote"
android:layout_row="0"
android:layout_column="6"
android:background="#drawable/f"
/>
</LinearLayout>
<TableRow android:id="#+id/Linearlayout2"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_below="#+id/linearlayout"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:weightSum="1">
<View
android:layout_width="10dp"
android:layout_height="40dp"
android:layout_weight="0.34" />
<ImageButton
android:layout_width="49dp"
android:layout_height="40dp"
android:id="#+id/pause"
android:layout_row="0"
android:layout_column="1"
android:src="#drawable/pause" />
<View
android:layout_width="10dp"
android:layout_height="40dp"
android:layout_weight="0.18" />
<ImageButton
android:layout_width="49dp"
android:layout_height="40dp"
android:id="#+id/play"
android:layout_row="0"
android:layout_column="3"
android:src="#drawable/play" />
<View
android:layout_width="10dp"
android:layout_height="40dp"
android:layout_weight="0.18" />
<ImageButton
android:layout_width="49dp"
android:layout_height="40dp"
android:id="#+id/stop"
android:src="#drawable/stop"
android:layout_row="0"
android:layout_column="3"/>
</TableRow>
<GridLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/gridView"
android:layout_below="#+id/Linearlayout2"
>
<Button
android:layout_width="78dp"
android:layout_height="wrap_content"
android:text="Prev"
android:id="#+id/previous"
android:layout_row="0"
android:layout_column="2" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/next"
android:layout_row="0"
android:layout_column="19" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="save"
android:id="#+id/save"
android:layout_row="1"
android:layout_column="1" />
<Button
android:layout_width="99dp"
android:layout_height="wrap_content"
android:text="Finish"
android:id="#+id/finish"
android:layout_row="1"
android:layout_column="21" />
</GridLayout>
Activity code:
private static ToggleButton wholenote;
private static ToggleButton halfnote;
private static ToggleButton quarternote;
private static ToggleButton eighthnote;
private static ToggleButton sixteenthnote;
private static ToggleButton thirtytwonote;
private static ToggleButton sixtyfourthnote;
private static String selected = "01";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wholenote = (ToggleButton) findViewById(R.id.wholenote);
wholenote.setOnClickListener(this);
halfnote = (ToggleButton) findViewById(R.id.halfnote);
halfnote.setOnClickListener(this);
quarternote = (ToggleButton) findViewById(R.id.quarternote);
quarternote.setOnClickListener(this);
eighthnote = (ToggleButton) findViewById(R.id.eightnote);
eighthnote.setOnClickListener(this);
sixteenthnote = (ToggleButton) findViewById(R.id.sixteennote);
sixteenthnote.setOnClickListener(this);
thirtytwonote = (ToggleButton) findViewById(R.id.thirtytwonote);
thirtytwonote.setOnClickListener(this);
sixtyfourthnote = (ToggleButton) findViewById(R.id.sixyfournote);
sixtyfourthnote.setOnClickListener(this);
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.wholenote:
wholenote.setTextOn("S");
break;
case R.id.halfnote:
halfnote.setTextOn("S");
break;
case R.id.quarternote:
quarternote.setTextOn("S");
break;
case R.id.eightnote:
eightnote.setTextOn("S");
break;
case R.id.sixteennote:
sixteennote.setTextOn("S");
break;
case R.id.thirtytwonote:
thirtytwonote.setTextOn("S");
break;
case R.id.sixyfournote:
sixtyfournote.setTextOn("S");
break;
}
}
android:textSize="700dp"
It's not showing on off text,it is because you text size is too large to show it on screen.
Set all togglebuttons textSize 10dp.
android:textSize="10dp"
Related
UPDATE: I've expanded the code, my app works as expected but still getting a NullPointerException when trying to test the activity_main.xml.
I'm trying to test the views in a layout for a calculator but I keep getting NullPointerException even after calling onCreate in the test file, I've also tried setting content view inside the test file directly to the activity_main but no luck.
public class MainActivity extends AppCompatActivity {
ActivityMainBinding binding;
Calculator calculator = new Calculator();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
void onCreateHelper() {
binding = DataBindingUtil.setContentView(this, R.layout.activity_main);
}
public void onNumberClick(View view) {
Button button = (Button) view;
String result = this.getButtonText(button);
this.setValueView(result);
int number = Integer.parseInt(result);
calculator.numberClick(number);
}
public void onOperatorClick(View view) {
Button button = (Button) view;
String value = this.getButtonText(button);
calculator.operatorClick(value);
String result = String.valueOf(calculator.getRunningTotal());
binding.editText.setText(result);
}
public void onClearClick (View view) {
Button button = (Button) view;
String value = this.getButtonText(button);
binding.editText.setText("");
calculator.clearClick();
}
String getButtonText(Button button) {
String result = button.getText().toString();
return result;
}
void setValueView(String value){
binding.editText.setText(binding.editText.getText() + value);
}
}
Test:
public class MainActivityTest<T extends MainActivity> {
private MainActivity mainActivity;
#Before
public void before() {
mainActivity = new MainActivity();
mainActivity.onCreateHelper();
}
#Test
public void OnNumberClickTest() throws Exception {
mainActivity.onNumberClick(mainActivity.binding.buttonSeven);
assertEquals(7, mainActivity.calculator.getRunningTotal());
}
#Test
public void OnOperatorClickTest() throws Exception {
mainActivity.onOperatorClick(mainActivity.binding.buttonAdd);
assertEquals('+', mainActivity.calculator.getPreviousOperator());
}
#Test
public void onClearClickTest() throws Exception {
mainActivity.onClearClick(mainActivity.binding.buttonClear);
assertEquals(0, mainActivity.calculator.getRunningTotal());
}
#Test
public void getButtonTextTest() throws Exception {
String buttonText = mainActivity.getButtonText(mainActivity.binding.buttonEight);
assertEquals(8, buttonText);
}
#Test
public void setValueViewTest() throws Exception {
mainActivity.setValueView("TEST");
assertEquals("TEST", mainActivity.binding.editText.getText());
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="99dp"
android:orientation="vertical" android:layout_weight="0.67">
<TextView
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:gravity="right"
android:paddingRight="10sp"
android:paddingTop="5sp"
android:textSize="15pt"
android:textStyle="bold" />
<TextView
android:id="#+id/txtInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.50"
android:gravity="right"
android:paddingRight="10sp"
android:paddingTop="5sp"
android:textSize="15pt"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="75dp"
android:orientation="horizontal" >
<Button
android:id="#+id/buttonClear"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="5"
android:textStyle="bold"
android:textSize="40sp"
android:text="Clear" />
<Button
android:id="#+id/buttonBack"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight=".51"
android:textStyle="bold"
android:textSize="40sp"
android:text="BS" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="75dp"
android:orientation="horizontal" >
<Button
android:id="#+id/buttonSeven"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="40sp"
android:text="7" />
<Button
android:id="#+id/buttonEight"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="40sp"
android:text="8" />
<Button
android:id="#+id/buttonNine"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="40sp"
android:text="9" />
<Button
android:id="#+id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1.15"
android:textStyle="bold"
android:textSize="40sp"
android:text="/" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="75dp"
android:orientation="horizontal" >
<Button
android:id="#+id/buttonFour"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:textSize="40sp"
android:textStyle="bold"
android:text="4" />
<Button
android:id="#+id/buttonFive"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="40sp"
android:text="5" />
<Button
android:id="#+id/buttonSix"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="40sp"
android:text="6" />
<Button
android:id="#+id/buttonMultiply"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight=".98"
android:textStyle="bold"
android:textSize="40sp"
android:text="x" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="75dp"
android:orientation="horizontal" >
<Button
android:id="#+id/buttonOne"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="40sp"
android:text="1" />
<Button
android:id="#+id/buttonTwo"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="40sp"
android:text="2" />
<Button
android:id="#+id/buttonThree"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1"
android:textStyle="bold"
android:textSize="40sp"
android:text="3" />
<Button
android:id="#+id/buttonSubtract"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1.27"
android:textStyle="bold"
android:textSize="40sp"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="75dp"
android:orientation="horizontal" >
<Button
android:id="#+id/buttonDot"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight="1.22"
android:textStyle="bold"
android:textSize="40sp"
android:text="." />
<Button
android:id="#+id/buttonZero"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight=".98"
android:textStyle="bold"
android:textSize="40sp"
android:text="0" />
<Button
android:id="#+id/buttonEqual"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight=".95"
android:textStyle="bold"
android:textSize="40sp"
android:text="=" />
<Button
android:id="#+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="75dp"
android:layout_weight=".93"
android:textStyle="bold"
android:textSize="40sp"
android:text="+" />
</LinearLayout>
</LinearLayout>
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.
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'm trying to have a popup window show details of an invoice. I look at examples on the internet and they all look like this so I don't understand why it get an error when I try to inflate the view. the only thing I noticed is that it have the word (port) after the invoice_look in the projects layout folder.
I get this error on the line:
View popupView = layoutInflater.inflate(R.layout.invoice_look,null);
this = {com.android.internal.os.RuntimeInit$UncaughtHandler#21167}
shadow$_klass_ = {java.lang.Class#20712} "class com.android.internal.os.RuntimeInit$UncaughtHandler"
accessFlags = 524288
classLoader = null
classSize = 416
clinitThreadId = 14084
componentType = null
dexCache = {java.lang.DexCache#21169}
dexCacheStrings = {java.lang.String[105519]#21170}
dexClassDefIndex = 3975
dexTypeIndex = 4549
directMethods = {java.lang.reflect.ArtMethod[2]#21171}
iFields = null
ifTable = {java.lang.Object[2]#21172}
name = {java.lang.String#21173} "com.android.internal.os.RuntimeInit$UncaughtHandler"
numReferenceInstanceFields = 0
numReferenceStaticFields = 0
objectSize = 8
primitiveType = 0
referenceInstanceOffsets = -2147483648
referenceStaticOffsets = 0
sFields = null
status = 10
superClass = {java.lang.Class#20126} "class java.lang.Object"
verifyErrorClass = null
virtualMethods = {java.lang.reflect.ArtMethod[1]#21174}
vtable = null
shadow$_klass_ = {java.lang.Class#18444} "class java.lang.Class"
shadow$_monitor_ = -1493239949
shadow$_monitor_ = -1272289465
Here is the the code in my activity.
lookBtn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
LayoutInflater layoutInflater = (LayoutInflater) Pickup.this.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.invoice_look,null);
final PopupWindow popupWindow = new PopupWindow(popupView, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
Button dismissBtn = (Button) popupView.findViewById(R.id.lookDismiss);
dismissBtn.setOnClickListener(new Button.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
popupWindow.dismiss();
}
});
popupWindow.showAtLocation(v, Gravity.CENTER, 0, 0);
}
});
Here is the XML for the invoice_look window.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/invLookLayout">
<ListView
android:id="#+id/listView"
android:layout_width="500dp"
android:layout_height="520dp" />
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableRow
android:id="#+id/tableRow"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
style="#style/BlackSText"
android:id="#+id/textView25"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:text="#string/discount" />
<TextView
style="#style/BlackSText"
android:id="#+id/textView26"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start" />
<TextView
style="#style/BlackSText"
android:id="#+id/lookDiscount"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end" />
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
style="#style/BlackSText"
android:id="#+id/textView28"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:text="#string/env" />
<TextView
style="#style/BlackSText"
android:id="#+id/textView29"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start" />
<TextView
style="#style/BlackSText"
android:id="#+id/lookEnviro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end" />
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
style="#style/BlackSText"
android:id="#+id/textView31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:text="#string/salestax" />
<TextView
style="#style/BlackSText"
android:id="#+id/textView32"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start" />
<TextView
style="#style/BlackSText"
android:id="#+id/lookSalesTax"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end" />
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
style="#style/BlackText"
android:id="#+id/textView34"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:text="#string/total" />
<TextView
style="#style/BlackText"
android:id="#+id/lookPcs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="start"
android:text="#string/pcs" />
<TextView
style="#style/BlackText"
android:id="#+id/lookTotal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="end" />
</TableRow>
</TableLayout>
<TextView
style="#style/BlackText"
android:id="#+id/textView24"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="20sp" />
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnCount="5"
android:columnOrderPreserved="true"
android:rowCount="1"
android:rowOrderPreserved="false"
android:useDefaultMargins="false"
android:orientation="horizontal"
android:id="#+id/gridLayout"
android:focusableInTouchMode="false" >
<Button
style="#style/BlackSText"
android:id="#+id/lookDismiss"
android:layout_width="96dp"
android:layout_height="70dp"
android:layout_column="0"
android:layout_row="0"
android:background="#drawable/lightrebbtn"
android:text="#string/cancel"
android:layout_gravity="fill_horizontal" />
<Button
style="#style/BlackSText"
android:id="#+id/button58"
android:layout_width="96dp"
android:layout_height="70dp"
android:layout_column="1"
android:layout_row="0"
android:background="#drawable/yellowbtn"
android:text="#string/del"
android:layout_gravity="fill_horizontal" />
<Button
style="#style/BlackSText"
android:id="#+id/button61"
android:layout_width="96dp"
android:layout_height="70dp"
android:layout_column="2"
android:layout_row="0"
android:background="#drawable/yellowbtn"
android:text="#string/price"
android:layout_gravity="fill_horizontal" />
<Button
style="#style/BlackSText"
android:id="#+id/button62"
android:layout_width="96dp"
android:layout_height="70dp"
android:layout_column="3"
android:layout_row="0"
android:background="#drawable/yellowbtn"
android:text="#string/myo"
android:layout_gravity="fill_horizontal" />
<Button
style="#style/BlackSText"
android:id="#+id/button63"
android:layout_width="96dp"
android:layout_height="70dp"
android:layout_column="4"
android:layout_row="0"
android:background="#drawable/yellowbtn"
android:text="#string/coupon"
android:layout_gravity="fill_horizontal" />
</GridLayout>
</LinearLayout>
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>