- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试构建一个寻呼机来按顺序显示图像。但是我收到了这个错误。
The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged!
Expected adapter item count: 0, found: 1 Pager id:.
请高人指导修复。
这是我的代码:
MatChedUserProfile Activity
public class MatChedUserProfile extends Activity implements OnClickListener {
private static final String TAG = "MatChedUserProfile";
private static boolean mDebugLog = true;
private static String mDebugTag = "MatChedUserProfile";
private ExtendedGallery imageExtendedGallery;
private LinearLayout image_count;
private TextView usernametextivew, ueragetextviw, distancetextview,
activetimetextview, abouttextview, abouttextviewvalues,
viewMatchedProfiletextview, statusTextView;
private RelativeLayout Aboutuseragelayout, likedislikebuttonlayout;
private Button likeButton, dislikebutton;
private ArrayList<GellaryData> imageList;
//private ImageAdapterForGellary mAdapterForGellary;
private ProgressDialog mDialog;
private int[] imageHeightandWIdth;
private ConnectionDetector cd;
private RelativeLayout.LayoutParams layoutParams;
private int count;
private TextView[] page_text;
private SharedPreferences preferences;
//new viewpager....
private ViewPager viewPager;
private MyViewPagerAdapter mAdapterForGellary;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.matcheduserprofile);
//Thread.setDefaultUncaughtExceptionHandler(new CrashLogger(getApplicationContext()));
cd = new ConnectionDetector(this);
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
preferences = PreferenceManager.getDefaultSharedPreferences(this);
initLayoutResource();
imageList = new ArrayList<GellaryData>();
//listOfItems=new ArrayList<GellaryData>();
mAdapterForGellary = new MyViewPagerAdapter(imageList);
//imageExtendedGallery.setAdapter(mAdapterForGellary);
viewPager.setAdapter(mAdapterForGellary);
Ultilities ultilities = new Ultilities();
imageHeightandWIdth = ultilities
.getImageHeightAndWidthForProfileGellary(this);
Bundle bundle = getIntent().getExtras();
if (bundle != null) {
if (bundle.getBoolean(Constant.isFromChatScreen)) {
likedislikebuttonlayout.setVisibility(View.GONE);
} else {
}
}
Settings.addLoggingBehavior(LoggingBehaviors.INCLUDE_ACCESS_TOKENS);
try {
likeButton.setOnClickListener(this);
dislikebutton.setOnClickListener(this);
} catch (Exception e) {
}
RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(
imageHeightandWIdth[1], imageHeightandWIdth[0]);
rlp.addRule(RelativeLayout.CENTER_HORIZONTAL);
layoutParams = ultilities.getRelativelayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layoutParams.setMargins(0, 5, 0, 0);
layoutParams = ultilities.getRelativelayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layoutParams.setMargins(0, 5, 0, 0);
cd = new ConnectionDetector(getApplicationContext());
if (cd.isConnectingToInternet()) {
getUserProfile();
// getUserShareeInterest();
} else {
AlertDialogManager
.internetConnetionErrorAlertDialog(MatChedUserProfile.this);
}
//myViewPagerAdapter = new MyViewPagerAdapter(imageList);
viewPager.setAdapter(mAdapterForGellary);
viewPager.setCurrentItem(0);
viewPager.setOnPageChangeListener(viewPagerPageChangeListener);
/* imageExtendedGallery
.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id) {
for (int i = 0; i < count; i++) {
page_text[i]
.setTextColor(android.graphics.Color.GRAY);
}
page_text[pos]
.setTextColor(android.graphics.Color.LTGRAY);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});*/
}
// page change listener
ViewPager.OnPageChangeListener viewPagerPageChangeListener = new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
for (int i = 0; i < count; i++) {
page_text[i]
.setTextColor(android.graphics.Color.GRAY);
}
page_text[position]
.setTextColor(android.graphics.Color.LTGRAY);
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
}
@Override
public void onPageScrollStateChanged(int arg0) {
}
};
private void initLayoutResource() {
viewMatchedProfiletextview = (TextView) findViewById(R.id.viewMatchedProfiletextview);
likeButton = (Button) findViewById(R.id.likeButton);
dislikebutton = (Button) findViewById(R.id.dislikebutton);
//imageExtendedGallery = (ExtendedGallery) findViewById(R.id.imageExtendedGallery);
viewPager = (ViewPager)findViewById(R.id.viewPager);
image_count = (LinearLayout) findViewById(R.id.image_count);
usernametextivew = (TextView) findViewById(R.id.usernametextivew);
ueragetextviw = (TextView) findViewById(R.id.ueragetextviw);
distancetextview = (TextView) findViewById(R.id.distancetextview);
activetimetextview = (TextView) findViewById(R.id.activetimetextview);
statusTextView = (TextView) findViewById(R.id.txtMatchedUserStatus);
// userfriendgallery = (HorizontalListView)
// findViewById(R.id.userfriendgallery);
// userIntestedgallery = (HorizontalListView)
// findViewById(R.id.userIntestedgallery);
abouttextview = (TextView) findViewById(R.id.abouttextview);
Aboutuseragelayout = (RelativeLayout) findViewById(R.id.Aboutuseragelayout);
Aboutuseragelayout.setVisibility(View.GONE);
likedislikebuttonlayout = (RelativeLayout) findViewById(R.id.likedislikebuttonlayout);
abouttextviewvalues = (TextView) findViewById(R.id.abouttextviewvalues);
Typeface HelveticaInseratLTStd_Roman = Typeface.createFromAsset(
getAssets(), "fonts/HelveticaInseratLTStd-Roman.otf");
Typeface HelveticaLTStd_Light = Typeface.createFromAsset(getAssets(),
"fonts/HelveticaLTStd-Light.otf");
viewMatchedProfiletextview.setTypeface(HelveticaLTStd_Light);
viewMatchedProfiletextview.setTextColor(Color.rgb(255, 255, 255));
viewMatchedProfiletextview.setTextSize(20);
usernametextivew.setTypeface(HelveticaInseratLTStd_Roman);
usernametextivew.setTextColor(Color.rgb(124, 124, 124));
((TextView) findViewById(R.id.txtst))
.setTypeface(HelveticaInseratLTStd_Roman);
((TextView) findViewById(R.id.txtst)).setTextColor(Color.rgb(124, 124,
124));
statusTextView.setTypeface(HelveticaInseratLTStd_Roman);
statusTextView.setTextColor(Color.rgb(124, 124, 124));
// usernametextivew.setTextSize(20);
ueragetextviw.setTypeface(HelveticaLTStd_Light);
ueragetextviw.setTextColor(Color.rgb(124, 124, 124));
abouttextview.setTypeface(HelveticaInseratLTStd_Roman);
abouttextview.setTextColor(Color.rgb(92, 92, 92));
abouttextview.setTextSize(15);
abouttextviewvalues.setTypeface(HelveticaInseratLTStd_Roman);
abouttextviewvalues.setTextColor(Color.rgb(131, 131, 131));
abouttextviewvalues.setTextSize(15);
distancetextview.setTypeface(HelveticaInseratLTStd_Roman);
distancetextview.setTextColor(Color.rgb(92, 92, 92));
distancetextview.setTextSize(15);
activetimetextview.setTypeface(HelveticaInseratLTStd_Roman);
activetimetextview.setTextColor(Color.rgb(131, 131, 131));
activetimetextview.setTextSize(15);
}
private void getUserProfile() {
SessionManager mSessionManager = new SessionManager(this);
String macheduserFacebookid = mSessionManager
.getMatchedUserFacebookId();
AppLog.Log(TAG, "Matched UserFacebook ID:" + macheduserFacebookid);
// String userSessionToken = mSessionManager.getUserToken();
String userDeviceId = Ultilities.getDeviceId(this);
if (macheduserFacebookid != null && macheduserFacebookid.length() > 0) {
// String[] params = { userSessionToken, userDeviceId,
// macheduserFacebookid };
String[] params = { macheduserFacebookid };
new BackGroundTaskForUserProfile().execute(params);
} else {
ErrorMessageMandetoryFiledMissing(
getResources().getString(R.string.alert), getResources()
.getString(R.string.retriedmessage));
}
}
private class BackGroundTaskForUserProfile extends
AsyncTask<String, Void, Void> {
Ultilities mUltilities = new Ultilities();
private String getProfileResponse;
private List<NameValuePair> userProfileNameValuePairList;
private userProFileData mUserProFileData;
private GellaryData mGellaryData;
@Override
protected Void doInBackground(String... params) {
try {
userProfileNameValuePairList = mUltilities
.getUserProfileParameter(params);
getProfileResponse = mUltilities.makeHttpRequest(
Constant.getProfile_url, Constant.methodeName,
userProfileNameValuePairList);
// logDebug("BackGroundTaskForUserProfile getProfileResponse "+getProfileResponse);
Gson gson = new Gson();
mUserProFileData = gson.fromJson(getProfileResponse,
userProFileData.class);
String[] images = mUserProFileData.getImages();
for (int i = 0; i < images.length; i++) {
mGellaryData = new GellaryData();
mGellaryData.setImageUrl(images[i]);
imageList.add(mGellaryData);
}
runOnUiThread(new Runnable() {
@Override
public void run() {
if (mDialog != null) {
mDialog.dismiss();
}
page_text = new TextView[imageList.size()];
count = imageList.size();
image_count.removeAllViews();
for (int i = 0; i < imageList.size(); i++) {
page_text[i] = new TextView(MatChedUserProfile.this);
page_text[i].setText(".");
page_text[i].setTextSize(45);
page_text[i].setTypeface(null, Typeface.BOLD);
page_text[i]
.setTextColor(android.graphics.Color.GRAY);
image_count.addView(page_text[i]);
}
//Log.d("shanImage", Array.toString(mUserProFileData.getImages()));
mAdapterForGellary.notifyDataSetChanged();
if (mUserProFileData.getStatus() != null
&& !mUserProFileData.getStatus().equals("")) {
statusTextView
.setText(mUserProFileData.getStatus());
} else {
statusTextView.setText("N/A");
}
ueragetextviw.setText("" + mUserProFileData.getAge());
usernametextivew.setText(""
+ mUserProFileData.getFirstName());
viewMatchedProfiletextview.setText(""
+ mUserProFileData.getFirstName());
SessionManager sessionManager = new SessionManager(
MatChedUserProfile.this);
String DistanceUinit = null;
if (sessionManager.getDistaceUnit().equals("Km")) {
DistanceUinit = "Km.";
} else {
DistanceUinit = "Mi.";
}
distancetextview.setText("Less than "
+ mUserProFileData.getDistance() + " "
+ DistanceUinit + " away");
String gmtTime = mUserProFileData.getLastActive();
// gmtTime=gmtTime.replaceAll("-", " ");
String localTime = UltilitiesDate.getLocalTime(gmtTime);
Ultilities ultilities = new Ultilities();
// String
// curentTime=ultilities.getCurrentDateYYYYMMdd();
String dataString = UltilitiesDate
.datesString(localTime);
UltilitiesDate ultilitiesDate = new UltilitiesDate();
int days = ultilitiesDate.getDays();
int hours = ultilitiesDate.getHours();
activetimetextview.setText("active " + days + " -d "
+ hours + "- Hour ago");
if (mUserProFileData.getPersDesc() != null
&& mUserProFileData.getPersDesc().length() > 0) {
Aboutuseragelayout.setVisibility(View.VISIBLE);
abouttextview.setText("About " + ""
+ mUserProFileData.getFirstName());
abouttextviewvalues.setText(""
+ mUserProFileData.getPersDesc());
} else {
Aboutuseragelayout.setVisibility(View.GONE);
}
}
});
} catch (Exception e) {
AppLog.Log(TAG,
"BackGroundTaskForUserProfile doInBackground Exception"
+ e);
}
return null;
}
@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
try {
if (mDialog != null) {
mDialog.dismiss();
}
} catch (Exception e) {
AppLog.Log(TAG,
"BackGroundTaskForUserProfile onPostExecute Exception "
+ e);
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
mDialog = mUltilities.GetProcessDialog(MatChedUserProfile.this);
mDialog.setMessage("Please Wait..");
mDialog.setCancelable(false);
mDialog.show();
}
}
ImageAdapterForGellary 适配器
private class ImageAdapterForGellary extends PagerAdapter {
Activity mActivity;
private LayoutInflater mInflater;
private Ultilities mUltilities = new Ultilities();
private int[] imageheightandWidth = mUltilities
.getImageHeightAndWidthForGellary(MatChedUserProfile.this);
public ImageAdapterForGellary(
List<GellaryData> objects) {
//mActivity = context;
mInflater = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return super.getCount();
}
@Override
public GellaryData getItem(int position) {
return super.getItem(position);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.galleritem, null);
holder.imageview = (ImageView) convertView
.findViewById(R.id.thumbImage);
// holder.mProgressBar = (ProgressBar) convertView
// .findViewById(R.id.pbGalleryItemImage);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// holder.mProgressBar.setId(position);
holder.imageview.setId(position);
Picasso.with(MatChedUserProfile.this) //
.load(getItem(position).getImageUrl()) //
.error(R.drawable.error) //
.resize(imageHeightandWIdth[1], imageHeightandWIdth[0]) //
.into(holder.imageview);
return convertView;
}
class ViewHolder {
ImageView imageview;
// ProgressBar mProgressBar;
}
}
MyViewPagerAdapter 适配器
// adapter
public class MyViewPagerAdapter extends PagerAdapter {
private LayoutInflater layoutInflater;
//private ArrayList<Integer> items;
private List<GellaryData> items;
public MyViewPagerAdapter(List<GellaryData> objects) {
this.items = objects;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = layoutInflater.inflate(R.layout.galleritem, container,false);
ImageView galleimageview = (ImageView) view
.findViewById(R.id.thumbImage);
Picasso.with(MatChedUserProfile.this) //
.load(imageList.get(position).getImageUrl()) //
.error(R.drawable.error) //
.resize(imageHeightandWIdth[1], imageHeightandWIdth[0]) //
.into(galleimageview);
((ViewPager) container).addView(view);
return view;
}
@Override
public int getCount() {
return items.size();
}
@Override
public boolean isViewFromObject(View view, Object obj) {
return view == ((View)obj);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
View view = (View)object;
((ViewPager) container).removeView(view);
}
}
@Override
public void onStart() {
super.onStart();
// Session.getActiveSession().addCallback(statusCallback);
// FlurryAgent.onStartSession(this, Constant.flurryKey);
}
@Override
public void onStop() {
super.onStop();
// Session.getActiveSession().removeCallback(statusCallback);
// FlurryAgent.onEndSession(this);
}
}
这是我的错误:
FATAL EXCEPTION: main
java.lang.IllegalStateException: The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 0, found: 1 Pager id: com.crushmatic.pro:id/viewPager Pager class: class android.support.v4.view.ViewPager Problematic adapter: class com.fresh.slidingmenu.MatChedUserProfile$MyViewPagerAdapter
at android.support.v4.view.ViewPager.populate(ViewPager.java:1000)
at android.support.v4.view.ViewPager.populate(ViewPager.java:952)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1474)
at android.view.View.measure(View.java:16677)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:847)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16677)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:16677)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
at android.view.View.measure(View.java:16677)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5286)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2421)
at android.view.View.measure(View.java:16677)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1927)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1119)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1301)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1006)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5652)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:544)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
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:5433)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1268)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1084)
at dalvik.system.NativeStart.main(Native Method)
最佳答案
for (int i = 0; i < images.length; i++) {
mGellaryData = new GellaryData();
mGellaryData.setImageUrl(images[i]);
imageList.add(mGellaryData);
}
这就是导致崩溃的原因,您无法将多个对象添加到附加到 for 循环内的适配器的数组
移动这个
mAdapterForGellary = new MyViewPagerAdapter(imageList);
//imageExtendedGallery.setAdapter(mAdapterForGellary);
viewPager.setAdapter(mAdapterForGellary);
任务执行后
关于android - 应用程序的 PagerAdapter 更改了适配器的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39206760/
SO亲爱的 friend 们: 2014 年 3 月 18 日。我正在处理一种情况,在使用 ng-repeat 时,数组内的元素(我从 Json 字符串中获取)更改了原始顺序。 需要明确的是,数组中的
有很多问题询问如何在 JavaScript 单击处理程序中更改 div 的类,例如,此处:Change Div style onclick .我理解得很好(只需更改 .className),并且它有效
我从access导入了一个数据库到mysql,但其中一个表的列名“股数”带有空格,但我尝试更改、替换甚至删除列名,但失败了。任何人都可以帮助解决这一问题 String UpdateQuary = "U
我正在做一个随机的学校元素。 目前,我有一个包含两个 CSS 的页面。一种用于正常 View ,一种用于残障人士 View 。 此页面还包括两个按钮,它们将更改使用的样式表。 function c
我需要使用 javascript 更改 HTML 元素中的文本,但我不知道该怎么做。 ¿有什么帮助吗? 我把它定义成这样: Text I want to change. 我正在尝试这样做: docum
我在它自己的文件 nav_bar.shtml 中有一个主导航栏,每个其他页面都包含该导航栏。这个菜单栏是一个 jQuery 菜单栏(ApyCom 是销售这些导航栏的公司的名称)。导航栏上的元素如何确定
我正在摆弄我的代码,并开始想知道这个变化是否来自: if(array[index] == 0) 对此: if(!array[index] != 0) 可能会影响任何代码,或者它只是做同样的事情而我不需
我一直在想办法调整控制台窗口的大小。这是我正在使用的函数的代码: #include #include #define WIDTH 70 #define HEIGHT 35 HANDLE wHnd;
我有很多情况会导致相同的消息框警报。 有没有比做几个 if 语句更简单/更好的解决方案? PRODUCTS BOX1 BOX2 BOX3
我有一个包含这些元素的 XELEMENT B Bob Petier 19310227 1 我想像这样转换前缀。 B Bob Pet
我使用 MySQL 5.6 遇到了这种情况: 此查询有效并返回预期结果: select * from some_table where a = 'b' and metadata->>"$.countr
我想知道是否有人知道可以检测 R 中日期列格式的任何中断的包或函数,即检测日期向量格式更改的位置,例如: 11/2/90 12/2/90 . . . 15/Feb/1990 16/Feb/1990 .
我希望能够在小部件显示后更改 GtkButton 的标签 char *ButtonStance == "Connect"; GtkWidget *EntryButton = gtk_button_ne
我正在使用 Altera DE2 FPGA 开发板并尝试使用 SD 卡端口和音频线路输出。我正在使用 VHDL 和 C 进行编程,但由于缺乏经验/知识,我在 C 部分遇到了困难。 目前,我可以从 SD
注意到这个链接后: http://www.newscientist.com/blogs/nstv/2010/12/best-videos-of-2010-progress-bar-illusion.h
我想知道在某些情况下,即使剧本任务已成功执行并且 ok=2,ansible 也会显示“changed=0”。使用 Rest API 和 uri 模块时会发生这种情况。我试图找到解释但没有成功。谁能告诉
这个问题已经有答案了: 已关闭12 年前。 Possible Duplicate: add buttons to push notification alert 是否可以在远程通知显示的警报框中指定有
当您的 TabBarController 中有超过 5 个 View Controller 时,系统会自动为您设置一个“更多” View 。是否可以更改此 View 中导航栏的颜色以匹配我正在使用的颜
如何更改.AndroidStudioBeta文件夹的位置,默认情况下,该文件夹位于Windows中的\ .. \ User \ .AndroidStudioBeta,而不会破坏任何内容? /编辑: 找
我目前正在尝试将更具功能性的编程风格应用于涉及低级(基于 LWJGL)GUI 开发的项目。显然,在这种情况下,需要携带很多状态,这在当前版本中是可变的。我的目标是最终拥有一个完全不可变的状态,以避免状
我是一名优秀的程序员,十分优秀!