Android - Customizing Dialog using an Xml Layout - java

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>

Related

Best way to make CardView hide

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

How to create a popup window programmatically in Android

I have made Activity which will popup on click of button. I have to add listener on Image Button. I have made the design in XMl but I want to design programmatically.
This is my image of xml design.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PopupMenu">
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="4"
android:orientation="horizontal"
android:rowCount="1">
<ImageView
android:id="#+id/imageOnlineIcon"
android:layout_width="28dp"
android:layout_height="28dp"
app:srcCompat="#drawable/olnine_user"
android:layout_row="0"
android:layout_column="0" />
<TextView
android:id="#+id/textViewUserName"
android:layout_width="201dp"
android:layout_height="44dp"
android:text="Shyam"
android:textAlignment="center"
android:textSize="22sp" />
<ImageButton
android:id="#+id/imageVideoIcon"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#drawable/videonline" />
<ImageButton
android:id="#+id/imageMuteIcon"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#drawable/muted" />
</GridLayout>
<View style="#style/Divider"/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="4"
android:orientation="horizontal"
android:rowCount="1">
<ImageView
android:id="#+id/imageOnlineIcon1"
android:layout_width="28dp"
android:layout_height="28dp"
app:srcCompat="#drawable/olnine_user" />
<TextView
android:id="#+id/textViewUserName1"
android:layout_width="201dp"
android:layout_height="44dp"
android:text="Samir"
android:textAlignment="center"
android:textSize="22sp" />
<ImageButton
android:id="#+id/imageVideoIcon1"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#drawable/videonline" />
<ImageButton
android:id="#+id/imageMuteIcon1"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#drawable/muted" />
</GridLayout>
<View style="#style/Divider"/>
<GridLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="4"
android:orientation="horizontal"
android:rowCount="1">
<ImageView
android:id="#+id/imageOnlineIcon2"
android:layout_width="28dp"
android:layout_height="28dp"
app:srcCompat="#drawable/olnine_user" />
<TextView
android:id="#+id/textViewUserName2"
android:layout_width="201dp"
android:layout_height="44dp"
android:text="Vivek"
android:textAlignment="center"
android:textSize="22sp" />
<ImageButton
android:id="#+id/imageVideoIcon2"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#drawable/videonline" />
<ImageButton
android:id="#+id/imageMuteIcon2"
android:layout_width="36dp"
android:layout_height="36dp"
android:background="#drawable/muted" />
</GridLayout>
<View style="#style/Divider"/>
</LinearLayout>
I have to create the same design in java programatically. And Add the listener in Image Button so that i can handle the button.
I think, you told about AlertDialog
You can try to write this method:
public void entre () {
AlertDialog.Builder alert = new AlertDialog.Builder(MainActivity.this);
alert.setTitle("Something");
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//what you need to do after click "OK"
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//what you need to do after click "Cancel"
}
});
alert.show();
}
And add it in onClickListner:
public void onButtonClick(View view) {
entre ();
}
You will get popup window with title "Something" and with two buttons: "Ok" and "Cancel"

How to access an item inside layout dialog?

