如何創建自定義ViewPager? 要在ViewPager實例化一個網頁是這樣的:自定義ViewPager
public Object instantiateItem(View collection, int position) {
TextView tv = new TextView(cxt);
tv.setText("Bonjour PAUG " + position);
tv.setTextColor(Color.WHITE);
tv.setTextSize(30);
((ViewPager) collection).addView(tv,0);
return tv;
}
是有辦法膨脹這樣從一個適配器擴展一個類:
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.the_layout, null);
}
CustomView cv = items.get(position);
if (cv != null) {
TextView text = (TextView) v.findViewById(R.id.text);
if (text != null) {
ticker.setText(cv.getText());
}