Android 单击按钮可多次填充ListView
我有一个显示服务器数据的应用程序 现在我的问题是,我有一个Listview,其中填充了来自服务器的JSON数据 这是为了显示记录的时间,我有一个截止日期和起始日期编辑文本来输入所需的日期 每次单击按钮时,列表视图都会填充,但以前加载的数据会保留在列表视图中 我想要实现的是,每次单击按钮时,清除以前的数据,只显示新数据 我正在使用截取从服务器获取Json 我已尝试设置自定义适配器,将适配器设置为Null 这是我的点击Android 单击按钮可多次填充ListView,android,json,listview,arraylist,android-volley,Android,Json,Listview,Arraylist,Android Volley,我有一个显示服务器数据的应用程序 现在我的问题是,我有一个Listview,其中填充了来自服务器的JSON数据 这是为了显示记录的时间,我有一个截止日期和起始日期编辑文本来输入所需的日期 每次单击按钮时,列表视图都会填充,但以前加载的数据会保留在列表视图中 我想要实现的是,每次单击按钮时,清除以前的数据,只显示新数据 我正在使用截取从服务器获取Json 我已尝试设置自定义适配器,将适配器设置为Null 这是我的点击 Submit.setOnClickListener(new View.OnCli
Submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Uri.Builder builder2=new Uri.Builder();
builder2.scheme("https")
.authority("www.FAKEWEBSiTE.co.za")
.appendPath("DATA.asp")
.appendQueryParameter("ClientID", clientId)
.appendQueryParameter("Username", email)
.appendQueryParameter("Pwd", pwd)
.appendQueryParameter("FromDate", FromDate.getText().toString().trim())
.appendQueryParameter("ToDate", ToDate.getText().toString().trim());
URL2=builder2.build().toString();
LoadReport(URL2);
下面是我加载JSON等的代码
private void LoadReport(String url) {
final ProgressDialog pd=new ProgressDialog(reportActivity.this);
pd.setMessage("Please Wait..Loading Time Log Data");
pd.setCanceledOnTouchOutside(false);
pd.show();
RequestQueue requestQueue=Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest=new StringRequest(Request.Method.GET, url, new Response.Listener<String>() {
@TargetApi(Build.VERSION_CODES.N)
@Override
public void onResponse(String response) {
pd.cancel();
try {
JSONObject jsonObject=new JSONObject(response);
if (jsonObject.getInt("success") == 1) {
JSONArray jsonArray=jsonObject.getJSONArray("Name");
for (int i=0; i < jsonArray.length(); i++) {
JSONObject jsonObject1=jsonArray.getJSONObject(i);
String key=jsonObject1.keys().next();
String task=jsonObject1.getString(key);
Project.add(task);
}
report.setAdapter(new ArrayAdapter<>(reportActivity.this, android.R.layout.simple_spinner_dropdown_item, Project));
report.setClickable(false);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
pd.cancel();
error.printStackTrace();
}
});
int socketTimeout=30000;
RetryPolicy policy=new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
stringRequest.setRetryPolicy(policy);
requestQueue.add(stringRequest);
}}
private void LoadReport(字符串url){
final ProgressDialog pd=新建ProgressDialog(reportActivity.this);
pd.setMessage(“请稍候..加载时间日志数据”);
pd.SetCanceledOnTouchOut(假);
pd.show();
RequestQueue RequestQueue=Volley.newRequestQueue(getApplicationContext());
StringRequest StringRequest=新建StringRequest(Request.Method.GET,url,new Response.Listener()){
@TargetApi(Build.VERSION\u code.N)
@凌驾
公共void onResponse(字符串响应){
pd.cancel();
试一试{
JSONObject JSONObject=新JSONObject(响应);
if(jsonObject.getInt(“成功”)==1){
JSONArray JSONArray=jsonObject.getJSONArray(“名称”);
for(int i=0;i
每次单击按钮时,必须清除传递给适配器的列表Submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(Project!=null){
Project.clear();
}
Uri.Builder builder2=new Uri.Builder();
builder2.scheme("https")
.authority("www.FAKEWEBSiTE.co.za")
.appendPath("DATA.asp")
.appendQueryParameter("ClientID", clientId)
.appendQueryParameter("Username", email)
.appendQueryParameter("Pwd", pwd)
.appendQueryParameter("FromDate", FromDate.getText().toString().trim())
.appendQueryParameter("ToDate", ToDate.getText().toString().trim());
URL2=builder2.build().toString();
LoadReport(URL2);