i want to build app with viewpager and display image and text from DB, and i had a button to resize Text to Small,Medium,Big size, but my problem how to make that methode and call it? this is my code
Phrase.java
public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.phrase);
mViewPager = (ViewPager) findViewById(R.id.viewPager);
mMyFragmentPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mMyFragmentPagerAdapter);
text = (ImageView)findViewById(R.id.ibText);
/* call db and store in arraylist */
....
}
private static class MyFragmentPagerAdapter extends FragmentPagerAdapter {
public MyFragmentPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int index) {
var = arrayphrase.get(index);
phrase = var.phraseKey;
title_phrase = var.titleKey;
sound_id = var.indexkey;
return PageFragment.newInstance(index,sound_id,phrase,title_phrase);
}
@Override
public void destroyItem(View container, int position, Object object) {
// TODO Auto-generated method stub
super.destroyItem(container, position, object);
}
@Override
public int getCount() {
return NUMBER_OF_PAGES;
}
}
CharSequence[] sizetext = {"Small", "Medium", "Big","Cancel"};
@Override
public void onClick(View v) {
case R.id.ibText:
AlertDialog.Builder listBuilder = new AlertDialog.Builder(Phrase.this);
listBuilder.setItems(sizetext, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item)
{
if(sizetext[item].equals("Big"))
{
sizeText=24;
onUpdateSize(sizeText);
}
else if(sizetext[item].equals("Medium"))
{
sizeText=20;
onUpdateSize(sizeText);
}
else if(sizetext[item].equals("Small"))
{
sizeText=16;
onUpdateSize(sizeText);
}
}
});
AlertDialog alertList = listBuilder.create();
alertList.show();
break;
}
PageFragment.java
public class PageFragment extends Fragment {
public static PageFragment newInstance(int index,String sound, String phrase, String title_phrase) {
PageFragment pageFragment = new PageFragment();
Bundle bundle = new Bundle();
bundle.putString("title_phrase", title_phrase);
bundle.putString("sound", sound);
bundle.putString("phrase", phrase);
bundle.putInt("index", index);
pageFragment.setArguments(bundle);
return pageFragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment, container, false);
ImageView imageView = (ImageView) view.findViewById(R.id.imageView1);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
options.inScaled = false;
options.inPreferQualityOverSpeed=true;
options.inJustDecodeBounds = false;
options.inDither = false;
Bitmap bitmap = BitmapFactory.decodeResource(this.getResources(), Imgid[(int)(Math.random()*Imgid.length)], options);
//imageView.setScaleType(ScaleType.FIT_XY);
imageView.setImageBitmap(bitmap);
ScrollView sv = (ScrollView)view.findViewById(R.id.scrollView1);
LinearLayout.LayoutParams lp2= new LinearLayout.LayoutParams((int)(TorasanApp.device_width*0.7), (int) (TorasanApp.device_height*0.65),Gravity.CENTER);
sv.setLayoutParams(lp2);
sv.setBackgroundColor(Color.argb(20, 65, 65, 65));
TextView tvdata = (TextView)view.findViewById(R.id.tvDetailPhrase);
tvdata.setText(getArguments().getString("phrase"));
TextView tvtitle = (TextView)view.findViewById(R.id.tvTitlephrase);
tvtitle.setText(getArguments().getString("title_phrase"));
return view;
}
}
you see in my Phrase when onclick i have onUpdateSize(sizeText) and i want call it to change TextView tvdata fontsize that was in PageFragment.java , so how to make that method and call it? because i try but still cant