Android 单击列表中的单选按钮时,带有onscroll事件重置滚动位置的Listview

Android 单击列表中的单选按钮时,带有onscroll事件重置滚动位置的Listview,android,Android,这是我的自定义适配器的getView方法。 列表视图位于警报对话框中。我在列表视图中填写了一个web服务请求 我的问题是,每当我选择列表中的任何单选按钮时,滚动位置都会重置为顶部 @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub View row = null;

这是我的自定义适配器的
getView
方法。
列表视图
位于
警报对话框
中。我在
列表视图中填写了一个web服务请求

我的问题是,每当我选择列表中的任何单选按钮时,滚动位置都会重置为顶部

@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View row = null;
        LayoutInflater inflater = (LayoutInflater) c
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        if (convertView == null) {
            row = inflater.inflate(R.layout.list_item_dialog_clients, parent,
                    false);
        } else {
            row = convertView;
        }
        RadioButton button = (RadioButton) row
                .findViewById(R.id.rbDialogCustomerName);
        button.setText(details.get(position).firstname
                + " " + details.get(position).lastname);
        button.setChecked(position == selectedPosition);
        button.setTag(position);
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                selectedPosition = (Integer) v.getTag();
                notifyDataSetInvalidated();
            }
        });
        return row;
    }
这是我的警报对话框类

import java.util.ArrayList;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.ListView;

import com.android.volley.AuthFailureError;
import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.test.R;
import com.pakage.adapters.DialogClientListAdapter;
import com.pakage.utilities.ProgressDialogManager;
import com.pakage.application.AppController;

public class CustomersDialog implements OnScrollListener {
    private Context c;
    ListView lvCustomers;
    DialogClientListAdapter adapter;
    ServerDetails serverDetails;
    ArrayList<DialogClientDetails> list;
    String errorMessage;
    View v;
    AlertDialog.Builder dialog;
    Boolean loading = false;
    int limitstart = 1, limitnum = 30, currentpage = 0, totalresults,
            totalpages = 0;

    public CustomersDialog(Context c) {
        this.c = c;
        serverDetails = new ServerDetails(c);
        list = new ArrayList<DialogClientDetails>();
        adapter = new DialogClientListAdapter(c, list);
    }

    public void createDialog() {

        dialog = new AlertDialog.Builder(c);
        v = View.inflate(c, R.layout.dialog_customers, null);
        dialog.setTitle("Select Client");
        dialog.setView(v);
        dialog.setPositiveButton("Select",
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
                });
        dialog.show();
        lvCustomers = (ListView) v.findViewById(R.id.lvDialogCustomers);
        lvCustomers.setAdapter(adapter);
        lvCustomers.setOnScrollListener(this);
        getCustomers();
    }

    private void getCustomers() {
        loading = true;
        ProgressDialogManager.showDialog(c);
        StringRequest request = new StringRequest(Method.POST,
                serverDetails.getUrl(), responseListner, errorListner) {

            @Override
            protected Map<String, String> getParams() throws AuthFailureError {
                if (currentpage > 0) {
                    limitstart = currentpage * limitnum + 1;
                }
                Map<String, String> map = serverDetails.getParameters();
                map.put("action", "getclients");
                map.put("limitstart", limitstart + "");
                map.put("limitnum", limitnum + "");
                return map;
            }

        };
        AppController.getInstance().addToRequestQueue(request);
    }

    Response.Listener<String> responseListner = new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            // TODO Auto-generated method stub
            try {
                JSONObject jobj = new JSONObject(response);
                String result = jobj.getString("result");
                if (result.contains("success")) {
                    totalresults = Integer.parseInt(jobj
                            .getString("totalresults"));
                    JSONObject clients = jobj.getJSONObject("clients");
                    JSONArray client = clients.getJSONArray("client");
                    for (int i = 0; i < client.length(); i++) {
                        JSONObject temp = client.getJSONObject(i);
                        DialogClientDetails details = new DialogClientDetails();
                        list.add(details);
                        details.id = temp.getString("id");
                        details.firstname = temp.getString("firstname");
                        details.lastname = temp.getString("lastname");
                    }

                    if (totalresults > limitnum) {
                        int reminder = totalresults % limitnum;
                        if (reminder > 0) {
                            totalpages = totalresults / limitnum + 1;
                        } else {
                            totalpages = totalresults / limitnum;
                        }
                    }

                } else if (result.contains("error")) {
                    errorMessage = jobj.getString("message");
                    Dialog d = new Dialog(c, errorMessage);
                    d.setCanceledOnTouchOutside(false);
                    d.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                loading = false;
            }
            ProgressDialogManager.hideDialog();
            adapter.notifyDataSetChanged();
            loading = false;
            currentpage++;
        }
    };
    Response.ErrorListener errorListner = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            // TODO Auto-generated method stub
            ProgressDialogManager.hideDialog();
            Dialog d = new Dialog(c, error.getMessage());
            d.setCanceledOnTouchOutside(false);
            d.show();
        }
    };

    @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
        if (firstVisibleItem + visibleItemCount == totalItemCount
                && totalItemCount != 0) {
            if (!loading) {
                if (currentpage < totalpages)
                    getCustomers();
            }
        }
    }
}

尝试使用
notifyDataSetChanged()
代替
notifyDataSetValidated()

您的问题是什么?当我选择该列表中的任何单选按钮时,Listview的滚动位置将变为初始状态。虽然这仍然不是问题,但我注意到您正在使数据集无效,而不仅仅是通知适配器。也许就是这样?
CustomersDialog dialog = new CustomersDialog(getActivity());
                    dialog.createDialog();