android开发viewpager中的listview怎样获得并填充?
搜到有人说这样写:LayoutInflatermInflater=getLayoutInflater();Viewv1=mInflater.inflate(R.layou...
搜到有人说这样写:
LayoutInflater mInflater = getLayoutInflater();
View v1 = mInflater.inflate(R.layout.first_frag, null);
ListView first_listview = (ListView) v1.findViewById(R.id.first_listview);
那么这段代码应该写在哪里呢?我是用的这个方法切换的页面:
public Fragment getItem(int position) {
switch(position)
{
case 0: return new FirstFragment();
case 1: return new SecondFragment();
case 2: return thirdFragment;
default:return new FirstFragment();
}
} 展开
LayoutInflater mInflater = getLayoutInflater();
View v1 = mInflater.inflate(R.layout.first_frag, null);
ListView first_listview = (ListView) v1.findViewById(R.id.first_listview);
那么这段代码应该写在哪里呢?我是用的这个方法切换的页面:
public Fragment getItem(int position) {
switch(position)
{
case 0: return new FirstFragment();
case 1: return new SecondFragment();
case 2: return thirdFragment;
default:return new FirstFragment();
}
} 展开
1个回答
展开全部
LayoutInflater mInflater = getLayoutInflater();
View v1 = mInflater.inflate(R.layout.first_frag, null);
ListView first_listview = (ListView) v1.findViewById(R.id.first_listview);
继承fragment的,类似的应该是放在
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.menu_list, null);
// findID(view);
ListView first_listview = (ListView) v1.findViewById(R.id.first_listview);
return view;
}
继承activity的,一般是放在onCreat()里面了
listview一般是用adapter来填充的,填充好后,类实现OnItemClickListener,
first_listview.setOnItemClickListener(this);
public void onItemClick(AdapterView<?> av, View arg1, int position, long arg3) {
//这里用来处理listview的点击
}
希望能够帮到你
View v1 = mInflater.inflate(R.layout.first_frag, null);
ListView first_listview = (ListView) v1.findViewById(R.id.first_listview);
继承fragment的,类似的应该是放在
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.menu_list, null);
// findID(view);
ListView first_listview = (ListView) v1.findViewById(R.id.first_listview);
return view;
}
继承activity的,一般是放在onCreat()里面了
listview一般是用adapter来填充的,填充好后,类实现OnItemClickListener,
first_listview.setOnItemClickListener(this);
public void onItemClick(AdapterView<?> av, View arg1, int position, long arg3) {
//这里用来处理listview的点击
}
希望能够帮到你
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询