Best way to make CardView hide - java

this CardView
<android.support.v7.widget.CardView
android:id="#+id/cardv"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="visible"
android:layout_margin="8dp"
app:cardElevation="4dp">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:orientation="horizontal"
android:layout_gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_margin="2dp"
android:orientation="vertical"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content">
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Data:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_date"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Order Date"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Nº de pedido:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_id"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="#111111"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Nome:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/userName"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Contacto:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_phone"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="123456789"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Morada:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_address"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Address"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Metodo de pagamento:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/paymentMethod"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Payment Method"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Estado de pagamento:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/paymentState"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Payment State"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Estado do pedido:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/order_status"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Status"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_marginLeft="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:text="Total:"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/totalAmount"
android:layout_marginLeft="10dp"
android:layout_gravity="center_vertical|start"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="#android:color/black"
android:text="Total Amount"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_weight="4"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<info.hoang8f.widget.FButton
android:layout_margin="5dp"
android:id="#+id/btnEdit"
android:text="Estado"
android:textColor="#android:color/white"
android:shadowColor="#android:color/black"
android:layout_weight="1"
app:cornerRadius="5dp"
app:fButtonColor="#android:color/holo_red_light"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<info.hoang8f.widget.FButton
android:id="#+id/btnHide"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_weight="1"
android:onClick="Hide"
android:shadowColor="#android:color/black"
android:text="Finalizr"
android:textColor="#android:color/white"
app:cornerRadius="5dp"
app:fButtonColor="#android:color/holo_blue_light" />
<info.hoang8f.widget.FButton
android:id="#+id/btnDetail"
android:layout_margin="5dp"
android:text="Detalhes"
android:layout_weight="1"
android:textColor="#android:color/white"
android:shadowColor="#android:color/black"
app:cornerRadius="5dp"
app:fButtonColor="#android:color/holo_orange_light"
android:layout_width="0dp"
android:layout_height="wrap_content" />
<info.hoang8f.widget.FButton
android:id="#+id/btnDirection"
android:layout_margin="5dp"
android:text="Direções"
android:layout_weight="1"
android:textColor="#android:color/white"
android:shadowColor="#android:color/black"
app:cornerRadius="5dp"
app:fButtonColor="#android:color/holo_green_dark"
android:layout_width="0dp"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
appears in this list:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:padding="16dp"
android:background="#drawable/bgencomendeas"
tools:context=".OrderStatus">
<Button
android:id="#+id/voltar2"
android:layout_width="65dp"
android:layout_height="wrap_content"
android:background="#color/fbutton_color_transparent"
android:text="Voltar"
android:textSize="12sp"
android:textStyle="bold"
tools:ignore="MissingConstraints" />
<pl.droidsonroids.gif.GifImageView
android:id="#+id/imgAndroidInstalike2"
android:layout_width="85dp"
android:layout_height="98dp"
android:layout_alignParentBottom="true"
android:background="#drawable/instalike2"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="297dp"
tools:layout_editor_absoluteY="595dp" />
<android.support.v7.widget.RecyclerView
android:layout_marginTop="46dp"
android:id="#+id/listOrders"
android:background="#android:color/transparent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout>
I declared in ViewHolder :
public class OrderViewHolder extends RecyclerView.ViewHolder{
public TextView txtOrderId,txtOrderStatus,txtOrderPhone,txtOrderAddress,txtOrderDate,txtPaymentState,txtPaymentMethod,txtName,txtTotal;
public Button btnEdit,btnHide,btnRemove,btnDetail,btnDirection;
public CardView cardlayoutadapter;
public OrderViewHolder(#NonNull View itemView) {
super(itemView);
txtOrderAddress=(TextView)itemView.findViewById(R.id.order_address);
txtOrderId=(TextView)itemView.findViewById(R.id.order_id);
txtOrderStatus=(TextView)itemView.findViewById(R.id.order_status);
txtOrderPhone=(TextView)itemView.findViewById(R.id.order_phone);
txtOrderDate=(TextView)itemView.findViewById(R.id.order_date);
txtPaymentState=(TextView)itemView.findViewById(R.id.paymentState);
txtPaymentMethod=(TextView)itemView.findViewById(R.id.paymentMethod);
txtName=(TextView)itemView.findViewById(R.id.userName);
txtTotal=(TextView)itemView.findViewById(R.id.totalAmount);
btnEdit=(Button)itemView.findViewById(R.id.btnEdit);
btnRemove=(Button)itemView.findViewById(R.id.btnRemove);
btnHide=(Button)itemView.findViewById(R.id.btnHide);
btnDetail=(Button)itemView.findViewById(R.id.btnDetail);
btnDirection=(Button)itemView.findViewById(R.id.btnDirection);
cardlayoutadapter = (CardView)itemView.findViewById(R.id.cardv);
}
}
when I click the btnHide button it goes to "private void hideOrder" to make sure I want to make it disappear after completing the order, and this is where I wanted to somehow make the cardview disappear with that data, so it's not there to occupy , I have another "layout that makes eliminate", either in GONE or invisibility or put the parameter layout_height == 0
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/Vahika.ttf")
.setFontAttrId(R.attr.fontPath)
.build());
setContentView(R.layout.activity_order_status);
#Override
protected void onBindViewHolder(#NonNull OrderViewHolder holder, final int position, #NonNull final Request model) {
holder.txtOrderId.setText(adapter.getRef(position).getKey());
holder.txtOrderStatus.setText(Common.convertCodeToStatus(model.getStatus()));
holder.txtOrderAddress.setText(model.getAddress());
holder.txtOrderPhone.setText(model.getPhone());
holder.txtOrderDate.setText(Common.getDate(Long.parseLong(adapter.getRef(position).getKey())));
holder.txtPaymentMethod.setText(model.getPaymentMethod());
holder.txtPaymentState.setText(model.getPaymentState());
holder.txtName.setText(model.getName());
holder.txtTotal.setText(model.getTotal());
holder.btnHide.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
hideOrder(adapter.getRef(position).getKey());
}
});
private void hideOrder(final String key) {
AlertDialog.Builder alertDialog=new AlertDialog.Builder(OrderStatus.this);
alertDialog.setTitle("Olá, "+Common.currentUser.getName());
alertDialog.setMessage("O pedido foi entregue?");
alertDialog.setCancelable(false);
alertDialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//linearcardv
//reuests.child(key).removeValue();
//binding.CardView.setVisibility(View.GONE);
//reuests.child(key).setValue(View.INVISIBLE);
cardlayoutadapter.setVisibility(View.GONE);
adapter.notifyDataSetChanged();
Toast.makeText(OrderStatus.this, "Pedido finalizado com sucesso!", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setNegativeButton("Não", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Toast.makeText(OrderStatus.this, "Cancelado", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setIcon(R.mipmap.picture);
alertDialog.show();
}

private void hideOrder(final Integer position) {//Pass selected item position
AlertDialog.Builder alertDialog=new AlertDialog.Builder(OrderStatus.this);
alertDialog.setTitle("Olá, "+Common.currentUser.getName());
alertDialog.setMessage("O pedido foi entregue?");
alertDialog.setCancelable(false);
alertDialog.setPositiveButton("Sim", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
//**remove item from list at specific position**
adapter.notifyDataSetChanged();
Toast.makeText(OrderStatus.this, "Pedido finalizado com sucesso!", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setNegativeButton("Não", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
Toast.makeText(OrderStatus.this, "Cancelado", Toast.LENGTH_SHORT).show();
}
});
alertDialog.setIcon(R.mipmap.picture);
alertDialog.show();
}

Related

Text in NestedScrollView in Fragment overlaps the 2nd time that I open the Fragment. First time it works fine

I've got a NestedScrollView inside of a ScrollView because I have an Activity with three hidden fragments that contain text, and when you click one of the fragments it opens to reveal the text. But the thing is that there is quite a bit of text so I'm using NestedScrollView so the reader can read all of it, and the first time it works fine (text doesn't overlap), and then second time when I close the fragment and re-open it the text starts overlapping...
So as mentioned, first time it doesn't happen, and then I close the fragment and reopen it and this happens:
So why is this happening and how can I fix it?
Fragment inside Activity
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbars="none"
tools:context=".Fragment.PrivacyFragment">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="22sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/Grey"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/Grey"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/Grey"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginTop="5dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="22dp"
android:layout_marginEnd="20dp"
android:padding="8dp"
android:textColor="#color/colorBlack"
android:textSize="16sp" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
Activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/button_gradient_two">
<RelativeLayout
android:id="#+id/relative_layout_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="25dp"
android:layout_marginEnd="10dp">
</RelativeLayout>
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="none">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/arrow_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="10dp"
android:layout_marginTop="25dp"
android:padding="8dp"
android:src="#drawable/icon_search_100" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:padding="8dp"
android:text="Settings"
android:textColor="#color/White"
android:textSize="22sp"
android:textStyle="bold" />
<de.hdodenhof.circleimageview.CircleImageView
android:id="#+id/image_profile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp"
android:elevation="16dp"
android:src="#drawable/profile_placeholder" />
<com.google.android.material.card.MaterialCardView
style="#style/CustomCardViewStyle"
android:layout_width="match_parent"
android:layout_height="1000dp"
android:layout_marginTop="150dp"
app:cardElevation="12dp">
<RelativeLayout
android:id="#+id/relative_layout_two"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"
android:gravity="center_horizontal"
android:text="Jack Sparrow"
android:textColor="#color/Black"
android:textSize="32sp"
android:textStyle="bold" />
<TextView
android:id="#+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/name"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:text="jacksparrow"
android:textColor="#color/Grey"
android:textSize="22sp"
android:textStyle="" />
<TextView
android:id="#+id/bio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/username"
android:layout_centerHorizontal="true"
android:layout_marginTop="4dp"
android:gravity="center_horizontal"
android:text="This is my bio!"
android:textColor="#color/Grey"
android:textStyle="" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bio"
android:orientation="vertical">
<TextView
android:id="#+id/privacy"
style="#style/SelectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="#string/privacy"
android:textColor="#color/colorBlack"
android:textSize="18sp" />
<FrameLayout
android:id="#+id/container_privacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="#+id/security"
style="#style/SelectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="#string/security"
android:textColor="#color/colorBlack"
android:textSize="18sp" />
<FrameLayout
android:id="#+id/container_security"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="#+id/help"
style="#style/SelectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="#string/help"
android:textColor="#color/colorBlack"
android:textSize="18sp" />
<FrameLayout
android:id="#+id/container_help"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
<TextView
android:id="#+id/about"
style="#style/SelectableItemBackground"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="12dp"
android:text="#string/about"
android:textColor="#color/colorBlack"
android:textSize="18sp" />
<FrameLayout
android:id="#+id/container_about"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
</com.google.android.material.card.MaterialCardView>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
SettingsActivity
public class SettingsActivity extends AppCompatActivity {
private ImageView mImageProfile, mBackArrow;
private TextView mName, mUsername, mBio, mPrivacy, mSecurity, mHelp, mAbout;
private FirebaseUser mFirebaseUser;
private FrameLayout mPrivacyContainer, mSecurityContainer, mHelpContainer, mAboutContainer;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings_tester);
mFirebaseUser = FirebaseAuth.getInstance().getCurrentUser();
mImageProfile = findViewById(R.id.image_profile);
mName = findViewById(R.id.name);
mUsername = findViewById(R.id.username);
mBio = findViewById(R.id.bio);
mPrivacy = findViewById(R.id.privacy);
mSecurity = findViewById(R.id.security);
mHelp = findViewById(R.id.help);
mAbout = findViewById(R.id.about);
mImageProfile.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.profile_animation_profile_picture));
mName.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.profile_animation_name));
mUsername.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.profile_animation_username));
mBio.setAnimation(AnimationUtils.loadAnimation(getApplicationContext(), R.anim.profile_animation_bio));
mPrivacyContainer = findViewById(R.id.container_privacy);
mSecurityContainer = findViewById(R.id.container_security);
mHelpContainer = findViewById(R.id.container_help);
mAboutContainer = findViewById(R.id.container_about);
mPrivacy.setOnClickListener(v -> {
getSupportFragmentManager().beginTransaction().add(R.id.container_privacy, new PrivacyFragment(), null).addToBackStack(null).commit();
if (mPrivacyContainer.getVisibility() == View.GONE) {
mPrivacyContainer.setVisibility(View.VISIBLE);
} else {
mPrivacyContainer.setVisibility(View.GONE);
}
});
mSecurity.setOnClickListener(v -> {
getSupportFragmentManager().beginTransaction().add(R.id.container_security, new SecurityFragment(), null).addToBackStack(null).commit();
if (mSecurityContainer.getVisibility() == View.GONE) {
mSecurityContainer.setVisibility(View.VISIBLE);
} else {
mSecurityContainer.setVisibility(View.GONE);
}
});
mHelp.setOnClickListener(v -> {
getSupportFragmentManager().beginTransaction().add(R.id.container_help, new HelpFragment(), null).addToBackStack(null).commit();
if (mHelpContainer.getVisibility() == View.GONE) {
mHelpContainer.setVisibility(View.VISIBLE);
} else {
mHelpContainer.setVisibility(View.GONE);
}
});
mAbout.setOnClickListener(v -> {
getSupportFragmentManager().beginTransaction().add(R.id.container_about, new AboutFragment(), null).addToBackStack(null).commit();
if (mAboutContainer.getVisibility() == View.GONE) {
mAboutContainer.setVisibility(View.VISIBLE);
} else {
mAboutContainer.setVisibility(View.GONE);
}
});
getUserInfo();
setBackArrow();
}
private void getUserInfo() {
DatabaseReference reference = FirebaseDatabase.getInstance().getReference("Users").child(mFirebaseUser.getUid());
reference.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(#NonNull DataSnapshot dataSnapshot) {
User user = dataSnapshot.getValue(User.class);
if (user != null) {
mName.setText(user.getFullname());
mUsername.setText(user.getUsername());
mBio.setText(user.getBio());
if (user.getImageurl() == null) {
mImageProfile.setImageResource(R.drawable.profile_placeholder);
} else {
Glide.with(getApplicationContext()).load(user.getImageurl()).into(mImageProfile);
}
}
}
#Override
public void onCancelled(#NonNull DatabaseError databaseError) {
}
});
}
private void setBackArrow() {
mBackArrow = findViewById(R.id.arrow_back);
mBackArrow.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
finish();
}
});
}
}
You are getting the fragment overlapped because there is a new fragment added each time.
You simply need to do a check if the fragment exits already then there is no need to add a new fragment. You can assign a 'tag' when adding fragment. Code as follows-
if (fragmentManager.findFragmentByTag("First Fragment") == null)
fragmentManager.beginTransaction().add(R.id.fragment, new FirstFragment(), "First Fragment").commit();
OR
Rather then using .add() method use .replace() to make sure fragment got replaced each time.
According to your Activity code, you need to choose the correct way, but make sure there is no fragment getting re-created without destroying previous one.
Happy Coding !!
You are adding two fragments on top of each other.
Instead of add use replace when executing the fragment transaction:
From:
getSupportFragmentManager().beginTransaction().add(R.id.container_privacy, new PrivacyFragment(), null).addToBackStack(null).commit();
if (mPrivacyContainer.getVisibility() == View.GONE) {
mPrivacyContainer.setVisibility(View.VISIBLE);
} else {
mPrivacyContainer.setVisibility(View.GONE);
}
To:
getSupportFragmentManager().beginTransaction().replace(R.id.container_privacy, new PrivacyFragment(), null).addToBackStack(null).commit();
if (mPrivacyContainer.getVisibility() == View.GONE) {
mPrivacyContainer.setVisibility(View.VISIBLE);
} else {
mPrivacyContainer.setVisibility(View.GONE);
}