Dialog was designed by the XML layer and named layout inside it contains a collection of spinner and TextView and some buttons are called from main activity class now I want to know which one of the spinner inside the
D1 () function
I want to define the elements within the layer layout , How do I do that?
//layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="260dp"
android:layout_height="200dp"
android:orientation="vertical"
android:background="#f71717">
<LinearLayout
android:id="#+id/l_layout"
android:paddingTop="10dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
tools:ignore="ObsoleteLayoutParam">
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textColor="#ffffff"
android:text="وقت التسليم"
android:textSize="20dp"
tools:ignore="HardcodedText,SpUsage" />
<Spinner
android:id="#+id/tex"
android:layout_width="172dp"
android:paddingRight="40dp"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:drawSelectorOnTop="true"
android:popupBackground="#c853d7"
style="#style/spinner_style"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry,SpUsage"
android:entries="#array/day_"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/rl"
android:layout_width="250dp"
android:layout_height="129dp"
android:layout_below="#+id/l_layout"
android:background="#f71717"
android:layout_marginTop="0dp"
tools:ignore="ObsoleteLayoutParam">
<TextView
android:id="#+id/text_h"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toStartOf="#+id/spinner_minutes2"
android:paddingLeft="10dp"
android:text="ساعة"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
<TextView
android:id="#+id/text_m"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/spinner_minutes2"
android:layout_alignBottom="#+id/spinner_minutes2"
android:layout_alignStart="#+id/button_holder"
android:paddingLeft="10dp"
android:text="دق"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
<TextView
android:id="#+id/text_pam"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:text="ص/م"
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry"
android:layout_marginEnd="12dp"
android:layout_alignBaseline="#+id/spinner_minutes"
android:layout_alignBottom="#+id/spinner_minutes"
android:layout_alignEnd="#+id/spinner_minutes3" />
<Spinner
android:id="#+id/spinner_minutes"
android:layout_width="85dip"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
style="#style/spinner_style"
android:layout_alignStart="#+id/spinner_minutes2"
android:entries="#array/fruits" />
<Spinner
android:id="#+id/spinner_minutes2"
android:layout_width="85dip"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner_minutes"
android:layout_marginStart="16dp"
style="#style/spinner_style"
android:layout_toEndOf="#+id/text_m"
android:entries="#array/fruits" />
<Spinner
android:id="#+id/spinner_minutes3"
android:layout_width="85dip"
android:layout_height="wrap_content"
style="#style/spinner_style"
android:paddingRight="20dp"
android:entries="#array/apm"
tools:ignore="RtlHardcoded,RtlSymmetry"
android:layout_alignBaseline="#+id/spinner_minutes2"
android:layout_alignBottom="#+id/spinner_minutes2"
android:layout_toEndOf="#+id/spinner_minutes" />
<TextView
android:id="#+id/text_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:visibility="gone" />
<LinearLayout
android:id="#+id/button_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/spinner_minutes"
android:layout_centerHorizontal="true"
android:paddingTop="10dp"
android:layout_marginTop="20dip">
<Button
android:id="#+id/button_set"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginLeft="10dip"
android:text="Set"
tools:ignore="ButtonStyle,HardcodedText,RtlHardcoded" />
<Button
android:id="#+id/button_cancel"
android:layout_width="100dip"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:layout_marginRight="10dip"
android:text="Cancel"
tools:ignore="ButtonOrder,ButtonStyle,HardcodedText,RtlHardcoded" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
// class: mainactivity
public class MainActivity extends AppCompatActivity {
Button buttonstartSetDialog;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonstartSetDialog = (Button)findViewById(R.id.startSetDialog);
buttonstartSetDialog.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick(View v) {
d1();
}});
}
public void d1(){
Dialog about_dlg = new Dialog(MainActivity.this);
about_dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
about_dlg.setContentView(R.layout.layout);
about_dlg.show();
//Spinner spinner = (Spinner) findViewById(R.id.spinner);
}
}
to access to Spinner in your layout :
public void d1(){
Dialog about_dlg = new Dialog(MainActivity.this);
about_dlg.requestWindowFeature(Window.FEATURE_NO_TITLE);
about_dlg.setContentView(R.layout.layout);
Spinner sp1 = about_dlg.findViewById(R.id.spinner_minutes);
Spinner sp1 = about_dlg.findViewById(R.id.spinner_minutes);
Spinner sp1 = about_dlg.findViewById(R.id.spinner_minutes);
about_dlg.show();
}

Hide and show when check box is checked

