【发布时间】:2015-06-23 08:00:50
【问题描述】:
我是安卓新手。我正在创建一个应用程序,它由一个带有滑动选项卡布局的视图寻呼机组成。当我单击该按钮时,它会在视图寻呼机内进行一些计算。在执行此操作时,我希望禁用选项卡之间的切换。所以在计算时不要在页面之间滑动。 计算完成后,我希望再次启用切换。谁能告诉我该怎么做? 提前致谢。 我试过这个。请看一下:
public class Auto extends FragmentActivity{
Button tests;
private ViewPager pager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.auto);
tests = (PaperButton)findViewById(R.id.action_button_tests);
tests.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(pager.getCurrentItem()==0){
tests.setTag(1);
tests.setText("START TEST");
final int status = (Integer)v.getTag();
if(status==1){
tests.setText("STOP TEST");
v.setTag(0);
int i;
Login.Communication_Ok=false;
for( i=0;(i<5 && Login.Communication_Ok!=true);i++)
Login.Send_Commands_To_Micro_Controller(1);
if(Login.Communication_Ok==true)
{
Video_Status=false;
Login.Bucket_Status = false;
Login.Auto_Mode_Bfr_Fuse =false;
for( i=0;(i<5 && Login.Auto_Mode_Bfr_Fuse!=true);i++)
Login.Send_Commands_To_Micro_Controller(3);
if(Login.Auto_Mode_Bfr_Fuse==true)
Toast.makeText(Auto.this, "Test started", Toast.LENGTH_LONG).show();
else
{
Toast.makeText(Auto.this, "Communication Failure in Before Fuse connection Segment", Toast.LENGTH_LONG).show();
tests.setText("START TEST");
v.setTag(1);
return;
}
Test_Completed=false;
if(!Auto_Bucket_Tests_Thread.isAlive())
Auto_Bucket_Tests_Thread.start();
}
}
else{
tests.setText("START TEST");
v.setTag(1);
}
}
if(pager.getCurrentItem()==1){
tests.setTag(1);
tests.setText("START TEST");
final int status = (Integer)v.getTag();
if(status==1){
tests.setText("STOP TEST");
v.setTag(0);
int i;
Login.Communication_Ok=false;
for( i=0;(i<5 && Login.Communication_Ok!=true);i++)
Login.Send_Commands_To_Micro_Controller(1);
if(Login.Communication_Ok==true)
{
Video_Status=false;
Login.Bucket_Status = false;
Login.Automode_After_connecting_fuse =false;
for( i=0;(i<5 && Login.Automode_After_connecting_fuse!=true);i++)
Login.Send_Commands_To_Micro_Controller(4);
if(Login.Automode_After_connecting_fuse==true){
Toast.makeText(Auto.this, "Test started", Toast.LENGTH_LONG).show();
**/*For Disabling swipe between tabs*/**
pager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
pager.getCurrentItem();
return false;
}
});
pager.setEnabled(false);
}
else
{
Toast.makeText(Auto.this, "Communication Failure in After Fuse connection Segment", Toast.LENGTH_LONG).show();
tests.setText("START TEST");
v.setTag(1);
return;
}
Test_Completed=false;
}
}
else{
tests.setText("START TEST");
v.setTag(1);
}
}
} }
【问题讨论】:
-
你在谷歌搜索过答案吗? HERE
-
但是在这里我将我的主要活动扩展到片段活动@snachmsm
-
那又怎样?使用修改后的
ViewPager,用在什么地方没有区别,Fragment,Activity,随便...都是View,只需要Context
标签: android swipe-gesture disabled-control