Android How to create rain like animtion?

I want to create a animation with some dots and they are falling from top to bottom. For that I am using a translate animation which moves the dots images from top to bottom. But I want this to be continuous meaning the animation should repeat itself.
I have to create a animation with some dots and they are falling from top to bottom i will post gif animation file , which is my requirement , please anyone guide me how to create this one?
it starts with FadeIn animation it is running fine in my code and then the dots moving in continuous Motion from TOP TO BOTTOM as in gif i have posted it is not working in my code i have created 14 Linearlayouts they contains 7 texviews Horizontally with VISIBILITY.GONE in Oncreate i am changing its VISIBILITY to VISIBLE and starting FADE IN animation and i will post my code , please anyone guide me?
MY REQUIREMNET
rain_like_animation
public class MainActivity extends Activity implements AnimationListener {
LinearLayout move_animation, move_animation1, move_animation2,
move_animation3, move_animation4, move_animation5;
Display display;
Point size2;
int width1, height1;
// Animation
Animation animFadein;
TranslateAnimation translateanimation;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
display = getWindowManager().getDefaultDisplay();
size2 = new Point();
display.getSize(size2);
width1 = size2.x;
height1 = size2.y;
move_animation = (LinearLayout) findViewById(R.id.move_animation);
move_animation1 = (LinearLayout) findViewById(R.id.move_animation1);
move_animation2 = (LinearLayout) findViewById(R.id.move_animation2);
move_animation3 = (LinearLayout) findViewById(R.id.move_animation3);
// load the animation
animFadein = AnimationUtils.loadAnimation(getApplicationContext(),R.anim.fade_in);
// set animation listener
animFadein.setAnimationListener(this);
// (float fromXDelta, float toXDelta, float fromYDelta, float toYDelta)
translateanimation = new TranslateAnimation(0.0f, 0.0f, -50.0f, height1);
translateanimation.setDuration(3000);
translateanimation.setRepeatCount(Animation.INFINITE);
translateanimation.setRepeatMode(Animation.RESTART);
translateanimation.setFillAfter(false);
translateanimation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
Log.e("onAnimationStart", "onAnimationStart");
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
Log.e("onAnimationRepeat", "onAnimationRepeat");
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
Log.e("onAnimationEnd", "onAnimationEnd");
}
});
move_animation.setVisibility(View.VISIBLE);
move_animation1.setVisibility(View.VISIBLE);
move_animation2.setVisibility(View.VISIBLE);
move_animation3.setVisibility(View.VISIBLE);
// start the Fadein animation
// =============================================
// =============================================
move_animation.startAnimation(animFadein);
move_animation1.startAnimation(animFadein);
move_animation2.startAnimation(animFadein);
move_animation3.startAnimation(animFadein);
}
#Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// start the translate animation when fade-in stops
move_animation.startAnimation(translateanimation);
move_animation1.startAnimation(translateanimation);
move_animation2.startAnimation(translateanimation);
move_animation3.startAnimation(translateanimation);
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/splashimage"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/move_animation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/move_animation1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/move_animation2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/move_animation3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal"
android:visibility="gone"
android:weightSum="7" >
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_red_dark" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:gravity="center"
android:text="."
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#android:color/holo_blue_bright" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Download this library https://github.com/plattysoft/Leonids
Add this to your project dependency
then
new ParticleSystem(RainActivity.this, 80, R.drawable.rain_drop, 10000)
.setSpeedByComponentsRange(0f, 0f, 0.05f, 0.1f)
.setAcceleration(0.00005f, 90)
.emitWithGravity(findViewById(R.id.cloud), Gravity.BOTTOM, 8);
It will look like

