I have a structure where a search view resides at the top and a frame layout does below. SearchAFragment is the initial fragment of frame layout.
I am managing frame layout like;
search_box.setOnSearchClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
changeFragment(new SearchBFragment(), id);
}
});
search_box.setOnCloseListener(new SearchView.OnCloseListener() {
#Override
public boolean onClose() {
changeFragment(new SearchAFragment(), id);
//search_box.clearFocus();
return false;
}
});
I am clicking search view and then searching things and everything is all right. After searching, I click close button of search view to switch to SearchAFragment and then the problem occurs. It switches SearchAFragment but when I try to open search view and search things again, SearchBFragment never comes to front. How can I handle this problem?
Related
How do I capture the click on the AutoCompleteTextView arrow.
OnClick works for the rest of the component, but it doesn't work when you specifically click the arrow.
It took a while, but I found the solution.
The event is in the parent of the AutoCompleteTextView.
XML:
XML
Solution:
public com.google.android.material.textfield.TextInputLayout txtGleba;
...
txtGleba = findViewById(R.id.txtGleba);
txtGleba.setEndIconOnClickListener (new View.OnClickListener() {
#Override
public void onClick(View v) {
}
});
I implemented a RecyclerView which is populating some records
It is populating appointments and appointments have approved and not approved status.
I implemented an approved button so that onclick the approved status for that appointment is updated on the database and also icon and text is changed of that particular displayed record.
but for some reason in onclick when i am updating the text and icon it is not changing dynamically, but the request to database is working since i can see the change in database, and when i reload the whole data set it shows the changes appropriately.
Here is the code
#Override
public void onBindViewHolder(final AppointmentsHolder holder, final int position) {
final AppointmentObject appointment = appointmentList.get(position);
//binding the data with the viewholder views
holder.patient_name.setText(appointment.patient_name);
holder.app_date.setText(appointment.appointment_date);
if (appointment.descr.length() > 30){
holder.app_descr.setText(String.valueOf(appointment.descr.substring(0,30)));
}else {
holder.app_descr.setText(String.valueOf(appointment.descr));
}
if (appointment.approved_status.equals("0")){
holder.approved_status.setTextColor(Color.RED);
holder.approved_status.setText("Not Approved");
holder.app_pa_approve.setImageResource(R.mipmap.approveicon);
}else {
holder.app_pa_approve.setImageResource(R.mipmap.approvedicon);
holder.approved_status.setTextColor(Color.GREEN);
holder.approved_status.setText("Approved");
}
holder.app_pa_relative.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mOnClickListenr.clicked_On_appointment(appointment);
}
});
holder.app_pa_approve.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
holder.approved_status.setTextColor(Color.GREEN);
holder.approved_status.setText("Approved");
holder.app_pa_approve.setImageResource(R.mipmap.approvedicon);
notifyDataSetChanged();
mOnClickListenr.aprove_appointment(appointment, position);
}
});
}
Here is the onBindViewHolder where i am trying to change the data dynamically onclick.
mOnclickListiner.aprove.appointment is just a listiner which i am implementing in the activity to pass data to activity
public interface OnClickListener{
public void clicked_On_appointment(AppointmentObject appointment);
public void aprove_appointment(AppointmentObject appointment, int position);
}
The mOnClickListenr.aprove_appointment(appointment, position); inside the OnClcick is executing so i know that the setText and setImageResource are executing as well but for some reason change in not showing in the view.
As you can see i am using notifyDataSetChanged(); properly.
What might be the cause of this behavior ?
As you can see even when i am clicking on the imageButton no dynamic change
only when i reload the arraylist it shows the changed, which means change is happening in database and onclick is executing
You have to set approved on the appointment When you call notifiyDataSetChanged it is rebinding all the views and the appointment is still marked unapproved
holder.app_pa_approve.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
appointment.setApprovedStatus(1);
holder.approved_status.setTextColor(Color.GREEN);
holder.approved_status.setText("Approved");
holder.app_pa_approve.setImageResource(R.mipmap.approvedicon);
notifyDataSetChanged();
mOnClickListenr.aprove_appointment(appointment, position);
}
});
I'm using ViewPager as my main navigation in app. I'm using ActionBar, as well. What I want to achieve is that when user clicks search button in ActionBar I want to have blurred background. So my approach is to take a screenshot, blur it, set as ImageView and display as an overlay over the whole view. And it works. But problem is that actually when I first open search it displays proper screenshot. Then I turn overlay off, change page in ViewPager, click search again and ... I can see the previous screenshot- not new one with new page on it. Here are my snippets of code:
show and hide overlay on search click (I'm passing R.id.container view which is parent id of my content view, menuOverlay is my ImageView referenced from layout)
Here's my method that takes screenshot and makes it blurry
// Ad. 1
item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
#Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
if(menuItem.getItemId() == R.id.action_search) {
menuOverlay.setImageBitmap(Utils.takeSnapshot(findViewById(R.id.container)));
menuOverlay.setVisibility(View.VISIBLE);
}
return true;
}
#Override
public boolean onMenuItemActionCollapse(MenuItem menuItem) {
if(menuItem.getItemId() == R.id.action_search) {
menuOverlay.setVisibility(View.GONE);
}
return true;
}
});
// Ad. 2
public static Bitmap takeSnapshot(View v) {
v.setDrawingCacheEnabled(true);
v.buildDrawingCache();
Bitmap bm = v.getDrawingCache();
Bitmap scaled = Bitmap.createScaledBitmap(bm, bm.getWidth()/5, bm.getHeight()/5, false);
return Utils.fastblur(scaled, 5);
}
I;m using fast blur algorithm found somewhere here on StackOverflow which is quite fast.
Where's the problem? Why it happens?
ok, I found the answer. if you want to always have "fresh" screenshot you need to destroy cache after all operations:
v.setDrawingCacheEnabled(false);
I found a workaround to actually enable the ActionBar home button on the nested PreferenceScreen... however it doesn't call OnOptionsItemSelected in my PreferenceActivity. Anyone know a way to actually use the home button on a nested PreferenceScreen?
Modification of post 35 here:
http://code.google.com/p/android/issues/detail?id=4611
#Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
{
super.onPreferenceTreeClick(preferenceScreen, preference);
if (preference!=null)
if (preference instanceof PreferenceScreen)
if (((PreferenceScreen)preference).getDialog()!=null)
((PreferenceScreen)preference).getDialog().getActionBar().setHomeButtonEnabled(true);
return false;
}
I had this problem recently and this is how I solved it. Firstly to access the PreferenceScreen I use the exact same method you mentioned above.
#Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
super.onPreferenceTreeClick(preferenceScreen, preference);
// If the user has clicked on a preference screen, set up the action bar
if (preference instanceof PreferenceScreen) {
initializeActionBar((PreferenceScreen) preference);
}
return false;
}
From here I looked into what a PreferenceScreen is, and I was saddened to find out it is just wrapper of a Dialog. Moving forward, I then set the actionbar display options and attempt find the home button area. This unfortunately wasn't too easy to get, but with the help of the hierarchy viewer I managed to gain access by finding the home icon and then its parent views. Once we have access to the containing LinearLayout, we can attach an onClickListener where we dismiss the PreferenceScreen's dialog, which calls PreferenceScreen's onDismissListener and returns us to the previous screen.
/** Sets up the action bar for an {#link PreferenceScreen} */
public static void initializeActionBar(PreferenceScreen preferenceScreen) {
final Dialog dialog = preferenceScreen.getDialog();
if (dialog != null) {
// Inialize the action bar
dialog.getActionBar().setDisplayHomeAsUpEnabled(true);
// Apply custom home button area click listener to close the PreferenceScreen because PreferenceScreens are dialogs which swallow
// events instead of passing to the activity
// Related Issue: https://code.google.com/p/android/issues/detail?id=4611
View homeBtn = dialog.findViewById(android.R.id.home);
if (homeBtn != null) {
OnClickListener dismissDialogClickListener = new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
};
// Prepare yourselves for some hacky programming
ViewParent homeBtnContainer = homeBtn.getParent();
// The home button is an ImageView inside a FrameLayout
if (homeBtnContainer instanceof FrameLayout) {
ViewGroup containerParent = (ViewGroup) homeBtnContainer.getParent();
if (containerParent instanceof LinearLayout) {
// This view also contains the title text, set the whole view as clickable
((LinearLayout) containerParent).setOnClickListener(dismissDialogClickListener);
} else {
// Just set it on the home button
((FrameLayout) homeBtnContainer).setOnClickListener(dismissDialogClickListener);
}
} else {
// The 'If all else fails' default case
homeBtn.setOnClickListener(dismissDialogClickListener);
}
}
}
}
I am going nuts over this.
I did not find any working solution (tried a few from stackoverflow)
Scenario (this is an actual screenshot what is already done):
I have a Activity that has a View as his Attribute.
This view adds another view via View.addView(myView).
I now want to add a Button to myView (to be specific: after MotionEvent.ACTION_UP the button should appear in the right lower corner (this will start the robot to drive the track))
Here is a shortcut of my code:
public class ModeRouting extends View {
public ModeRouting(Context context) {
super(context);
Button asuroStartButton = new Button(context) //does not work
}
#Override
public boolean onTouchEvent(MotionEvent event) {
int actionevent = event.getAction();
if (actionevent == MotionEvent.ACTION_UP
|| actionevent == MotionEvent.ACTION_CANCEL) {
asuroStartButton.visible=true;
view.add(asuroStartButton);
}
return true;
}
}
and my Activity:
//in constructor
contentView = (FrameLayout) findViewById(R.id.content);
onClickListenerFacade(routingMode, route);
//this removes all views from stack and places the new one on the view
private void onClickListenerFacade(View v, final View target) {
v.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
contentView.removeAllViews();
contentView.setBackgroundColor(0xff000000);
contentView.addView(target);
modeSelectorAnimation();
}
});
}
I tried to create a button in my mainactivity.xml and instantiate in my mainactivity.
I am missing some point in here but i am not sure which.
Since my view is purely dynamic (no layout.xml) i dont think i should use a layout.xml (maybe thats my mind-blockage) but instead set the button attributes dynamically too.
Any hint is appreciated!
You want to extend ViewGroup rather than just a View (LinearLayout, RelativeLayout, FrameLayout, etc) - they handle child views for you.
I think maybe you need to refresh the whole view/activity. Try to do this in the onResume methode, maybe this helps. But as you don't use a layout.xml, I'm not sure if this helps you much..
#Override
protected void onResume(){
super.onResume();
setContentView(R.layout.activity_main);
}