How to pass data from bottom sheet to a fragment in android? - android

I am trying to pass values from a bottom sheet which contains some TextViews to a fragment.
My fragment contains an EditText field and a Floating action button.When the user clicks on the floating action button, the bottom sheet shows up which has a number of TextViews, when the user clicks on any of the textViews on the bottom sheet, the value or the string of that TextView should be displayed in the editText field of the fragment and the bottom sheet should be dismissed.
I have tried implementing the onClickListener inside the setOnShowListener method but it doesn't seem to work.
Here is my code:
Fragment_TextPropert1_EditText.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.sumitroy.TextProperty1_EditText"
>
<android.support.v7.widget.CardView 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:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_below="#+id/view"
android:layout_marginTop="10dp"
app:cardUseCompatPadding="true"
android:id="#+id/view2">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:hint="Enter Your Comments Here.."
android:id="#+id/userText"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</android.support.v7.widget.CardView>
<ImageButton
android:layout_width="65dp"
android:layout_height="65dp"
android:id="#+id/example_Ads"
android:background="#drawable/oval"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="20dp"
android:layout_marginRight="15dp"
android:src="#drawable/double_plus"
/>
</RelativeLayout>
TextProperty1_bottomsheet.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RelativeLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<android.support.v7.widget.CardView 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:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="15dp"
app:cardUseCompatPadding="true"
android:id="#+id/view1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment1"
android:id="#+id/example_Ad1"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
android:layout_alignParentStart="true" />
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView 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:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="10dp"
app:cardUseCompatPadding="true"
android:layout_below="#+id/view1"
android:id="#+id/view2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment 2"
android:id="#+id/example_Ad2"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView 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:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="15dp"
app:cardUseCompatPadding="true"
android:id="#+id/view3"
android:layout_below="#+id/view2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment 3 "
android:id="#+id/example_Ad3"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView 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:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="15dp"
app:cardUseCompatPadding="true"
android:id="#+id/view4"
android:layout_below="#+id/view3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment 4 "
android:id="#+id/example_Ad4"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
/>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView 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:orientation="horizontal"
app:cardCornerRadius="15dp"
android:padding="15dp"
android:layout_marginTop="15dp"
app:cardUseCompatPadding="true"
android:id="#+id/view5"
android:layout_below="#+id/view4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Comment 5 "
android:id="#+id/example_Ad5"
android:padding="10dp"
android:textStyle="bold"
android:textSize="14sp"
android:layout_below="#+id/view"
/>
</android.support.v7.widget.CardView>
</RelativeLayout>
</ScrollView>
TextProperty1_EditText.java
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomSheetBehavior;
import android.support.design.widget.BottomSheetDialog;
import android.support.v4.app.Fragment;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
/**
* A simple {#link Fragment} subclass.
*/
public class TextProperty1_EditText extends Fragment {
View bottomSheetView;
EditText editText1;
TextView t1;
BottomSheetDialog bottomSheetDialog;
BottomSheetBehavior bottomSheetBehavior;
ImageButton floatButton;
RelativeLayout backgroundLayout;
public TextProperty1_EditText() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View rootview= inflater.inflate(R.layout.fragment_text_property1__edit_text, container, false);
editText1=(EditText) rootview.findViewById(R.id.userText);
floatButton=(ImageButton)rootview.findViewById(R.id.example_Ads);
floatButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//Toast.makeText(v.getContext(),"Floating Button Works",Toast.LENGTH_SHORT).show();
bottomSheetView=getActivity().getLayoutInflater().inflate(R.layout.textproperty1_bottomsheet,null);
bottomSheetDialog=new BottomSheetDialog(rootview.getContext());
bottomSheetDialog.setContentView(bottomSheetView);
bottomSheetBehavior=BottomSheetBehavior.from((View) bottomSheetView.getParent());
bottomSheetDialog.show();
bottomSheetDialog.setOnShowListener(new DialogInterface.OnShowListener() {
#Override
public void onShow(DialogInterface dialog) {
t1=(TextView)bottomSheetView.findViewById(R.id.example_Ad1);
t1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String take1=t1.getText().toString();
//Toast.makeText(bottomSheetView.getContext(),"Floating Button Works",Toast.LENGTH_SHORT).show();
editText1.setText(take1);
bottomSheetDialog.dismiss();
}
});
}
});
bottomSheetDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
#Override
public void onDismiss(DialogInterface dialog) {
}
});
bottomSheetDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
#Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
//Toast.makeText(bottomSheetView.getContext(),"Floating Button Works",Toast.LENGTH_SHORT).show();
return false;
}
});
}
});
return rootview;
}
}

