私は Android 開発の初心者であり、Jake Wharton の Viewpagerindicator のタイトル/ヘッダーを動的に更新するのに問題があります。onPageChangeListener メソッド内および別のメソッド内のインジケーター インスタンスで notifyDataSetChanged() を使用しようとしましたが、成功しませんでした。最初に、OnCreate のグローバル文字列を介してタイトル/ヘッダーを設定しました。このSO の質問からの回答を実装しようとしましたが、成功しませんでした。これを解決する助けがあれば大歓迎です。
マイコード
作成時
chosenAilment = "";
suggestedRemedy="";
whichAilment=chosenAilment;
whichRemedy=suggestedRemedy;
whichArea="AREA OF DISCOMFORT";
setContentView(R.layout.viewpagermain);
MyPagerAdapter adapter = new MyPagerAdapter( this );
pager = (ViewPager)findViewById( R.id.viewpager );
indicator = (TitlePageIndicator)findViewById( R.id.indicator );
pager.setAdapter( adapter );
indicator.setViewPager( pager );
indicator.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
Crouton.makeText(RemedyActivity.this, "page changed", Style.INFO).show();
if(position==0){
whichAilment="";
whichRemedy="";
whichArea="AREA OF DISCOMFORT";
}else if(position==1){
whichAilment=chosenAilment;
whichRemedy="";
whichArea="";
}else if(position==2){
whichAilment="";
whichRemedy=suggestedRemedy;
whichArea="";
}
indicator.notifyDataSetChanged();
}
Update メソッド
public void updateMsg(String t_info, float t_x, float t_y, int t_c){
//infoView.updateInfo(t_info, t_x, t_y, t_c);
popUpButton.setText(TouchView.touchInfo);
popUpButton.setX(t_x-(popUpButton.getWidth()/2));
popUpButton.setY(t_y-(popUpButton.getHeight()));
Resources res = getResources();
if(TouchView.touchInfo=="Arm"){
ailmentsList = res.getStringArray(R.array.arm_ailments);
chosenAilment = "ARM AILMENTS";
}else if(TouchView.touchInfo=="Leg"){
ailmentsList = res.getStringArray(R.array.leg_ailments);
chosenAilment = "LEG AILMENTS";
}else if(TouchView.touchInfo=="Back"){
ailmentsList = res.getStringArray(R.array.back_ailments);
chosenAilment = "BACK AILMENTS";
}else if(TouchView.touchInfo=="Groin"){
if(isMale){
ailmentsList = res.getStringArray(R.array.groin_ailments_male);
chosenAilment = "GROIN AILMENTS";
}else{
ailmentsList = res.getStringArray(R.array.groin_ailments_female);
chosenAilment = "GROIN AILMENTS";
}
}else if(TouchView.touchInfo=="Chest"){
if(isMale){
ailmentsList = res.getStringArray(R.array.chest_ailments_male);
chosenAilment = "CHEST AILMENTS";
}else{
ailmentsList = res.getStringArray(R.array.chest_ailments_female);
chosenAilment = "CHEST AILMENTS";
}
}else if(TouchView.touchInfo=="Abdomen"){
if(isMale){
ailmentsList = res.getStringArray(R.array.abdomen_ailments_male);
chosenAilment = "ABDOMEN AILMENTS";
}else{
ailmentsList = res.getStringArray(R.array.abdomen_ailments_female);
chosenAilment = "ABDOMEN AILMENTS";
}
}else if(TouchView.touchInfo=="Head"){
ailmentsList = res.getStringArray(R.array.head_ailments);
chosenAilment = "HEAD AILMENTS";
}else if(TouchView.touchInfo=="Buttocks"){
ailmentsList = res.getStringArray(R.array.buttocks_ailments);
chosenAilment = "BUTTOCKS AILMENTS";
}else{
ailmentsList = res.getStringArray(R.array.head_ailments);
chosenAilment = "";
}
indicator.notifyDataSetChanged();
}
ページャ アダプタ
private class MyPagerAdapter extends PagerAdapter {
private String[] titles = new String[] {whichArea, whichAilment, whichRemedy };
private final Context context;
private int[] scrollPosition = new int[titles.length];
public MyPagerAdapter( Context context )
{
this.context = context;
for ( int i = 0; i < titles.length; i++ )
{
scrollPosition[i] = 0;
}
}
@Override
public String getPageTitle( int position )
{
return titles[position];
}
@Override
public int getCount()
{
return titles.length;
}