充氣意見獲取值我有一個ViewPager
,並實現了PagerAdaper
自定義適配器的Activity
。我正在充氣PagerAdapter
中的一個視圖,並向子視圖添加子視圖。這些子視圖RadioGroup
,Checkboxes
,EditText
等等,這取決於的對象,其名單我傳遞給適配器的某個參數。從在PagerAdapter
我想一旦網頁被改爲從這些子視圖獲取值。但是由於我的充氣代碼在適配器中,所以我需要知道如何從我的適配器本身檢測頁面更改。
這裏是我的適配器代碼: -
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;
}
我通過適配器連接到我的ViewPager如下: -
mViewPager.Adapter = new PollViewPagerAdapter(this, this.FragmentManager, AppHelper.SelectedVotes);
如何檢測頁面的變化,並從價值觀RadioGroup
,Checkbox
和EditText
?任何幫助表示讚賞。
有一個''ViewPager.onPageChangeListener您連接到viewpager。這是你以後的事嗎?我可以將它作爲一個答案,如果這樣 – RobVoisey
@RobVoisey'ViewPager.onPageChangeListener'已被應用到活動中,但我需要在'PagerAdapter'充氣的值,我怎樣才能得到這些值的頁面更改時? – user3034944
您不能簡單地將視圖作爲字段存儲在您的課堂上嗎? 'ViewPager.onPageChangeListener'可以讓你知道什麼時候頁面已經更新,你可以得到當前正在顯示的頁面,然後你就會知道使用哪個視圖字段。 – RobVoisey