English 中文(简体)
名单
原标题:Listview Returns Exception when Adapter is Modified

我有一份清单,显示一定数量的数据,在底部有一顿,可以要求装上更多的数据。 情况如下:

CustomArrayAdapter a = GetInitialData();
LayoutInflater layoutInflater = 
   (LayoutInflater)context.getSystemService( Context.LAYOUT_INFLATR_SERVICE );
LinearLayout ll = 
   (LinearLayout)layoutInflater.inflate(R.layout.more_button_layout, null, false);
Button b = (Button)ll.findViewById(R.id.more_button);

b.setOnClickListener(new OnClickListener() {

public void onClick(View v) {
    a.loadNextPage();
  }
});

lv.addFooterView(ll);
lv.setAdapter(a);

问题是,每当我向纽特施加压力时,我就在适应者自己掌握的电动器中获得了同步的消化。 我认为,这是因为在清单中点燃时,有人叫上装载NextPage,但我无法说明如何做到这一点。

问题回答

See the following URL http://www.javacodegeeks.com/2011/05/avoid-concurrentmodificationexception.html

页: 1 印本

如果不允许这种修改,则可能通过发现同时修改物体的方法推翻这一例外。

例如,在另一个读写者——或同一读物——正在篡改收时,通常无法调取。

请注意,这一例外并不总是表明物体已同时经过不同校对。 如果一对一对一物体的合同违反一系列方法的援引,该物体可放弃这一例外。 例如,如果在收集工作时,一面直截了当,一面会把收集工作与一个失败的炉子相隔,则该机将how这个例外。

Example:

for (Iterator it = myCollection.iterator(); it.hasNext()) {
Object myObject = it.next();
if (someConditionIsTrue) {
// myCollection.remove(myObject); // wrong can throw ConcurrentModificationException
it.remove(myObject); // right
}
} 




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签