こんにちは、誰かがこれを見て、私がどこで間違ったのか知っているかどうかを確認してください。GetTheMoreData() のポスト実行タスクが GetTheMoreData と GetTheData の両方からのエントリをリストビューに追加しようとするまで、正常に動作します。[さらに読み込む] ボタンをクリックすると、エラーは発生せず、リストビューは同じままです。ログにデータが表示されるので、Postexecute は起動します。ありがとう
SimpleAdapter mAdapter;
String mCurFilter;
List<Map<String, String>> items = new ArrayList<Map<String, String>>();
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
String letter = getActivity().getIntent().getStringExtra("LETTER");
new GetTheData().execute(letter);
final ListView lv = getListView();
Button btnLoadMore = new Button(getActivity());
btnLoadMore.setText("Load More");
lv.addFooterView(btnLoadMore);
lv.setTextFilterEnabled(true);
btnLoadMore.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
new GetTheMoreData().execute("A");
Log.i(TAG, "loadmore clicked : ");
}
});
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//room for stuff
}
});
setListShown(false);
getLoaderManager().initLoader(0, null, this);
}
private class GetTheMoreData extends AsyncTask<String, Void, List<Map<String, String>>> {
@Override
protected List<Map<String, String>> doInBackground(String... res) {
List<Map<String, String>> items = new ArrayList<Map<String, String>>();
start = start +25;
JSONObject json = JSONfunctions.getJSONfromURL("http://www.myurl.com/main.php?letter="+res[0]+"&start="+start);
try{
JSONArray songlist = json.getJSONArray("mainlist");
for(int i=0;i<songlist.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = songlist.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("Item", e.getString("Item"));
items.add(map);
Log.i(TAG, "dat:" + items);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
return items;
}
@Override
protected void onPostExecute(List<Map<String, String>> items) {
mAdapter.notifyDataSetChanged();
super.onPostExecute(items);
}
@Override
protected void onProgressUpdate(Void... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
}
}
private class GetTheData extends AsyncTask<String, Void, List<Map<String, String>>> {
@Override
protected List<Map<String, String>> doInBackground(String... res) {
JSONObject json = JSONfunctions.getJSONfromURL("http://www.myurl.com/main.php?letter="+res[0]+"&start=0");
try{
JSONArray songlist = json.getJSONArray("mainlist");
for(int i=0;i<songlist.length();i++){
HashMap<String, String> map = new HashMap<String, String>();
JSONObject e = songlist.getJSONObject(i);
map.put("id", String.valueOf(i));
map.put("Item", e.getString("Item"));
items.add(map);
}
}catch(JSONException e) {
Log.e("log_tag", "Error parsing data "+e.toString());
}
return items;
}
@Override
protected void onPostExecute(List<Map<String, String>> items) {
String[] from = new String[] { "Item" };
int[] to = new int[] { android.R.id.text1 };
mAdapter = new SimpleAdapter( getActivity(), items,
android.R.layout.simple_list_item_1, from, to );
setListAdapter( mAdapter );
super.onPostExecute(items);
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
switch( position )
{}
Log.i(TAG, "Item clicked: " + id);
}
// These are the rows that we will retrieve.
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
// mAdapter.swapCursor(data);
// The list should now be shown.
if (isResumed()) {
setListShown(true);
} else {
setListShownNoAnimation(true);
}
}
public void onLoaderReset(Loader<Cursor> loader) {
// mAdapter.swapCursor(null);
}
@Override
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
// TODO Auto-generated method stub
return null;
}