As a simple solution you may use LocalBroadcastManager.
public static final String SOME_INTENT_FILTER_NAME = "SOME_INTENT_FILTER_NAME";
In your fragment:
private BroadcastReceiver someBroadcastReceiver = new BroadcastReceiver() {
#Override
public void onReceive(Context context, Intent intent) {
//TODO extract extras from intent
}
};
#Override
public void onResume() {
super.onResume();
LocalBroadcastManager.getInstance(getContext()).registerReceiver(someBroadcastReceiver,
new IntentFilter(SOME_INTENT_FILTER_NAME));
}
#Override
public void onPause() {
LocalBroadcastManager.getInstance(getContext()).unregisterReceiver(someBroadcastReceiver);
super.onPause();
}
In your bottomsheet:
Intent someIntent = new Intent(SOME_INTENT_FILTER_NAME);
//TODO put extras to your intent
LocalBroadcastManager.getInstance(context).sendBroadcast(someIntent);

Related

In Android, Is it possible to make Text Tag separation in editext Like Stack overflow (see the image)?

I want to create this kind of separation between commas(,)? like StackOverflow Tags
Try this:
In MainActivity.java
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.SwitchCompat;
import android.widget.CompoundButton;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import me.originqiu.library.EditTag;
public class MainActivity extends AppCompatActivity
implements SwitchCompat.OnCheckedChangeListener {
private EditTag editTagView;
private SwitchCompat statusSwitchView;
private List<String> tagStrings = new ArrayList<>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTagView = (EditTag) findViewById(R.id.edit_tag_view);
statusSwitchView = (SwitchCompat) findViewById(R.id.status_switch);
statusSwitchView.setOnCheckedChangeListener(this);
for (int i = 0; i < 10; i++) {
tagStrings.add("test" + i);
}
//Set tag add callback before set tag list
editTagView.setTagAddCallBack(new EditTag.TagAddCallback() {
#Override
public boolean onTagAdd(String tagValue) {
if ("test1".equals(tagValue)) {
return false;
} else {
return true;
}
}
});
editTagView.setTagDeletedCallback(new EditTag.TagDeletedCallback() {
#Override
public void onTagDelete(String deletedTagValue) {
Toast.makeText(MainActivity.this, deletedTagValue, Toast.LENGTH_SHORT).show();
}
});
editTagView.setTagList(tagStrings);
editTagView.addTag("hello world!");
editTagView.removeTag("test3");
}
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
editTagView.setEditable(isChecked);
}
}
In activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="me.originqiu.edittag.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<me.originqiu.library.EditTag
android:id="#+id/edit_tag_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:input_layout="#layout/view_sample_input_tag"
app:tag_layout="#layout/view_sample_tag" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_marginTop="4dp"
android:background="#color/colorAccent" />
</LinearLayout>
<android.support.v7.widget.SwitchCompat
android:id="#+id/status_switch"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checked="true"
android:padding="16dp"
android:text="open editable status" />
</LinearLayout>
In view_sample_input_tag.xml
<?xml version="1.0" encoding="utf-8"?>
<me.originqiu.library.MEditText
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:minWidth="56dp"
android:drawablePadding="2dp"
android:paddingBottom="4dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="4dp"
android:singleLine="true"
android:maxEms="30"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:hint="Add Tag "
android:imeOptions="actionDone"
android:textColor="#color/dark_clr"
android:textSize="14sp"/>
In view_sample_tag.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginTop="2dp"
android:background="#drawable/bg_sample_tag"
android:gravity="center"
android:paddingBottom="2dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="2dp"
android:textColor="#fff"
android:textSize="14sp"
android:textStyle="bold" />
See here for more details: https://github.com/qiugang/EditTag/blob/master/sample/src/main/res/layout/view_sample_tag.xml

