(1) TabPageIndicator 动态刷新数据
TabPageIndicator 动态刷新数据
adapter.notifyDataSetChanged();
indicator.notifyDataSetChanged();
————————————————————————————————————————————————————————————————
解决:
/**
* 当栏目项发生变化时候调用
* */
private void setChangelView() {
userChannelList = ((ArrayList<ChannelItem>)ChannelManage.getManage(MyApplication.getApp().getSQLHelper()).getUserChannel());
readChannel();
initFragment();
//((TabPageIndicatorAdapter) mAdapter).refresh();
mAdapter.setFragments(fragments);
mIndicator.notifyDataSetChanged();
}
(2)getView 中的类型强转问题
1.cdv.nanan.mobilestation.ui.fragment.AbsListFragment$ViewHolder cannot be cast to cdv.nanan.mobilestation.ui.fragment.AbsListFragment$RecommondViewHolder
if(type.equals("list") && position==0){
recommondViewHolder = (RecommondViewHolder)convertView.getTag();
}else{
viewHolder = (ViewHolder) convertView.getTag();
}
因为自己不知道ListView中convertView的刷新复用机制,导致类型转换问题,看看ListView 复用问题
(3)建立表 要用空格!
public void onCreate(SQLiteDatabase db) {
// TODO 创建数据库后,对数据库的操作
String sql = "create table if not exists "+TABLE_CHANNEL +
"(_id INTEGER PRIMARY KEY AUTOINCREMENT, " +
ID + " INTEGER , " +
NAME + " TEXT , " + // name 与 text 之间 是用空格的
TYPE + " TEXT ," +
ORDERID + " INTEGER , " +
SELECTED + " SELECTED)";
db.execSQL(sql);
}
(4)ViewPager + HorizontalScrollView 问题
问题: viewPager 右滑有fragment ,而左滑回去就没有了fragment 问题
因为自己写的代码不严谨导致的这种界面显示的问题,真的很难找到这种问题,只有代码一步一步的调试,才会有结果,还有就是自己对fragment的生命周期在ViewPager里面的过程不清楚 导致这个的严重问题
</pre><pre name="code" class="java">@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
//新闻分类
catid = Integer.valueOf(getArguments().getString(CATID,""));
type = getArguments().getString(PROGRAMA_TYPE,"");
Log.e("type", type);
mContext = activity;
dialog = new LoadingDialog(mContext);
dialog.show();
pi.get().GetNewsList(catid, 0, 15, this);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mContainer = inflater.inflate(R.layout.activity_list, container, false);
initBitMapUtil() ;
initView();
return mContainer;
}
问题在于第一次有界面是因为,在网络加载成功后有执行了initView()操作,而左滑回来时就不会执行OnAttach()方法,而是直接执行onCreaterVivew() 方法 进行第二次加载!!!
(7)圆点添加 动态布局
(a).xml 中 设置成match_parent
<RelativeLayout
android:id="@+id/relative_recommend_item"
android:layout_width="match_parent"
android:layout_height="160dp"
android:orientation="vertical" >
<cdv.nanan.mobilestation.view.UGallery
android:id="@+id/recomemd_gallery"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
<LinearLayout
android:id="@+id/change_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:gravity="center_vertical" >
<LinearLayout
android:id="@+id/point_layout"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="horizontal" >
</LinearLayout>
</LinearLayout>
</RelativeLayout>
(b) point_layout在java代码中动态设置重力位置Grivaty才会有效果
if(recommendList.size() > 0 && position == 0){
viewHolder.mRecommendItem.setVisibility(View.VISIBLE);
viewHolder.mNormalItem.setVisibility(View.GONE);
//圆点初始化 动态添加
viewHolder.imgs = new ImageView[recommendList.size()];
viewHolder.layout.setGravity(Gravity.CENTER_HORIZONTAL);
viewHolder.layout.removeAllViews(); // 刷新
for(int i = 0; i< recommendList.size();i++){
viewHolder.imgs[i] = new ImageView(mContext);
if(i == 0)
viewHolder.imgs[i].setBackgroundResource(R.drawable.selectedflag);
else
viewHolder.imgs[i].setBackgroundResource(R.drawable.unselectedflag);
viewHolder.layout.addView(viewHolder.imgs[i]);
}
/**初始化推荐栏目*/
adGallery_Adapt adapt = new adGallery_Adapt(mContext, recommendList);
viewHolder.mRecommendGallery.setAdapter(adapt);
}