Android 如何通过调用notifyOnDatasetChanged with in-base adapter刷新列表视图
我的fragment类中有一个带有按钮的列表视图,它是使用自定义适配器填充的。当按下列表视图中的按钮时,我想删除该项。在这里,当按钮从我的适配器类中单击时,我使用了Android 如何通过调用notifyOnDatasetChanged with in-base adapter刷新列表视图,android,listview,refresh,baseadapter,Android,Listview,Refresh,Baseadapter,我的fragment类中有一个带有按钮的列表视图,它是使用自定义适配器填充的。当按下列表视图中的按钮时,我想删除该项。在这里,当按钮从我的适配器类中单击时,我使用了notifyDataSetChanged,但它不反映任何结果。有人可以吗告诉我如何从适配器类更新列表视图 这是我在单击按钮后在适配器类中编写的代码 remove.setOnClickListener(new View.OnClickListener() { @Override publi
notifyDataSetChanged
,但它不反映任何结果。有人可以吗告诉我如何从适配器类更新列表视图
这是我在单击按钮后在适配器类中编写的代码
remove.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
notifyDataSetChanged();
}
});
我的完整适配器代码
import java.util.List;
import java.util.Objects;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.Color;
import android.lotus.com.androidmis.R;
import android.os.AsyncTask;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import com.lotus.mis.modle.Complaints.Complaint;
import com.lotus.mis.modle.MyAppApplication;
import com.subtabs.complaints.Complaints_pending;
import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.HttpTransportSE;
import org.w3c.dom.Text;
public class Support_ComplainAdapter extends BaseAdapter {
Context context;
List<Complaint> objects;
ProgressDialog progressdialog;
String UserID;
MyAppApplication mApp;
public Support_ComplainAdapter(Context context,int resource,List<Complaint> objects)
{
this.context = context;
this.objects = objects;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return objects.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return objects.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
// View POItemRow = inflater.inflate(R.layout.activity_poitem_listrow,parent,false);
View PurchaseOrderRow = LayoutInflater.from(context).inflate(R.layout.layout_complaint_adapter,null);
progressdialog = new ProgressDialog(context);
if (position % 2 == 1) {
PurchaseOrderRow.setBackgroundColor(Color.WHITE);
} else {
PurchaseOrderRow.setBackgroundColor(Color.LTGRAY);
}
mApp = ((MyAppApplication)context.getApplicationContext());
final Complaint TR = (Complaint)objects.get(position);
final String RequestNO = TR.getTicketNo();
final String reqID = TR.getComplaintID();
Complaint Complaintlist = (Complaint) objects.get(position);
//TextView txt_PONo = (TextView) PurchaseOrderRow.findViewById(R.id.txt_PONo);
//TextView txt_SuppName = (TextView) PurchaseOrderRow.findViewById(R.id.txt_SuppName);
TextView username = (TextView)PurchaseOrderRow.findViewById(R.id.txt_complaint_empname);
username.setText(mApp.getmGlobal_UserName());
TextView userid = (TextView)PurchaseOrderRow.findViewById(R.id.txt_complaint_userid);
userid.setText(mApp.getmGlobal_UserID());
TextView module_name = (TextView)PurchaseOrderRow.findViewById(R.id.txt_module_name);
module_name.setText(Complaintlist.getText2());
TextView Ref_no = (TextView)PurchaseOrderRow.findViewById(R.id.txt_ref_no);
Ref_no.setText(Complaintlist.getTicketNo());
TextView created_by = (TextView)PurchaseOrderRow.findViewById(R.id.txt_created_by_complaint);
created_by.setText(Complaintlist.getCreatedBy());
TextView created_Date= (TextView)PurchaseOrderRow.findViewById(R.id.txt_created_date_complaint);
created_Date.setText(Complaintlist.getCreatedDate());
TextView complaint_sub = (TextView)PurchaseOrderRow.findViewById(R.id.txt_complaint_sub);
complaint_sub.setText(Complaintlist.getComplaintName());
TextView complaint_body = (TextView)PurchaseOrderRow.findViewById(R.id.txt_complaint_body);
complaint_body.setText(Complaintlist.getText1());
final Button chat_support = (Button)PurchaseOrderRow.findViewById(R.id.btn_chat_support);
chat_support.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
final Button close_complaint = (Button)PurchaseOrderRow.findViewById(R.id.btn_close);
close_complaint.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new set_updateSupport().execute("UpdateValues", "1011",
reqID, "", "", "", "",
"", "","","","");
}
});
return PurchaseOrderRow;
}
class set_updateSupport extends AsyncTask<String, Integer, String> {
private static final String NAME_SPACE = "http://tempuri.org/";
private static final String URL = "http://192.168.1.106:99/Service.asmx";
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
progressdialog.setMessage("Adding Sales Request");
progressdialog.show();
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
String TempMethod = params[0];
String Flag = params[1];
String value1 = params[2];
String value2 = params[3];
String value3 = params[4];
String value4 = params[5];
String value5 = params[6];
String value6 = params[7];
String value7 = params[8];
String value8 = params[9];
String value9 = params[10];
String value10 = params[11];
try {
SoapObject request = new SoapObject(NAME_SPACE, TempMethod);
request.addProperty("Flag", Flag);
request.addProperty("value1", value1);
request.addProperty("value2", value2);
request.addProperty("value3", value3);
request.addProperty("value4", value4);
request.addProperty("value5", value5);
request.addProperty("value6", value6);
request.addProperty("value7", value7);
request.addProperty("value8", value8);
request.addProperty("value9", value9);
request.addProperty("value10", value10);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE Android_HttpTransport = new HttpTransportSE(URL);
Android_HttpTransport.debug = true;
Android_HttpTransport.call(NAME_SPACE + TempMethod, envelope);
String responseXml = envelope.getResponse().toString();
// String responseXml = Android_HttpTransport.responseDump;
Log.i("RITESH", "responseXml" + responseXml);
return responseXml;
} catch (Exception ex) {
ex.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
// super.onPostExecute(result);
progressdialog.dismiss();
if (result == null) {
Toast.makeText(context, "Error while reading data",
Toast.LENGTH_SHORT).show();
} else if (result.equals("0")) {
Toast.makeText(context, "No record for Update",
Toast.LENGTH_SHORT).show();
} else if (result.equals("1")) {
Toast.makeText(context, "Complain/Support Close Successfully", Toast.LENGTH_SHORT)
.show();
notifyDataSetChanged();
} else {
Toast.makeText(context, "Not Updated result " + result,
Toast.LENGTH_SHORT).show();
}
}
}
}
import java.util.List;
导入java.util.Objects;
导入android.app.ProgressDialog;
导入android.content.Context;
导入android.graphics.Color;
导入android.lotus.com.androidmis.R;
导入android.os.AsyncTask;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.BaseAdapter;
导入android.widget.Button;
导入android.widget.TextView;
导入android.widget.Toast;
导入com.lotus.mis.modle.Complaints.Complaints;
导入com.lotus.mis.modle.MyAppApplication;
导入com.subtabs.complaints.complaints\u待定;
导入org.ksoap2.SoapEnvelope;
导入org.ksoap2.serialization.SoapObject;
导入org.ksoap2.serialization.SoapSerializationEnvelope;
导入org.ksoap2.transport.HttpTransportSE;
导入org.w3c.dom.Text;
公共类支持\u ComplainAdapter扩展BaseAdapter{
语境;
列出对象;
进行对话进行对话;
字符串用户标识;
MyAppApplication mApp;
公共支持应用程序(上下文、int资源、列表对象)
{
this.context=上下文;
this.objects=对象;
}
@凌驾
public int getCount(){
//TODO自动生成的方法存根
返回objects.size();
}
@凌驾
公共对象getItem(int位置){
//TODO自动生成的方法存根
返回对象。获取(位置);
}
@凌驾
公共长getItemId(int位置){
//TODO自动生成的方法存根
返回位置;
}
@凌驾
公共视图getView(int位置、视图转换视图、视图组父视图){
//TODO自动生成的方法存根
//查看项目行=充气器。充气(R.layout.activity\u poitem\u listrow,父项,false);
查看PurchaseOrderRow=LayoutFlater.from(上下文)。充气(R.layout.layout\u适配器,空);
progressdialog=新建progressdialog(上下文);
如果(位置%2==1){
PurchaseOrderRow.setBackgroundColor(颜色:白色);
}否则{
PurchaseOrderRow.setBackgroundColor(Color.LTGRAY);
}
mApp=((MyAppApplication)context.getApplicationContext());
最终投诉TR=(投诉)对象。获取(位置);
最后一个字符串RequestNO=TR.getTicketNo();
最终字符串reqID=TR.getComplaintID();
投诉列表=(投诉)对象。获取(位置);
//TextView txt_-PONo=(TextView)PurchaseOrderRow.findViewById(R.id.txt_-PONo);
//TextView txt_SuppName=(TextView)PurchaseOrderRow.findViewById(R.id.txt_SuppName);
TextView用户名=(TextView)PurchaseOrderRow.findViewById(R.id.txt\u投诉\u empname);
username.setText(mApp.getmGlobal_username());
TextView用户标识=(TextView)PurchaseOrderRow.findViewById(R.id.txt\u投诉\u用户标识);
userid.setText(mApp.getmGlobal_userid());
TextView模块_名称=(TextView)PurchaseOrderRow.findViewById(R.id.txt_模块_名称);
模块_name.setText(Complaintlist.getText2());
TextView参考号=(TextView)PurchaseOrderRow.findViewById(R.id.txt参考号);
参考号setText(Complaintlist.getTicketNo());
TextView创建人=(TextView)PurchaseOrderRow.findViewById(R.id.txt创建人);
由.setText(Complaintlist.getCreatedBy())创建;
TextView创建日期=(TextView)PurchaseOrderRow.findViewById(R.id.txt创建日期);
已创建_Date.setText(Complaintlist.getCreatedDate());
TextView投诉号=(TextView)PurchaseOrderRow.findViewById(R.id.txt投诉号);
投诉_sub.setText(Complaintlist.getComplaintName());
TextView投诉正文=(TextView)PurchaseOrderRow.findViewById(R.id.txt投诉正文);
投诉_body.setText(投诉列表.getText1());
最终按钮聊天支持=(按钮)PurchaseOrderRow.findViewById(R.id.btn聊天支持);
chat_support.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
}
});
最终按钮关闭\投诉=(按钮)PurchaseOrderRow.findViewById(R.id.btn\关闭);
关闭.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
新集合\u updateSupport().execute(“updateValue”,“1011”,
请求ID、、、、、、,
"", "","","","");
}
});
返回PurchaseOrderRow;
}
类集合\u更新支持扩展异步任务{
私有静态最终字符串名称\u空格=”http://tempuri.org/";
私有静态最终字符串URL=”http://192.168.1.106:99/Service.asmx";
@凌驾
受保护的void onPreExecute(){
//TODO自动生成的方法存根
super.onPreExecute();
progressdialog.setMessage(“添加销售请求”);
progressdialog.show();
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
//TODO自动生成的方法存根
字符串TempMethod=params[0];
字符串标志=参数[1];
字符串值1=参数[2];
字符串值2=参数[3];
字符串值3=参数[4];
字符串值4=参数[5];
字符串值5=参数[6];
斯特里
objects.clear();
objects.addAll(query(......));
mAdapter.notifyDataSetChanged();