Nullpointer setadapter in spinner

this is my code where there is an error.
i think that every its ok but i dont know where is the error
this is my code:
public class MainActivity extends Activity implements OnItemSelectedListener{
private EditText promAcum;
private EditText credCur;
private EditText sem;
private EditText num_examenes;
private EditText editText13;
private EditText editText14;
private EditText editText15;
private EditText editText16;
private EditText editText17;
private EditText editText18;
private EditText editText19;
private EditText editText20;
private EditText editText21;
private Spinner spinner1;
public String valorPromAcum;
public String valorCredCur;
public String valorSem;
public String[] numeroExamenes={"3","4","5","6"};
private final static String TAG_FRAGMENT = "TAG_FRAGMENT";
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FragmentManager fm = getFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragment_content);
if (fragment == null) {
FragmentTransaction ft = fm.beginTransaction();
ft.add(R.id.fragment_content, new MainFragment());
ft.commit();
}
promAcum = (EditText) findViewById(R.id.promAcum);
credCur = (EditText) findViewById(R.id.credCur);
sem = (EditText) findViewById(R.id.sem);
editText13 = (EditText)findViewById(R.id.editText13);
editText14 = (EditText)findViewById(R.id.editText14);
editText15 = (EditText)findViewById(R.id.editText15);
editText16 = (EditText)findViewById(R.id.editText16);
editText17 = (EditText)findViewById(R.id.editText17);
editText18 = (EditText)findViewById(R.id.editText18);
editText19 = (EditText)findViewById(R.id.editText19);
editText20 = (EditText)findViewById(R.id.editText20);
editText21 = (EditText)findViewById(R.id.editText21);
spinner1 = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String> (this,android.R.layout.simple_spinner_item,numeroExamenes);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner1.setAdapter(dataAdapter);
addListenerOnSpinnerItemSelection();
}
public void addListenerOnSpinnerItemSelection(){
spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
Toast.makeText(MainActivity.this,
"On Button Click : " +
"\n" + String.valueOf(spinner1.getSelectedItem()) ,
Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
});}
this is my xml code
<LinearLayout 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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:text="#string/materias"
android:textSize="20sp" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:ems="10"
android:inputType="text" >
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/creditos"
android:textSize="20sp" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3"
android:layout_marginBottom="30sp">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cantidad de Examenes"
android:textSize="20sp" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableRow
android:id="#+id/tableRow1"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="20sp"
android:text="Examen" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:textSize="20sp"
android:text="Nota" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="center"
android:layout_weight="2"
android:text="%" />
</TableRow>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TableRow
android:id="#+id/tableRow2"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text"/>
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"/>
<EditText
android:id="#+id/editText6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number"/>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text"/>
<EditText
android:id="#+id/editText8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"/>
<EditText
android:id="#+id/editText9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number"/>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text"/>
<EditText
android:id="#+id/editText11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"/>
<EditText
android:id="#+id/editText12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number"/>
</TableRow>
<TableRow
android:id="#+id/tableRow5"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text"/>
<EditText
android:id="#+id/editText14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"/>
<EditText
android:id="#+id/editText15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number"/>
</TableRow>
<TableRow
android:id="#+id/tableRow6"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text"/>
<EditText
android:id="#+id/editText17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"/>
<EditText
android:id="#+id/editText18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number"/>
</TableRow>
<TableRow
android:id="#+id/tableRow7"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="text"/>
<EditText
android:id="#+id/editText20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="numberDecimal"/>
<EditText
android:id="#+id/editText21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:inputType="number" />
</TableRow>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/guardar" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:onClick="agregarNotas"
android:text="#string/materias" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="3"
android:text="#string/nueva" />
</LinearLayout>
logcat error line 78 : spinner1.setadapter(adapter);
enter code here09-03 11:25:46.344: E/AndroidRuntime(7841): Caused by: java.lang.NullPointerException
09-03 11:25:46.344: E/AndroidRuntime(7841): at com.jonathanar.promapp.MainActivity.onCreate(MainActivity.java:78)
any suggestions are appreciated
You are trying to retrieve Views from Activity, but they are in Fragment.
getActivity().findViewById(R.id.yourId); is what you should do whenever you are using findViewById() method.
The NullPointerException is not a problem with instantiating your adapter, but rather with the way you are getting the Spinner.
If the spinner exists in the fragment you need to specify its context as so.
just putting findViewById() is really this.findViewById(), where this is your activity. In other words your telling the method to find views in the content view of the activity.
If the spinner is in the content view of the fragment, you need to instead use
fragment.getActivity().findViewById(R.id.???);
this way findViewById() knows to find your spinner in the context of the fragment.
Hope this helps!