Value Of EditText In android Get changed after Typing to initial value

Value is automatically changed after user started typing in EditText.Value is automatically changed with initial value.
Please Help me what is causing this issue
This layout is USed for adapter layout the complete layout file and adapter code is given below here is EditTextbox part that is causing issue
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<TextView
style="#style/booking_heading"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Enter Amount" />
<EditText
android:layout_width="0dp"
android:editable="true"
android:inputType="number"
android:layout_weight="1"
android:background="#fff"
android:padding="8dp"
android:text="00"
android:layout_height="match_parent"
android:id="#+id/booking_price" />
</LinearLayout>
Code Of My Adapter class is
package com.visionprecis.vikrant;
import android.content.Context;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.visionprecis.vikrant.DriverService.Booking;
import com.visionprecis.vikrant.LocationProvider.TrackingActivity;
import com.visionprecis.vikrant.StaticData.StaticInfo;
import java.util.ArrayList;
import java.util.HashMap;
public class BookingArrayAdapter extends ArrayAdapter {
ArrayList<Booking> bookingArrayList;
Context context;
public BookingArrayAdapter(Context context, int resource,ArrayList<Booking> objects) {
super(context, resource, objects);
this.context=context;
this.bookingArrayList=objects;
}
#Override
public View getView(int position, View convertView,ViewGroup parent) {
LayoutInflater inflater=(LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
View view=inflater.inflate(R.layout.single_booking_layout,null);
final Booking booking=bookingArrayList.get(position);
TextView orgin=view.findViewById(R.id.booking_origin);
TextView destination=view.findViewById(R.id.booking_destination);
TextView status=view.findViewById(R.id.booking_status);
final EditText price=view.findViewById(R.id.booking_price);
Button trackbtn=view.findViewById(R.id.booking_track_btn);
Button cancel=view.findViewById(R.id.booking_cancel);
Button confirm=view.findViewById(R.id.booking_confirm);
orgin.setText(booking.getOrigin().getAdress());
destination.setText(booking.getDestination().getAdress());
status.setText(booking.getStatus());
price.setText(booking.getPrice());
if(booking.getStatus().equals(StaticInfo.RIDE_REQUESTED)){
confirm.setText("Send Amount");
confirm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sendbidamound(booking,price.getText().toString());
Log.i(StaticInfo.TAG,"Price kis "+price.getText());
}
});
}else if(booking.getStatus().equals(StaticInfo.RIDE_BID_PROVIDED)){
// confirm.setText("Confirmed");
confirm.setText("Send Amount");
confirm.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
sendbidamound(booking,price.getText().toString());
Log.i(StaticInfo.TAG,"Price kis "+price.getText());
}
});
}
trackbtn.setEnabled(true);
trackbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
trackuser(booking.getUserid());
}
});
cancel.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
oncancelpressed(booking);
}
});
return view;
}
private void trackuser(String userid) {
Intent intent=new Intent(context,TrackingActivity.class);
intent.putExtra("userid",userid);
context.startActivity(intent);
}
private void oncancelpressed(Booking booking) {
DatabaseReference reference=FirebaseDatabase.getInstance().getReference().child(StaticInfo.USER_BOOKING_REQUEST_TABLE)
.child(booking.getUserid())
.child(booking.getBookingid());
reference.child("status").setValue(StaticInfo.RIDE_CANCELED).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
Toast.makeText(context,"Booking caceled Succcessfully",Toast.LENGTH_LONG).show();
}
});
}
private void sendbidamound(final Booking booking, final String price) {
if(validateprice()){
DatabaseReference userreference=FirebaseDatabase.getInstance().getReference().child(StaticInfo.USER_BOOKING_REQUEST_TABLE)
.child(booking.getUserid())
.child(booking.getBookingid());
HashMap<String,Object> updatevalue=new HashMap<>();
updatevalue.put("status",StaticInfo.RIDE_BID_PROVIDED);
updatevalue.put("price",price);
userreference.updateChildren(updatevalue).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
DatabaseReference driverreference=FirebaseDatabase.getInstance().getReference().child(StaticInfo.DRIVER_BOOKING_REQUEST_TABLE)
.child(booking.getDriverid())
.child(booking.getBookingid());
HashMap<String,Object> updatechild=new HashMap<>();
updatechild.put("status",StaticInfo.RIDE_BID_PROVIDED);
updatechild.put("price",price);
driverreference.updateChildren(updatechild).addOnCompleteListener(new OnCompleteListener<Void>() {
#Override
public void onComplete(#NonNull Task<Void> task) {
Toast.makeText(context,"Bid amount Placed Succcesfully Awaiting User Confirmation And You Will Be Notified back",Toast.LENGTH_LONG).show();
context.startActivity(new Intent(context,MainActivity.class));
}
});
}
});
}
}
private boolean validateprice() {
return true;
}
}
Complete Layout Of The adapter is
<!-- Begning Of child Layout horizental-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<TextView
style="#style/booking_heading"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Origin" />
<TextView
style="#style/booking_value"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/booking_origin"
android:text="Shimla Himachal Pradesh India" />
</LinearLayout>
<!-- End Of child Layout horizental-->
<!-- Begning Of child Layout horizental-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<TextView
style="#style/booking_heading"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Destination" />
<TextView
style="#style/booking_value"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/booking_destination"
android:text="Shimla Himachal Pradesh India" />
</LinearLayout>
<!-- End Of child Layout horizental-->
<!-- Begning Of child Layout horizental-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<TextView
style="#style/booking_heading"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Ride Status" />
<TextView
style="#style/booking_value"
android:layout_width="0dp"
android:layout_height="match_parent"
android:id="#+id/booking_status"
android:text=" " />
</LinearLayout>
<!-- End Of child Layout horizental-->
<!-- Begning Of child Layout horizental-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<TextView
style="#style/booking_heading"
android:layout_width="0dp"
android:layout_height="match_parent"
android:text="Enter Amount" />
<EditText
android:layout_width="0dp"
android:editable="true"
android:inputType="number"
android:layout_weight="1"
android:background="#fff"
android:padding="8dp"
android:layout_height="match_parent"
android:id="#+id/booking_price" />
</LinearLayout>
<!-- End Of child Layout horizental-->
<!-- Begning Of child Layout horizental-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<Button
style="#style/booking_heading"
android:textColor="#fff"
android:layout_width="0dp"
android:layout_height="match_parent"
android:background="#273e70"
android:gravity="center"
android:textStyle="bold"
android:textAlignment="center"
android:text="Cancel"
android:layout_margin="4dp"
android:id="#+id/booking_cancel"/>
<Button
style="#style/booking_heading"
android:layout_width="0dp"
android:textColor="#fff"
android:layout_height="match_parent"
android:background="#273e70"
android:gravity="center"
android:textStyle="bold"
android:textAlignment="center"
android:text="Confirm"
android:layout_margin="4dp"
android:id="#+id/booking_confirm" />
</LinearLayout>
<!-- End Of child Layout horizental-->
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Track User"
android:layout_marginTop="8dp"
android:textSize="22sp"
android:enabled="false"
android:id="#+id/booking_track_btn"
/>
</LinearLayout>
<!-- End Of main Layout vertical-->
</android.support.constraint.ConstraintLayout>
The Activity layout is
<?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"
tools:context=".RequestedRidesListActivity">
<ListView
android:layout_width="match_parent"
android:id="#+id/booking_list_view"
android:layout_height="wrap_content">
</ListView>
</android.support.constraint.ConstraintLayout>
Layout of the File is
Have you set textwatcher to your edit text ?

