我已经使用 ViewPager 实现了三个选项卡。在右侧选项卡布局中,我有一个编辑文本小部件,当用户单击它时,键盘会出现。如果用户不手动关闭键盘并滑动到中间或左侧选项卡,则键盘将保留在屏幕上。那么如何避免在我不需要的其他两个选项卡中使用键盘。
编辑:这是我的代码。
class ViewPagerActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MyPagerAdapter adapter = new MyPagerAdapter();
ViewPager myPager = (ViewPager) findViewById(R.id.myfivepanelpager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(1);
TitlePageIndicator titleIndicator = (TitlePageIndicator) findViewById(R.id.titles);
titleIndicator.setViewPager(myPager);
} }
第二个文件:MyPagerAdapter.java
class MyPagerAdapter extends PagerAdapter implements OnClickListener,
OnLongClickListener, AdapterView.OnItemSelectedListener {
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
View view;
switch (position) {
case 0:
resId = R.layout.left;
view = inflater.inflate(resId, null);
break;
case 1:
resId = R.layout.main_c;
view = inflater.inflate(resId, null);
btn_no1 = (Button) view.findViewById(R.id.one);
btn_no1.setOnClickListener(this);
((ViewPager) collection).addView(view, 0);
return view;
case 2:
resId = R.layout.right;
view = inflater.inflate(resId, null);
main_spinner = (Spinner) view.findViewById(R.id.spinner1);
main_spinner.setOnItemSelectedListener(this);
from_spinner = (Spinner) view.findViewById(R.id.spinner2);
from_spinner.setOnItemSelectedListener(this);
to_spinner = (Spinner) view.findViewById(R.id.spinner3);
to_spinner.setOnItemSelectedListener(this);
swap = (ImageButton) view.findViewById(R.id.swap_spinner);
swap.setOnClickListener(this);
((ViewPager) collection).addView(view, 0);
return view;
}
view = inflater.inflate(resId, null);
((ViewPager) collection).addView(view, 0);
return view;
}
TitlePageIndicator 看起来像这样:TitlePageIndicator