我有一个查看寻呼机项目列表,每行都有查看寻呼机项目。我想为视图寻呼机项目制作布局类型,如附图所示,用户应该能够使用箭头点击移动视图寻呼机。
我无法获得如何实现相同的效果,这是我的列表适配器和寻呼机适配器的代码:
ListView GetView
ViewHolder holder;
if(rowView==null){
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.horizontal_list_item, parent,
false);
MyPagerAdapter adapter = new MyPagerAdapter(context);
ViewPager myPager = (ViewPager) rowView.findViewById(R.id.mypager);
myPager.setAdapter(adapter);
myPager.setCurrentItem(4, true);
rowView.setTag(holder);
}
else{
holder = (ViewHolder) rowView.getTag();
}
PagerAdapter
@Override
public Object instantiateItem(View container, final int position) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) inflater.inflate(
R.layout.inner_layout_file, null);
TextView tv_view = (TextView) layout.findViewById(R.id.text);
tv_view.setText("Example Item " + position);
((ViewPager) container).addView(layout);
});
return layout;
寻呼机项目布局(inner_layout_file)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inner_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6.0dip"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:text="Example Value"
android:textAppearance="?android:textAppearanceMedium" />
</LinearLayout>
我无法在哪里添加箭头以及在运行时执行点击的位置。我想使用左侧和右侧的箭头轻扫寻呼机视图
答案 0 :(得分:1)
您应该在ListView中为ViewPager充气并为其设置适配器
这是你怎么做的......
public View getView(int position, View view, ViewGroup vGroup) {
inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
vRow=view;
final ContentHolder holder;
if(view==null){
holder=new ContentHolder();
//infalte your viewPager here
vRow=inflater.inflate(R.layout.activity_swipe_view_pager, null);
holder.vPager=(ViewPager) vRow.findViewById(R.id.ui_pager);
holder.radiogrp=(RadioGroup) vRow.findViewById(R.id.ui_radiogroup);
addRadio=new AddRadioViewSwipe(context, pageCount);
addRadio.addRadio(holder.radiogrp);
holder.radiogrp.getChildAt(0).setAlpha(1.0f);
holder.vPager.setTag(R.id.ui_pager, "hold");
vRow.setTag(holder);
}
else{
holder=(ContentHolder) vRow.getTag();
}
pagerAdpt=new ViewPagerAdapter(context, integer,R.layout.activity_viewpager_model);
Parcelable state=holder.vPager.onSaveInstanceState();
//set your adapter here
holder.vPager.setAdapter(pagerAdpt);
holder.vPager.setOffscreenPageLimit(integer.length);
holder.vPager.setTag(position);
Float den = (float) context.getResources().getDisplayMetrics().densityDpi;
holder.vPager.setPageMargin((int) -den);
holder.vPager.onRestoreInstanceState(state);
holder.vPager.setOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
for(int i=0;i<pageCount;i++){
holder.radiogrp.getChildAt(pageCount-(i+1)).setAlpha(0.5f);
}
holder.radiogrp.getChildAt(position).setAlpha(1.0f);
}
@Override
public void onPageScrolled(int position, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
});
return vRow;
}
希望这可以帮助你...