Activity
にはViewPager
、カスタムアダプターにはPagerAdaper
が実装されています。私はPagerAdapter
の中のビューを膨らませて、親ビューにサブビューを追加しています。これらのサブビューは、アダプターに渡すリストのオブジェクトの特定のパラメーターに応じて、RadioGroup
、Checkboxes
、EditText
などです。PagerAdapterで膨らんだビューから値を取得
ページが変更されると、これらのサブビューから値を取得します。しかし、私のインフレコードはアダプターの中にあるので、アダプター自体からページの変更をどのように検出できるのか知る必要があります。次のように私は私のViewPagerにアダプタを渡す
public override Java.Lang.Object InstantiateItem(ViewGroup container, int position)
{
var view = voteFormActivity.LayoutInflater.Inflate(Resource.Layout.active_votes_layout, container, false);
txtvoteTitle = view.FindViewById<TextView>(Resource.Id.txtTitle);
//radioGroup = view.FindViewById<RadioGroup>(Resource.Id.radioGroupChoice);
btnSubmit = view.FindViewById<Button>(Resource.Id.btnSubmit);
layoutForcomponents = view.FindViewById<LinearLayout>(Resource.Id.layoutForComponents);
radioGroup = new RadioGroup(voteFormActivity);
var data = selectedVotes.ElementAt(position);
if (data != null)
{
if (!string.IsNullOrEmpty(data.Title))
{
txtvoteTitle.Text = data.Title;
}
var choiceList = data.Choices;
if (choiceList != null && choiceList.Count > 0)
{
if (checkParam == "RadioChoice")
{
foreach (var choice in choiceList)
{
RadioButton rButton = new RadioButton(voteFormActivity);
rButton.Text = choice;
radioGroup.AddView(rButton);
layoutForcomponents.RemoveAllViews();
layoutForcomponents.AddView(radioGroup);
}
}
else if (checkParam == "CheckBoxChoice")
{
foreach (var choice in choiceList)
{
CheckBox cButton = new CheckBox(voteFormActivity);
cButton.Text = choice;
radioGroup.AddView(cButton);
layoutForcomponents.RemoveAllViews();
layoutForcomponents.AddView(radioGroup);
}
}
}
//if (checkParam == "MultiLineText")
else{
EditText etMultilineText = new EditText(voteFormActivity);
etMultilineText.Hint = "Enter feedback";
etMultilineText.SetLines(6);
layoutForcomponents.RemoveAllViews();
layoutForcomponents.AddView(etMultilineText);
}
}
container.AddView(view);
return view;
}
: - - :ここで
は、アダプタの私のコードである私は、ページの変更を検出してから値を取得できますかmViewPager.Adapter = new PollViewPagerAdapter(this, this.FragmentManager, AppHelper.SelectedVotes);
RadioGroup
,Checkbox
およびEditText
?どんな助けもありがとうございます。
ビューページに添付する 'ViewPager.onPageChangeListener 'があります。これはあなたの後だったのですか? – RobVoisey
@RobVoisey 'ViewPager.onPageChangeListener'をアクティビティに適用する必要がありますが、必要な値が' PagerAdapter'で膨らんでいますが、ページが変更されたときにそれらの値を取得するにはどうすればよいですか? – user3034944
ビューをクラスのフィールドとして単に保存することはできますか? 'ViewPager.onPageChangeListener'は、ページが更新されたことを知らせ、現在表示されているページを取得できる場合に、使用するビューフィールドを知ります。 – RobVoisey