ListView row not clickable (after adding two buttons)

Strangely, my listView's onClick no longer works after I added two Buttons: Submit and Show Result.
Here is the list view xml.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".CulturalActivity"
android:background="#EFEFEF"
android:id="#+id/AdLayout"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="3dp"
>
<ListView
android:id="#+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:divider="#android:color/transparent"
android:descendantFocusability="blocksDescendants"
android:scrollbars="none"
android:dividerHeight="10dp"
android:listSelector="#drawable/list_selector" />
</RelativeLayout>
Here is the layout of each list row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="315dp"
android:clickable="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="7dp"
android:background="#drawable/bg_card"
android:orientation="horizontal"
android:padding="5dip" >
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginLeft="-60dp"
android:background="#2093CD"
android:gravity="center_horizontal" >
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="52dp"
android:text="Audit"
android:textColor="#android:color/white"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/relativeLayout2" />
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Farm/Grp"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignTop="#+id/tile"
android:layout_toRightOf="#+id/textView4" />
<!--thumbnail-->
<LinearLayout
android:layout_width="80dp"
android:layout_height="80dp"
android:background="#drawable/thumbnail_image"
android:layout_marginTop="35dp"
android:gravity="center"
android:id="#+id/tile">
<ImageView
android:id="#+id/thumbImage"
android:layout_width="50dp"
android:clickable="false"
android:layout_height="50dp"
android:src="#drawable/opened" />
</LinearLayout>
<TextView
android:id="#+id/crophead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Crop"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_alignBottom="#+id/tile"
android:layout_alignLeft="#+id/title" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Certification"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginTop="10dp"
android:layout_below="#+id/textView4"
android:layout_alignParentLeft="true" />
<TextView
android:id="#+id/certification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/textView2"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/title"
android:text="Test"
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Audit Type"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/tile"
android:layout_alignLeft="#+id/textView2"
android:layout_marginTop="20dp" />
<TextView
android:id="#+id/audittype"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignLeft="#+id/certification"
android:maxLines="2"
android:text="ES"
android:textColor="#343434"
android:textSize="17sp" />
<View
android:layout_width="fill_parent"
android:layout_height="3px"
android:layout_marginTop="200dp"
android:background="#21265b"
android:id="#+id/view" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_below="#+id/view"
android:layout_alignLeft="#+id/view"
android:layout_marginLeft="5dp"
android:layout_marginTop="5dp"
android:layout_alignParentBottom="false" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="End Date"
android:textColor="#000000"
android:typeface="sans"
android:textSize="17sp"
android:textStyle="bold"
android:layout_marginRight="15dp"
android:layout_alignTop="#+id/textView6"
android:layout_alignRight="#+id/startdate" />
<TextView
android:id="#+id/startdate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="30/05/1992"
android:textSize="17sp"
android:layout_alignTop="#+id/enddate"
android:layout_toRightOf="#+id/relativeLayout2"
android:layout_marginLeft="6dp"
android:layout_alignParentBottom="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#8B1A1A"
android:text="2/13/14"
android:textSize="17sp"
android:id="#+id/enddate"
android:layout_below="#+id/textView7"
android:layout_alignRight="#+id/textView7" />
<TextView
android:id="#+id/farm"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/audittype"
android:maxLines="3"
android:layout_alignTop="#+id/title"
android:text="Tea Estate Nagarcoil Tamil Nadu, India "
android:textColor="#343434"
android:textSize="17sp" />
<TextView
android:id="#+id/crop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/farm"
android:layout_alignTop="#+id/crophead"
android:maxLines="2"
android:text="Wheat without its chaff and barn but not brown"
android:textColor="#343434"
android:textSize="17sp" />
<Button
android:id="#+id/upsync"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:background="#drawable/blue_thumb"
android:layout_below="#+id/enddate"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Show Results"
android:textColor="#android:color/white" />
<Button
android:id="#+id/submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/upsync"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_below="#+id/enddate"
android:background="#drawable/blue_thumb"
android:text="Submit"
android:textColor="#android:color/white" />
</RelativeLayout>
Here is the click snippet of the list view:
listview.setOnItemClickListener( new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View view,
int position, long id) {
long audit_id;
try{
audit_id = (new CustomListAdapter(HomeList.this, c).getAuditID(position));
changeTileStatus(audit_id,"opened");
System.out.println("listClicked");
sendAuditAndIntent(audit_id);
}catch(Exception e)
{
System.out.println("ERROR # HOMELIST list onClick: "+e);
}
}
private void sendAuditAndIntent(long audit_id) { //sends audit id and api key
Intent intent = new Intent(HomeList.this,ChapterActivity.class );
Bundle extras= new Bundle();
extras.putString("audit_id",String.valueOf(audit_id));
extras.putString("api_key", api_key);
intent.putExtras(extras);
startActivity(intent);
}
private void changeTileStatus(long audit_id, String value) {
AuditTableManager tile= new AuditTableManager(HomeList.this);
tile.open();
tile.updateEntry(audit_id, value);
tile.close();
}
});
OnItemClickListener is not called if cells contain clickable Views. It is an Android feature. You can handle clicks by OnClickListener then - set it to your two buttons (not the listView itself).
In your adapter:
public View onCreateView(..., final int position){
...
convertView.findViewById(R.id.button1).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction1(position);
}
});
convertView.findViewById(R.id.button2).setOnClickListener(new OnClickListener(){
public void onClick(View view){
itemClickedAction2(position);
}
});
...
}
Try android:Focusable="false" and also android:clickable="false" in the custom row TextView

