ユーザが各ペイン内で対話できるViewPagerを使用しようとしています。このViewPagerでは、チュートリアルを作成して、スイッチ・ペインに水平にスワイプするようユーザーに指示します。ユーザーが最後のペインに達すると、ダッシュボードにナビゲートされるボタンがユーザーに表示されます。私はいくつかの記事を読んで、ボタンがViewPager内でどのように動作するのかを理解しようとしましたが、本当に意味をなさないはずです。ViewPager内のボタンの使用
コードは、ViewPager内のペイン内のボタンをクリックすると、ダッシュボードアクティビティが開始されます。ここで
はpagerAdapterの完全なコードです:
class MyPagerAdapter extends PagerAdapter {
public int getCount() {
return 5;
}
public Object instantiateItem(View collection, int position) {
View v = new View(collection.getContext());
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = R.layout.tutorial_step1;
break;
case 1:
resId = R.layout.tutorial_step2;
break;
case 2:
resId = R.layout.tutorial_step3;
break;
case 3:
resId = R.layout.tutorial_step4;
break;
case 4:
resId = R.layout.tutorial_complete;
v = inflater.inflate(R.layout.tutorial_complete, null, false);
LinearLayout l = (LinearLayout) v.findViewById(R.id.llComplete);
Button button=(Button)l.findViewById(R.id.bTutorialComplete);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Create an intent that starts a different activity
}
});
break;
}
((ViewPager) collection).addView(v, 0);
return v;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public Parcelable saveState() {
return null;
}
}
私が記事で見てきたものから、一緒に働くべきであるコードは次のとおりです。
public Object instantiateItem(View collection, int position) {
View v = new View(collection.getContext());
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int resId = 0;
switch (position) {
case 0:
resId = R.layout.tutorial_step1;
break;
case 1:
resId = R.layout.tutorial_step2;
break;
case 2:
resId = R.layout.tutorial_step3;
break;
case 3:
resId = R.layout.tutorial_step4;
break;
case 4:
resId = R.layout.tutorial_complete;
v = inflater.inflate(R.layout.tutorial_complete, null, false);
LinearLayout l = (LinearLayout) v.findViewById(R.id.llComplete);
Button button=(Button)l.findViewById(R.id.bTutorialComplete);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
//Create an intent that starts a different activity
}
});
break;
}
((ViewPager) collection).addView(v, 0);
return v;
}
それが唯一のcase 4:
内にありますswitch
私はこれがボタンを持っているので、他のレイアウトは画像とテキストだけが相互作用を必要としないが含まれているので、作業中です。
私は数え切れないほどの時間をかけてこれを進めてきましたが、これを解決する方法はまだ分かりませんでした。あなたが私にこれを手伝ってもらえれば非常に感謝しています。
を私は何をあなたの質問は本当にわからないんだけどです。ボタンでビューのレイアウトを作成する方法を理解しようとしていますか?または、アクティビティを開始する意図を作成する方法を理解しようとしていますか?または、他の何か?これまでのコードは大丈夫です。あなたのレイアウトとエラーを示すLogCatを提供できるなら、それはあなたの質問に答えるのにも役立ちます。 – louielouie
私はswitch文でレイアウトを提供しましたが、レイアウトの1つにボタンがあります。そのボタンにアクティビティを開始するためのインテントを作成します。私はインテントの作成を試み、switch文内でアクティビティを開始しようとしましたが、コンパイラはそれを受け入れず、このインテント引数とstartActivityメソッドを認識しません。 – kibria3