BottomSheetDialog setOnClickListener not firing

I am having issues firing the onClick method of the setOnClickListener of the BottomSheetDialog menu.
This is the xml fragment layout or the BottomSheetDialog
<?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"
android:id="#+id/fragment_grocery_menu_bottom"
android:layout_width="match_parent"
android:layout_height="180dp"
android:background="#ffffff"
android:orientation="vertical"
app:layout_behavior="android.support.design.widget.BottomSheetBehavior">
<LinearLayout
android:id="#+id/fragment_grocery_bottom_sheet_search"
android:layout_width="match_parent"
android:layout_height="60dp"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
app:srcCompat="#drawable/ic_search_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Search Item" />
</LinearLayout>
<LinearLayout
android:id="#+id/fragment_grocery_bottom_sheet_got"
android:layout_width="match_parent"
android:layout_height="60dp"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
app:srcCompat="#drawable/ic_done_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Mark Item as Gotten" />
</LinearLayout>
<LinearLayout
android:id="#+id/fragment_grocery_bottom_sheet_delete"
android:layout_width="match_parent"
android:layout_height="60dp"
android:clickable="true"
android:descendantFocusability="blocksDescendants"
android:focusable="true"
android:foreground="?android:attr/selectableItemBackground"
android:orientation="horizontal"
android:padding="16dp">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
app:srcCompat="#drawable/ic_delete_black_24dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="16dp"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="Remove Item" />
</LinearLayout>
</LinearLayout
The java class code for the Fragment is below. So for example if I click on the got menu (LinearLayout) the onClick method is not fired and the Log is not written also the SnackBar is not displayed
import android.os.Bundle;
import android.app.Fragment;
import android.support.design.widget.Snackbar;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
public class GroceryItemsMenu extends Fragment {
public GroceryItemsMenu() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View view = inflater.inflate(R.layout.fragment_grocery_items_menu, container, false);
LinearLayout delete = (LinearLayout) view.findViewById(R.id.fragment_grocery_bottom_sheet_delete);
LinearLayout got = (LinearLayout) view.findViewById(R.id.fragment_grocery_bottom_sheet_got);
LinearLayout search = (LinearLayout) view.findViewById(R.id.fragment_grocery_bottom_sheet_search);
search.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
got.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("Item: ", "Got");
Snackbar.make(getActivity().findViewById(R.id.groceryItemsCoordinatorLayout), "Got this Item", Snackbar.LENGTH_SHORT)
.setAction("Undo", new View.OnClickListener() {
#Override
public void onClick(View v) {
}
}).show();
}
});
delete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Delete code here;
}
});
return view;
}
}
What am I doing wrong?
use : public class GroceryItemsMenu extends Fragment implements View.OnClickListener

