Reputation: 52
OnClickListener not working with ScrollView because "extends Fragment". How can I use it with this? An example enough. Thanks..
UPDATE Fragment1.java
package intizamyazilim.example;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
/**
* Created by Administrator on 26.02.2015.
*/
public class Fragment1 extends Fragment {
@Override
public View onCreateView (LayoutInflater inflater, ViewGroup container, Bundle SavedInstanceState) {
if (container == null) {
return null;
}
return (LinearLayout) inflater.inflate(R.layout.fragment1, container, false);
}
}
Upvotes: 0
Views: 199
Reputation: 128
You can use horizontallscrollviews onTouchListener as in this example. I just quickly used Android Studio's default activity with fragment but I hope it gives you an idea :)
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
return rootView;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
HorizontalScrollView horizontalScrollView = (HorizontalScrollView) getActivity().findViewById(R.id.horizontalScrollView);
horizontalScrollView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
Toast.makeText(getActivity(), "Touched", Toast.LENGTH_LONG).show();
}
return false;
}
});
}
}
Upvotes: 1