我目前正在开发一款Android应用。当我初始化一个UI元素并在片段中的OnPageScrolled中设置UI元素的内容时,它不仅在片段中起作用,而是在活动类中起作用。这是代码:
circleIndicator.setOnPageChangeListener(new OnPageChangeListener(){
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
switch(arg0){
case 0:{
WorkoutDetailsFragment.this.txtNote = (EditText) getSherlockActivity().findViewById(R.id.editTextNote);
WorkoutDetailsFragment.this.txtNote.setText("hello");
WorkoutDetailsFragment.this.lstViewList1 = (ListView) getSherlockActivity().findViewById(R.id.lstViewlist1);
WorkoutDetailsFragment.this.lstViewList2 = (ListView) getSherlockActivity().findViewById(R.id.lstViewlist2);
p2 = new ArrayList<ArrayList<String>>();
arrayList2 = new ArrayList<String>();
arrayList2.add(getString(R.string.Recovery_rate));
arrayList2.add("");
p2.add(arrayList2);
adapter1 = new ListViewAdapterwithoutArrowHorizontal(getSherlockActivity(),
android.R.layout.simple_list_item_1, p2);
p2 = new ArrayList<ArrayList<String>>();
arrayList2 = new ArrayList<String>();
arrayList2.add(getString(R.string.Diet_Points));
arrayList2.add("");
p2.add(arrayList2);
adapter2 = new ListViewAdapterwithoutArrowHorizontal(getSherlockActivity(),
android.R.layout.simple_list_item_1, p2);
WorkoutDetailsFragment.this.lstViewList1.setAdapter(adapter1);
WorkoutDetailsFragment.this.lstViewList2.setAdapter(adapter2);
//LoadWorkoutResult();
//LoadWorkoutDetails();
if (adapter2.getItem(1).get(0).equals(getString(R.string.Diet_Points))
&& extras != null) {
adapter2.getItem(1).remove(1);
adapter2.getItem(1).add(
extras.getInt(getString(R.string.dietpoints)) + "");
}
Toast.makeText(getActivity(), "testing..........", Toast.LENGTH_LONG).show();
break;
}
case 1:{
//mapview = (MapView) findViewById(R.id.mapview);
// break;
}
case 2:{
//multitouchplot = (MultitouchPlot) findViewById(R.id.multitouchPlot);
//series = new SimpleXYSeries();
//splitchart = new SplitChart(series, multitouchplot, isMile);
//LoadSplitChart();
//break;
}
}
}
@Override
public void onPageSelected(int arg0) {
// TODO Auto-generated method stub
}
});
谁能知道问题出在哪里?我是否需要使用扩展FragmentPageAdapter的circleppageindicator适配器?
提前感谢您的任何帮助。
答案 0 :(得分:1)