Android - Add subview after animation

I'm trying to add a subview below another view after an animation. anyone have any idea what i'm doing wrong?
this.animate().translationY(newY - 170).setDuration(500).withEndAction(new Runnable() {
#Override
public void run() {
clearAnimation();
RouteBreakDownLayout routeBreakDownLayout = new RouteBreakDownLayout(mContext);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, R.id.selected_route_layout);
routeBreakDownLayout.setLayoutParams(p);
addView(routeBreakDownLayout);
}
}).start();
Here is the XML for the layout. I have a scrollview embeded which will hold the content that needs to be animated in.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/selected_route_layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/selected_route_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:background="#FFF"
android:gravity="bottom"
android:padding="10dip">
<TextView
android:id="#+id/time_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#1D1C18" />
<TextView
android:id="#+id/eta_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/time_label"
android:layout_toEndOf="#+id/time_label"
android:layout_toRightOf="#+id/time_label"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#7EC82F" />
<LinearLayout
android:id="#+id/route_breakdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/time_label"
android:layout_centerVertical="true"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:gravity="center_vertical"
android:orientation="horizontal" />
<TextView
android:id="#+id/via_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/route_breakdown"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#BDBDBD" />
<ImageButton
android:id="#+id/arrow_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#null"
android:padding="15dip"
android:src="#drawable/transit_symbol_up_arrow" />
</RelativeLayout>
<ScrollView
android:layout_below="#+id/selected_route_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:showDividers="middle"
android:divider="?android:dividerHorizontal"
android:animateLayoutChanges="true"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</ScrollView>
</RelativeLayout>
What goes wrong for you in your code-snippet?
Here's working example I came up with:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/containerRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/headerView"
android:background="#00FF00"
android:layout_width="match_parent"
android:layout_height="25dp"/>
<View
android:id="#+id/detailsView"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="40dp"
android:clickable="true"
android:background="#FF0000"/>
</RelativeLayout>
And MainActivity is
package klogi.com.animationstestapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View detailsView = findViewById(R.id.detailsView);
final View headerView = findViewById(R.id.headerView);
final RelativeLayout container = (RelativeLayout)findViewById(R.id.containerRelativeLayout);
container.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
detailsView.animate().translationY(-detailsView.getY()).setDuration(500).withEndAction(new Runnable() {
#Override
public void run() {
Button additionalButton = new Button(MainActivity.this);
additionalButton.setText("Additional button");
RelativeLayout.LayoutParams additionalButtonParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
additionalButtonParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
additionalButton.setLayoutParams(additionalButtonParams);
container.addView(additionalButton);
}
}).start();
headerView.animate().translationY(detailsView.getHeight()).setDuration(500).start();
}
});
}
}
It works just as expected.
Have you tried to add your control(RouteBreakDownLayout) without animation? Does it work? It can be something like control is actually adding, but it's out of the viewport, etc. - so far, I can just guessing.