In my Activity A , I have checkbox, spinner and editText. If checkbox is checked, it will show editText and hide spinner and textView .Otherwise, it will show them.
public void addListenerOnChk() // for checkbox
{
checkBox2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(((CheckBox)v).isChecked())
{
typeProject.setVisibility(View.VISIBLE);
project.setVisibility(View.GONE);
ProjectName.setVisibility(View.GONE);
}
else
{
typeProject.setVisibility(View.GONE);
project.setVisibility(View.VISIBLE);
ProjectName.setVisibility(View.VISIBLE);
}
}
});
So this is my layout
Before checkbox is checked
After
If the checkbox did not checked, how can I move the progress bar below the checkbox(Currently it has a space for editText)?
If checkbox checked, how to move up the checkbox and hide the spinner and text ? Thanks.
Here my layout...sorry, it a bit long (but the things I want to change is id/ProjectName, id/checkbox2 and id/editText). id/checkbox2 and id/editText is in the last two paragraph.
<?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="wrap_content">
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/layout"
android:background="#mipmap/background_work_details">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/ProjectName"
android:padding="10dp"
android:text="Project/Service/Training"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="11dp" />
<Spinner
android:layout_width="322dp"
android:layout_height="41dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="15dp"
android:layout_y="47dp"
android:id="#+id/SpinnerProject"
android:spinnerMode="dropdown" />
<EditText
android:layout_width="339dp"
android:layout_height="156dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:paddingBottom="80dp"
android:layout_x="14dp"
android:layout_y="730dp"
android:id="#+id/editTextWorkDescription" />
<SeekBar
android:layout_width="206dp"
android:layout_height="wrap_content"
android:id="#+id/seekBarPercentage"
android:layout_x="30dp"
android:layout_y="189dp"
android:indeterminate="false" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView5"
android:padding="10dp"
android:text="Time In"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="16dp"
android:layout_y="225dp" />
<EditText
android:layout_width="80dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:focusableInTouchMode="false"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="86dp"
android:layout_y="225dp"
android:id="#+id/TimeIn" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView4"
android:padding="10dp"
android:text="Time Out"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="172dp"
android:layout_y="225dp" />
<EditText
android:layout_width="87dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:focusableInTouchMode="false"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="246dp"
android:layout_y="225dp"
android:id="#+id/TimeOut" />
<Button
android:layout_width="127dp"
android:layout_height="63dp"
android:text="save"
android:drawableRight="#mipmap/save"
android:id="#+id/save"
android:layout_x="217dp"
android:layout_y="891dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textProgress"
android:layout_x="257dp"
android:textColor="#color/red"
android:layout_y="194dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView7"
android:padding="10dp"
android:text="Travel From"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="262dp" />
<EditText
android:layout_width="223dp"
android:layout_height="85dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="14dp"
android:layout_y="300dp"
android:id="#+id/travelFrom" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView15"
android:padding="10dp"
android:text="Travel To"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="390dp" />
<EditText
android:layout_width="97dp"
android:layout_height="35dp"
android:layout_margin="10dp"
android:inputType="numberDecimal"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="15dp"
android:layout_x="255dp"
android:layout_y="470dp"
android:id="#+id/mileage" />
<EditText
android:layout_width="222dp"
android:layout_height="85dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:paddingLeft="20dp"
android:layout_x="14dp"
android:layout_y="423dp"
android:id="#+id/travelTo" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView16"
android:padding="10dp"
android:inputType="numberDecimal"
android:text="Hotel accomm"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="550dp"
android:allowUndo="true" />
<EditText
android:layout_width="92dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:inputType="numberDecimal"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:hint="RM"
android:paddingLeft="15dp"
android:layout_x="131dp"
android:layout_y="554dp"
android:id="#+id/hotel" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView17"
android:padding="10dp"
android:text="Toll"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="222dp"
android:layout_y="550dp" />
<EditText
android:layout_width="187dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:hint="RM"
android:inputType="numberDecimal"
android:paddingLeft="15dp"
android:layout_x="163dp"
android:layout_y="620dp"
android:id="#+id/business" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView18"
android:padding="10dp"
android:text="Business Expenses"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="620dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView19"
android:padding="10dp"
android:text="Mileage"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="268dp"
android:layout_y="430dp" />
<EditText
android:layout_width="92dp"
android:layout_height="34dp"
android:layout_margin="10dp"
android:background="#drawable/round_corner_square"
android:layout_weight="0.07"
android:hint="RM"
android:inputType="numberDecimal"
android:paddingLeft="15dp"
android:layout_x="263dp"
android:layout_y="554dp"
android:id="#+id/toll" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/textView20"
android:padding="10dp"
android:text="Work Description"
android:textColor="#color/peru"
android:layout_alignParentTop="true"
android:layout_x="14dp"
android:layout_y="683dp" />
<CheckBox
android:layout_width="112dp"
android:layout_height="53dp"
android:text="outstation"
android:id="#+id/checkBox"
android:textColor="#color/peru"
android:layout_x="232dp"
android:layout_y="662dp"
android:checked="false" />
<CheckBox
android:layout_width="112dp"
android:layout_height="45dp"
android:text="Others?"
android:id="#+id/checkBox2"
android:layout_x="24dp"
android:textColor="#color/peru"
android:layout_y="92dp"
android:checked="false" />
<EditText
android:layout_width="296dp"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:visibility="gone"
android:layout_x="27dp"
android:layout_y="133dp" />
</AbsoluteLayout>
</ScrollView>
Your problem is because you are using absolute_layout with layout_x and layout_y, so all views will be at your predefined positions of x and y, no matter what elements will you remove or what elements will you leave.
So, you have to change the layout parameters for the elements not just set it's visibility to VISIBLE or GONE, so the complete solution will be:
checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
typeProject.setVisibility(View.VISIBLE);
project.setVisibility(View.GONE);
ProjectName.setVisibility(View.GONE);
// now settings the new parameters
AbsoluteLayout.LayoutParams params = ((AbsoluteLayout.LayoutParams) typeProject.getLayoutParams());
params.x = 100; // the new value
params.y = 100; // the new value
typeProject.setLayoutParams(params);
}
else{
typeProject.setVisibility(View.GONE);
project.setVisibility(View.VISIBLE);
ProjectName.setVisibility(View.VISIBLE);
// use the same way here with 'project' and 'ProjectName'
}
});
Try with OnCheckedChangeListener:
checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if(isChecked){
typeProject.setVisibility(View.VISIBLE);
project.setVisibility(View.GONE);
ProjectName.setVisibility(View.GONE);
}
else{
typeProject.setVisibility(View.GONE);
project.setVisibility(View.VISIBLE);
ProjectName.setVisibility(View.VISIBLE);
}
});
You should use OnCheckedChangeListener, rather than OnClickListener
Do this
checkBox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
if(isChecked)
{
typeProject.setVisibility(View.VISIBLE);
project.setVisibility(View.GONE);
ProjectName.setVisibility(View.GONE);
}
else
{
typeProject.setVisibility(View.GONE);
project.setVisibility(View.VISIBLE);
ProjectName.setVisibility(View.VISIBLE);
}
}
});

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

Categories

Resources