I have 5 tabs and I want to call a function on it's longclick (onLongClick()).
The longclick is working but when I release the touch the click (onClick()) function is also called along with it.
Please anyone help me on this problem.
It happens. I also had the same problem while implementing OnItemClickListener and OnItemLongClickListener.
You can accomplish this with a vairable value:
int i=0;//declare this as outside all methods
void onClick(...)
{
if(i==0)
{//your code
}
else
{
i=0;
}
}
void OonLongClick(...)
{
//your code
i=1;
}
this won't stop onClick from being called on long click but will fulfill your purpose by not performing the task you want to perform only on onClick().
Another method is to call another activity using intent from method onLongClick(). This will stop onClick() from being called because the control will move to another activity.
Related
OK,i have ScrollView with multiply recyclerview-s.When user click on some item on my list that item expand itself with some more info. The problem is that although it does expand correctly, my root view(in my case ScrollView) does not follow that expansion automatically ,so i need to scroll manually to see expanded item.So i used scrollView.fullScroll(View.FOCUS_DOWN) in onClick in my recyclerview.And it works fine but after this line of code is triggered every other click on some other recycelerView it scroll down although that recyclerview does not have fullScroll().
I tried to use scrollTo(),smoothScrollTo etc.I dont use ExpandableRecyclerView but cachapa/ExpandableLayout and in this thread developer said that it is rather the parent View "issue".Also tried solution from the same thread but problem persist.
So my question is how to stop triggering fullScroll(View.FOCUS_DOWN) when i click on other recuclerviews items.
my code:
` animaton.setOnClickListener(v -> {
notifyDataSetChanged();
//some stuff
scrollView.post(new Runnable() {
public void run() {
scrollView.fullScroll(View.FOCUS_DOWN);
}
});
});`
I'm new new in Java and working on an old project that uses bsImagePicker. There's a bug in my current project that when the user wants to click the below back button of the gallery it takes the user to home page.
This shouldn't be the default behavior, rather it should take the user 1 step back. Please, How do I overwrite the method of this back button? Unfortunately, I couldn't find any xml file that has referenced this button neither there's any previous overwritten method.
Thanks in advance.
Edit: I searched more and figured out maybe it has to do something with getSupportActionBar().setDisplayHomeAsUpEnabled() but I don't know how to set its android:parentActivityName attribute.
To override onBackPressed() method and implement your own functionality or behavior.
#Override
public void onBackPressed() {
//implement your own functionality in this
}
But since you are trying to implement it for back button shown in attached image and you don't have reference of it. Either you can create a reference by own or you can try on onCancelled method as provided in BSImagePicker gallary github repo.
//Optional
#Override
public void onCancelled(boolean isMultiSelecting, String tag) {
//Do whatever you want when user cancelled
}
I have code like this below. It works (run without any error), however it seems button doesn't call method boardMaker() properly. Furthermore two previous lines doesn't work either. When I comment line with boardMaker call. It works. Any suggestions why this call paralyze my button?
(refresh is RelativeLayout)
refresh.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v){
refresh.setVisibility(View.INVISIBLE);
resultDisplay.setTextColor(Color.MAGENTA);
boardMaker(1);
}
});
There is no reason why the lines of code inside the onClickListener block would not work you're syntax is perfect.
Please show us boardMaker() method.
Your button getting paralyzed could be a sign of a blocking call made in boardMaker().
When a return button is pressed in the app I am working on:
public void clickReturn(View view)
{
// ...
// Call an event handler before finishing the activity
_appData.CustomDetail.hookBeforeFinish(this, new ArrayList<CompSubmission>(_submissions));
// Finish this activity
finish();
}
I am not able to modify clickReturn() - the way the application is structured, all I have access to is the hook hookBeforeFinish().
What I want to do is add a dialog to prompt for some input. I can do this in hookBeforeFinish(), but it only appears for a split second. I assume what is happening is I set up the AlertDialog builder, call builder.show() but finish() is being called directly afterwards - so the dialog only appears momentarily.
Is there anything I can put after builder.show() in the hook function such that it won't continue execution to finish()? If I can pause the application flow until someone presses the OK button on the dialog thatwould work better for me.
Thanks
Please comment finish().
Then read and add a dialog as explained here. In your positive button click (e.g. OK button), add finish();
Edit
Since you cannot override clickReturn() or change the class, you can use your hookBeforeFinish() to create a dialog and comment 'clickReturn();' line.
In your dialog, in the listener for the button which expects to finish the activity add clickReturn();.
This way you will pause the activity closing until user decides to do so.
I have a class called TouchImageView extends ImageView and I detect where the user clicks on it. If it is a interest point, I want to call a method on the Detailed_Image_Activity that will update a WebView. How can I achieve this?
I found some ideas about using observer and observables but I don't know how to do that. I found this solution Equivalent of iOS NSNotificationCenter in Android? but I can't make it work it
This is my code in the TouchImageView class...
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
if(isPointOfInterest) {
//The code below is used to update the WebView
//The task called below exists in the Detailed_Image_Activity
DownloadHighlightBackground HighlightDownloaderTask = new DownloadHighlightBackground();
HighlightDownloaderTask.execute(new String[] { arg1.toString() });
}
}
Try this,
You can get the activity from within the view, in this way..
((MyActivity)getContext()).method_name();
To start up an activity you need access to the application's context and then you can call startActivity.