标签:
在项目过程中,有时候需要给一个控件设置多个tag的需求,最常见的就是在ListView中的item,如果有数据错乱的行为,最好的办法就是给当前的 view设置tag保存跟它一致的数据,
view.setTag(Object);
view.getTag;
view.setTag(int key,Object object); view.getTag(int key);
view.setTag(1,object);
view.getTag(1);
E/AndroidRuntime: FATAL EXCEPTION: main Process: cn.vcinema.cinema, PID:6755 java.lang.IllegalArgumentException:The key must be an application-specific resource id. at android.view.View.setTag(View.java:16284) at cn.vcinema.cinema.module.adapter.MovieDetailsHolder1.refreshView(MovieDetailsHolder1.java:91) at cn.vcinema.cinema.base.BaseHolder.setDate(BaseHolder.java:28) at cn.vcinema.cinema.base.MyBaseAdapter.getView(MyBaseAdapter.java:51) at cn.vcinema.cinema.widget.flipview.FlipView.getView(FlipView.java:477) at cn.vcinema.cinema.widget.flipview.FlipView.fillPageForIndex(FlipView.java:398) at cn.vcinema.cinema.widget.flipview.FlipView.setFlipDistance(FlipView.java:383) at cn.vcinema.cinema.widget.flipview.FlipView.setAdapter(FlipView.java:1123) at cn.vcinema.cinema.module.ui.MovieDetailsFragment.setData(MovieDetailsFragment.java:129) at cn.vcinema.cinema.presenter.MovieDetailsPresenter$1.onResponse(MovieDetailsPresenter.java:61) at retrofit.ExecutorCallAdapterFactory$ExecutorCallback$1.run(ExecutorCallAdapterFactory.java:86) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5065) at java.lang.reflect.Method.invokeNative(NativeMethod) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609) at dalvik.system.NativeStart.main(NativeMethod)
<item type="id" name="tag_first"/> <item type="id" name="tag_second"/>
view.setTag(R.id.tag_first,object);
view.getTag(R.id.tag_first);
标签:
原文地址:http://www.cnblogs.com/Android-MR-wang/p/5088045.html