Android - Customizing Dialog using an Xml Layout

I am trtying to create this layout below, but I can seem to get the right
layout that I need. What I'm trying to accomplish is have a customize dailog box,
using a layout. I tried edit the xml below but if this is shown as a dialog the
defined layout is a mess. Please help me understand what I need to do for
this. THanks and looking forward. They dialog is SHOWING but the layout is not met.
This layout is what I am trying to accomplish:
Dialog:
View checkBoxView = View.inflate(this, R.layout.display_item_dialog, null);
CheckBox checkBox = (CheckBox)checkBoxView.findViewById(R.id.checkBox1);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// Save to shared preferences
}
});
checkBox.setText("Search All Images");
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Image Preferences");
builder.setMessage(" Select from below ")
.setView(checkBoxView)
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
}).show();
display_item_dialog.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="Map Category: BEVERAGES" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="200dip"
android:layout_height="200dip"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView1"
android:layout_marginTop="14dp"
android:src="#drawable/sunny" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView2"
android:layout_marginTop="28dp"
android:text="TextView" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageView1"
android:layout_marginRight="20dp"
android:layout_marginTop="47dp"
android:text="+" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView2"
android:layout_alignLeft="#+id/button1"
android:layout_marginBottom="14dp"
android:text="-" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button2"
android:layout_alignRight="#+id/button2"
android:layout_below="#+id/button1"
android:ems="10"
android:clickable="false" >
<requestFocus />
</EditText>
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/textView3"
android:layout_marginTop="33dp"
android:text="CheckBox" />
</RelativeLayout>
You can refer to this tutorials
http://www.mkyong.com/android/android-custom-dialog-example/
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.custom);
dialog.setTitle("Title...");
// set the custom dialog components - text, image and button
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Android custom dialog example!");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
// if button is clicked, close the custom dialog
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
Try this:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Map Category: BEVERAGES" />
<LinearLayout
android:id="#+id/linear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:gravity="center_vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="0dp"
android:layout_height="200dip"
android:layout_weight="0.6"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.4"
android:orientation="vertical" >
<TextView
android:id="#+id/TextView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="+" />
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:clickable="false" >
<requestFocus />
</EditText>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="-" />
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />
</LinearLayout>
</ScrollView>

Categories

Resources