我是新来的ViewPager
。所以我参加了一个教程,现在一切正常。教程结束后,我有ViewPager
一个 TextView 。现在,我想在ImageView
这个TextView
. 我必须从哪里开始?
这是我的代码:
public static final MyFragment newInstance(String message){
MyFragment f = new MyFragment();
Bundle bdl = new Bundle(1);
bdl.putString(EXTRA_MESSAGE, message);
f.setArguments(bdl);
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String message = getArguments().getString(EXTRA_MESSAGE);
View v = inflater.inflate(R.layout.activity_my_fragment, container, false);
TextView messageTextView = (TextView)v.findViewById(R.id.tvTest);
messageTextView.setText(message);
return v;
}
和
public class Bilderbuch extends FragmentActivity {
MyPageAdapter pageAdapter;
int id;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_bilderbuch);
id = getIntent().getIntExtra("kinderid", 0);
List<Fragment> fragments = getFragments();
pageAdapter = new MyPageAdapter(getSupportFragmentManager(), fragments);
ViewPager pager = (ViewPager)findViewById(R.id.viewpager);
pager.setAdapter(pageAdapter);
}
private List<Fragment> getFragments(){
List<Fragment> fList = new ArrayList<Fragment>();
DBHelper dbh = new DBHelper(this);
Cursor c = dbh.selectEreignis(id);
int i = 0;
while(c.moveToNext())
{
fList.add(MyFragment.newInstance(c.getString(c.getColumnIndex("ereignisname"))));
i++;
}
fList.add(MyFragment.newInstance("Fragment 1"));
fList.add(MyFragment.newInstance("Fragment 2"));
fList.add(MyFragment.newInstance("Fragment 3"));
return fList;
}
private class MyPageAdapter extends FragmentPagerAdapter {
private List<Fragment> fragments;
public MyPageAdapter(FragmentManager fm, List<Fragment> fragments) {
super(fm);
this.fragments = fragments;
}
@Override
public Fragment getItem(int position) {
return this.fragments.get(position);
}
@Override
public int getCount() {
return this.fragments.size();
}
}