こんにちは、Android アプリケーションにリストビューがあります。アプリを開いているときにロードし、ユーザーがリストの最後までスクロールすると、リストビューが完全にロードされます。しかし、2番目のスクロールでは、それ自体はロードされません。これが私のコードです:
lstinteract.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
// TODO Auto-generated method stub
}
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
// TODO Auto-generated method stub
int lastInScreen = firstVisibleItem + visibleItemCount;
if((lastInScreen == totalItemCount) && !(loadingMore2)){
loadingMore2=true;
GetFacebookInitDatas fb = new GetFacebookInitDatas();
fb.execute();
loadingMore2=false;
}
}
});
private class GetFacebookInitDatas extends AsyncTask<String, Void, Void>
{
@Override
protected Void doInBackground(String... params) {
// TODO Auto-generated method stub
final ArrayList<String> interactsenders = new ArrayList<String>();
final ArrayList<String> interactposts = new ArrayList<String>();
final ArrayList<String> interactimages = new ArrayList<String>();
final ArrayList<String> interactlinks = new ArrayList<String>();
try {
inprevpage = intlinks.getString("previous");
innextpage = intlinks.getString("next");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
System.out.println(innextpage);
URL url = new URL(innextpage);
URLConnection connection = url.openConnection();
HttpURLConnection httpConnection = (HttpURLConnection) connection;
int responseCode = httpConnection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
InputStream in = httpConnection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(
in, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
JSONObject data = new JSONObject(jsonText);
if (data != null) {
JSONArray duyurular = null;
try {
duyurular = data.getJSONArray("data");
intlinks = data.getJSONObject("paging");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String hocaid = null;
String postid=null;
String sender = null;
String mesaj = null;
for (int i = 0; i < duyurular.length(); i++) {
JSONObject obj = null;
try {
obj = duyurular.getJSONObject(i);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
postid = obj.getString("id");
postids.add(postid);
mesaj = obj.getString("message");
} catch (JSONException e) {
mesaj = "This attachment may have been removed or the person who shared it may not have permission to share it with you.";
}
JSONObject fromObj = null;
try {
fromObj = obj.getJSONObject("from");
} catch (JSONException e1) {
System.out.println("Hata 2");
e1.printStackTrace();
}
try {
sender = fromObj.getString("name");
hocaid = fromObj.getString("id");
} catch (JSONException e) {
sender = "Name didn't recieved.";
}
if (lecturerID.equals(hocaid)) {
} else {
interactsenders.add(sender);
interactposts.add(mesaj);
interactimages.add("http://graph.facebook.com/"+ hocaid + "/picture");
interactlinks.add("http://www.facebook.com/544570888900558/posts/"+ postid);
}
}
System.out.println("Size: "+postids.size());
ListToList(interactsenders, profname);
ListToList(interactposts, intercontent);
ListToList(interactimages, profpic);
ListToList(interactlinks, facebookunlink);
}
}
} catch (Exception e) {
System.out.println(e.toString());
}
return null;
}
protected void ListToList(ArrayList<String> source,ArrayList<String> destination) {
for (int i = 0; i < source.size(); i++) {
destination.add(source.get(i));
}
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
interaction=new AnnounceAdapter(main, profname,profpic,intercontent);
interaction.notifyDataSetChanged();
}
}
私のLogcatは次のとおりです。
08-19 10:38:10.172: W/System.err(4946): org.json.JSONException: No value for paging
08-19 10:38:10.172: W/System.err(4946): at org.json.JSONObject.get(JSONObject.java:354)
08-19 10:38:10.172: W/System.err(4946): at org.json.JSONObject.getJSONObject(JSONObject.java:569)
08-19 10:38:10.172: W/System.err(4946): at com.invemo.vodafonelivecoursetest.MainActivity$GetFacebookAnnounceDatas.doInBackground(MainActivity.java:613)
08-19 10:38:10.172: W/System.err(4946): at com.invemo.vodafonelivecoursetest.MainActivity$GetFacebookAnnounceDatas.doInBackground(MainActivity.java:1)
08-19 10:38:10.182: W/System.err(4946): at android.os.AsyncTask$2.call(AsyncTask.java:264)
08-19 10:38:10.182: W/System.err(4946): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-19 10:38:10.182: W/System.err(4946): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-19 10:38:10.182: W/System.err(4946): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
08-19 10:38:10.182: W/System.err(4946): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
08-19 10:38:10.182: W/System.err(4946): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
08-19 10:38:10.182: W/System.err(4946): at java.lang.Thread.run(Thread.java:856)