问题描述
我要创建与目标2.2上一个Android应用程序。我还是想用在android.support-v4.jar.i提供的ViewPager想需要禁用按钮click.i Viewpager swipping必须使用以下code为禁用。但它不工作。
I'm creating a android application with target on 2.2. I still want to use the ViewPager provided in the android.support-v4.jar.i want need to disable Viewpager swipping on button click.i have use following code for disable. but its don't work.
public class ServiesDeail extends FragmentActivity{
ServiesTitleFragmentAdapter mAdapter;
ViewPager mPager;
int position = 0 ;
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mastermenu);
LinearLayout lnrparent = (LinearLayout) findViewById(R.id.LL_001);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.menu_deatil, null);
lnrparent.addView(view);
mAdapter = new ServiesTitleFragmentAdapter(getSupportFragmentManager());
mPager = (ViewPager) findViewById(R.id.pagerone);
mPager.setAdapter(mAdapter);
TitlePageIndicator indicator = (TitlePageIndicator) findViewById(R.id.indicatorone);
indicator.setViewPager(mPager,position);
Menu_Button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mPager.setClickable(false);
}
});
}
}
如果u有任何想法的人..请给我效应初探..即时通讯等待你的回应
if u have any idea anyone.. please give me reponse.. i m waiting your response
推荐答案
您必须扩展视图寻呼机,并创建一个自定义视图寻呼机您可以在XML,而不是认为寻呼机使用,你从支持获得图书馆和改变一些属性,请参见下面的code,它为我工作。使用customviewpager在code和刷卡将被禁用。
You will have to extend the view pager and create a custom view pager for you which can be used in the xml instead of the view pager that you get from support library and change some properties, see the code below, it worked for me. Use the customviewpager in your code, and the swiping will be disabled.
public class CustomViewPager extends ViewPager{
public CustomViewPager(Context context){
super(context);
}
public CustomViewPager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
public boolean onInterceptTouchEvent(MotionEvent ev){
return false;
}
@Override
public boolean onTouchEvent(MotionEvent ev){
return false;
}
}
这篇关于如何使用Android的支持,v4.jar Android中禁用ViewPager刷卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!