1.RT, I want to dynamically update the listview data on the fragment interface by clicking the button on the fragment interface. I write the method of updating Listview into a showlist () method
/**
*
*/
private void showList() {
mArrayList.clear();
for (int i = 2; i < paraList.size(); iPP) {
Para para = paraList.get(i);
HashMap<String, String> map = new HashMap<String, String>();
map.put("one_show_item_title", para.getName());
map.put("one_show_item_text", para.getValue());
mArrayList.add(map);
}
simpleAdapter = new SimpleAdapter(getContext(),
mArrayList,
R.layout.item_listview_fg_one,
new String[]{"one_show_item_title", "one_show_item_text"}, //ListItem
new int[]{R.id.one_show_item_title, R.id.one_show_item_text} //
);
for (HashMap<String, String> map : mArrayList) {
Log.d(TAG, "run: " + map.get("one_show_item_title"));
Log.d(TAG, "run: " + map.get("one_show_item_text"));
}
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
lv_fg_one_show.setAdapter(simpleAdapter);
}
});
}
then update the data in the array in updatalist, and then call the showlist method to update the listview, after the update, but it still can"t be updated. What"s going on?
/**
* url
*
* @param url
*/
private void updateList(String url) {
HttpUtils.sendOkHttpRequest(url, new okhttp3.Callback() {
@Override
public void onFailure(Call call, IOException e) {
//
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getContext());
builder.setMessage("")
.setPositiveButton("", null);
builder.show();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
//jsonresponse.body().string()
String data = response.body().string();
Gson gson = new Gson();
paraList.clear();
paraList = gson.fromJson(data, new TypeToken<List<Para>>() {
}.getType());
for (Para para : paraList) {
Log.d(TAG, "onResponse: ---------" + para.getString());
}
}
});
}