Not-clipped childview of RelativeLayout is not clickable

I have the following activity. It is an simplification of a draggable map. The problem is that mytext2 is not clickable, even if it is visible. Can anybody tell me how to make it clickable? And for some reason the inner-RelativeLayout gets not bigger than screen size, even when i set this high dp.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000ff"
android:clipChildren="false"
tools:context="${relativePackage}.${activityClass}" >
<RelativeLayout
android:layout_width="100000dp"
android:layout_height="100000dp"
android:background="#00ff00"
android:translationX="-100dp" >
<TextView
android:id="#+id/mytext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:text="#string/hello_world"
android:translationX="400dp"
android:translationY="100dp" />
<TextView
android:id="#+id/mytext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:text="#string/hello_world"
android:translationX="200dp"
android:translationY="100dp" />
</RelativeLayout>
</RelativeLayout>
class
package com.example.relativatest;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.mytext1).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("HELLO!1");
}
});
findViewById(R.id.mytext2).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
System.out.println("HELLO!2");
}
});
}
}
Use this code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000ff"
android:clipChildren="false"
tools:context="${relativePackage}.${activityClass}" >
<RelativeLayout
android:layout_width="100000dp"
android:layout_height="100000dp"
android:background="#00ff00"
android:translationX="-100dp" >
<TextView
android:id="#+id/mytext1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:text="#string/hello_world"
android:focusable="true"
android:padding="20dp"
android:translationX="400dp"
android:clickable="true"
android:translationY="100dp" />
<TextView
android:id="#+id/mytext2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff0000"
android:text="#string/hello_world"
android:translationX="200dp"
android:clickable="true"
android:padding="20dp"
android:focusable="true"
android:translationY="100dp" />
</RelativeLayout>
</RelativeLayout>

Categories

Resources