0
我的工作簡單的應用程序,我做了3次一viewpager,我需要把列表視圖中viepager 但列表視圖不會showup 這裏是我的viewpager 包特級com.Schoolreporting.androidApp;如何把列表視圖中viewpager
import java.util.ArrayList;
import android.content.Context;
import android.location.Address;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MyPagerAdapter extends PagerAdapter {
String Name;
// State number of pages
public int getCount() {
return 4;
}
public void setName(String Name) {
this.Name = Name;
}
// Set each screen's content
@Override
public Object instantiateItem(View container, int position) {
Context context = container.getContext();
LinearLayout layout = new LinearLayout(context);
// Add elements
TextView textItem = new TextView(context);
ListView grades=new ListView(context);
ArrayList<String>names=new ArrayList<String>();
names.add("Adel");
names.add("zetta");
names.add("Pringy");
ArrayAdapter<String> adapter=new ArrayAdapter<String> (context,android.R.layout.simple_list_item_1,names);
grades.setAdapter(adapter);
switch (position) {
case 0:
Toast.makeText(context,names.get(1),Toast.LENGTH_LONG).show();
textItem.setText(Name + "'s Grades");
grades.setAdapter(adapter);
Toast.makeText(context,names.get(1),Toast.LENGTH_LONG).show();
break;
case 1:
grades.setAdapter(adapter);
textItem.setText(Name + "'s grades");
break;
case 2:
textItem.setText(Name + "'s feedback");
break;
case 3:
textItem.setText(Name + "'s school");
break;
}
layout.addView(textItem);
((ViewPager) container).addView(layout, 0); // This is the line I
// added
return layout;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
}
@Override
public boolean isViewFromObject(View arg0, Object arg1) {
return arg0 == ((View) arg1);
}
@Override
public Parcelable saveState() {
return null;
}
}