Android listView不使用新值刷新

Android listView不使用新值刷新,android,android-listview,adapter,Android,Android Listview,Adapter,将列表视图从旧值刷新为新值时出现问题。 经过几个小时的搜索,我得到了那个适配器;必须使用。 但我无法理解我如何使用它,因为每当我使用它时,它都会给我一个错误 “类型ListAdapter的notifyDataSetChanged()方法未定义” 我不确定我做的事情是否正确。请帮忙 这是我的密码 public class Slider extends Activity implements OnClickListener, OnDrawerOpenListener, OnDrawerClo

将列表视图从旧值刷新为新值时出现问题。 经过几个小时的搜索,我得到了那个适配器;必须使用。 但我无法理解我如何使用它,因为每当我使用它时,它都会给我一个错误

“类型ListAdapter的notifyDataSetChanged()方法未定义”

我不确定我做的事情是否正确。请帮忙

这是我的密码

public class Slider extends Activity implements OnClickListener,
    OnDrawerOpenListener, OnDrawerCloseListener {

Button mCloseButton;
Button mOpenButton;
MultiDirectionSlidingDrawer mDrawer;
ListView list;
TextView t1;
String data, query, is;
Spinner d;
String FILENAME = "http://24.php";
ArrayList<String> pos;
ListAdapter adapter;
ArrayList<HashMap<String, String>> mylist;

HashMap<String, String> map;

static String j_id = null;
static Object j_make = null;
static String j_model = null;
static String j_version = null;
static String j_price = null;
static String j_reg_plc = null;

String ID = "car_id";
String MAKE = "make";
String MODEL = "model";
String VERSION = "version";
String PRICE = "expected_price";
String PLACE_REG = "registration_place";
CheckBox cb1, cb2, cb3, cb4, cb5, cb6, cb7, cb8, cb9, cb10;
Spinner sp1;
int flag = 0;
String drive[] = new String[] { "Select Drive", "Two-Wheel Drive",
        "Four-Wheel Drive", "All-Wheel Drive" };

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.slider);

    t1 = (TextView) findViewById(R.id.noRec);
    list = (ListView) findViewById(R.id.listView1);
    cb1 = (CheckBox) findViewById(R.id.checkBox1);
    cb2 = (CheckBox) findViewById(R.id.checkBox2);
    cb3 = (CheckBox) findViewById(R.id.checkBox3);
    cb4 = (CheckBox) findViewById(R.id.checkBox4);
    cb5 = (CheckBox) findViewById(R.id.checkBox5);
    cb6 = (CheckBox) findViewById(R.id.checkBox6);
    cb7 = (CheckBox) findViewById(R.id.checkBox7);
    cb8 = (CheckBox) findViewById(R.id.checkBox8);
    cb9 = (CheckBox) findViewById(R.id.checkBox9);
    cb10 = (CheckBox) findViewById(R.id.checkBox10);
    d = (Spinner) findViewById(R.id.drive);

    @SuppressWarnings("unchecked")
    ArrayAdapter spdrv = new ArrayAdapter(this,
            android.R.layout.simple_spinner_item, drive);
    d.setAdapter(spdrv);

    t1.setVisibility(View.GONE);
    mylist = new ArrayList<HashMap<String, String>>();

    pos = new ArrayList<String>();

    Bundle bundle = getIntent().getExtras();
    String stuff = bundle.getString("stuff");
    Toast.makeText(getApplicationContext(), "Stuff= |" + stuff + "|",
            Toast.LENGTH_LONG).show();

    if (stuff.contains("null")) {

        t1.setVisibility(View.VISIBLE);
        t1.setText("No Records Found");
        Toast.makeText(getApplicationContext(), "No Records Found!",
                Toast.LENGTH_LONG).show();

    } else {

        load_list(stuff);              //Load list with values

    }

    mCloseButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            flag = 1;
            query = "Select make, model, version, expected_price, registration_place FROM `used_cars` where registration_place ="
                    + "'" + j_reg_plc + "'";
            if (cb1.isChecked()) {
                query = query + " AND transmission ='Yes'";
            }
            if (cb2.isChecked()) {
                query = query + " AND ac ='Yes'";
            }
            if (cb3.isChecked()) {
                query = query + " AND car_lockk ='Yes'";
            }
            if (cb4.isChecked()) {
                query = query + " AND sunroof ='Yes'";
            }
            if (cb5.isChecked()) {
                query = query + " AND window ='Yes'";
            }
            if (cb6.isChecked()) {
                query = query + " AND seats ='Yes'";
            }
            if (cb7.isChecked()) {
                query = query + " AND stearing ='Yes'";
            }
            if (cb8.isChecked()) {
                query = query + " AND player ='Yes'";
            }

            if (cb9.isChecked()) {
                query = query + " AND sound_system ='Yes'";
            }
            if (cb10.isChecked()) {
                query = query + " AND wheels ='Yes'";
            }
            query = query + ";";

            Toast.makeText(getApplicationContext(), "QUERY= " + query,
                    Toast.LENGTH_LONG).show();
            System.out.println("QUERY= " + query);
            startDownload();

            mDrawer.animateClose();
        }
    });

    mOpenButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!mDrawer.isOpened())
                mDrawer.animateOpen();

        }
    });

}

private void startDownload() {

    new AppTask().execute(FILENAME);
}

public class AppTask extends AsyncTask<String, Integer, String> {

    @Override
    protected void onPreExecute() {
        super.onPreExecute();

    }

    protected void onPostExecute(String result) {
        super.onPostExecute(result);
        Toast.makeText(getApplicationContext(), "res" + result,
                Toast.LENGTH_LONG).show();
        pos = new ArrayList<String>();

        mylist.clear();
        load_list(result);         //Refresh list with new values

    }

    @Override
    protected void onProgressUpdate(Integer... values) {
        super.onProgressUpdate(values);

    }

    @Override
    protected String doInBackground(String... params) {

        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://animsinc.com/filter.php");
        try {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(
                    5);
            nameValuePairs.add(new BasicNameValuePair("Qry", query));

            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            httpclient.execute(httppost);
            HttpResponse response = httpclient.execute(httppost);

            HttpEntity entity = response.getEntity();
            is = EntityUtils.toString(entity);

        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
        }

        return is;
    }

}

@Override
public void onContentChanged() {
    super.onContentChanged();
    mCloseButton = (Button) findViewById(R.id.button_close);
    mOpenButton = (Button) findViewById(R.id.button_open);
    mDrawer = (MultiDirectionSlidingDrawer) findViewById(R.id.drawer);
}

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub

}

@Override
public void onDrawerClosed() {
    // TODO Auto-generated method stub
    // demo.setVisibility(View.VISIBLE);
}

@Override
public void onDrawerOpened() {
    // TODO Auto-generated method stub
    // demo.setVisibility(View.GONE);
}

public void load_list(String lt) {

    // list.setAdapter(null);

    Toast.makeText(getApplicationContext(), "Inside load_list", 100).show();
    try {

        JSONArray jArray = new JSONArray(lt.toString());

        for (int i = 0; i < jArray.length(); i++) {
            Toast.makeText(getApplicationContext(),
                    "Inside load_list----FOR", 100).show();
            map = new HashMap<String, String>();
            JSONObject jObject = jArray.getJSONObject(i);
            j_id = jObject.getString(ID);
            j_make = jObject.getString(MAKE);
            j_model = jObject.getString(MODEL);
            j_version = jObject.getString(VERSION);
            j_price = jObject.getString(PRICE);
            j_reg_plc = jObject.getString(PLACE_REG);

            data = j_make + "";
            map.put("make", data);

            data = j_model + "";
            map.put("model", data);

            data = j_version + "";
            map.put("version", data);

            data = j_price + "";
            map.put("price", data);

            data = j_reg_plc + "";
            map.put("place", data);

            mylist.add(map);
            pos.add(j_id);

        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    list = (ListView) findViewById(R.id.listView1);

    String[] from = new String[] { "make", "model", "version", "price",
            "place" };
    int[] to = new int[] { R.id.text1, R.id.text5, R.id.text3, R.id.text4,
            R.id.text2 };
    adapter = new SimpleAdapter(this, mylist, R.layout.text_adaptr, from,
            to);
    Toast.makeText(getApplicationContext(), "B4 list setAdapter", 100)
            .show();

    // mylist.notifyDataSetChanged();

    list.setAdapter(adapter);

    // ---------------------------------

    int[] colors = { 0, 0xff00ffff, 0 }; // red for the example
    list.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
    list.setDividerHeight(4);
    list.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {

            String data = pos.get(position) + "";

            Toast.makeText(getApplicationContext(), "data: " + data,
                    Toast.LENGTH_LONG).show();

            // Display_Car dc=new Display_Car();
            // dc.get_cid(data);
            Intent myIntent = new Intent(Slider.this, Buy_View.class);
            Bundle bundle = new Bundle();
            // Add your data to bundle
            bundle.putString("stuff", data);
            // Add the bundle to the intent
            myIntent.putExtras(bundle);
            startActivity(myIntent);

        }
    });
    // ---------------------------------
}

}
公共类滑块扩展活动实现OnClickListener,
OnDrawerOpenListener,OnDrawerCloseListener{
按钮mclose按钮;
按钮MOPENBUTON;
多向滑轨抽屉;
列表视图列表;
文本视图t1;
字符串数据,查询,是;
旋转器d;
字符串文件名=”http://24.php";
arraylistpos;
列表适配器;
ArrayList mylist;
HashMap图;
静态字符串j_id=null;
静态对象j_make=null;
静态字符串j_model=null;
静态字符串j_version=null;
静态字符串j_price=null;
静态字符串j_reg_plc=null;
String ID=“car\u ID”;
字符串MAKE=“MAKE”;
字符串MODEL=“MODEL”;
String VERSION=“VERSION”;
String PRICE=“预期价格”;
String PLACE_REG=“注册地点”;
复选框cb1、cb2、cb3、cb4、cb5、cb6、cb7、cb8、cb9、cb10;
Spinner sp1;
int标志=0;
字符串驱动[]=新字符串[]{“选择驱动”、“两轮驱动”,
“四轮驱动”、“全轮驱动”};
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
requestWindowFeature(窗口。功能\u无\u标题);
setContentView(R.layout.slider);
t1=(TextView)findViewById(R.id.noRec);
列表=(ListView)findViewById(R.id.listView1);
cb1=(复选框)findViewById(R.id.checkBox1);
cb2=(复选框)findViewById(R.id.checkBox2);
cb3=(复选框)findViewById(R.id.checkBox3);
cb4=(复选框)findViewById(R.id.checkBox4);
cb5=(复选框)findViewById(R.id.checkBox5);
cb6=(复选框)findViewById(R.id.checkBox6);
cb7=(复选框)findViewById(R.id.checkBox7);
cb8=(复选框)findViewById(R.id.checkBox8);
cb9=(复选框)findViewById(R.id.checkBox9);
cb10=(复选框)findViewById(R.id.checkBox10);
d=(微调器)findViewById(R.id.drive);
@抑制警告(“未选中”)
ArrayAdapter spdrv=新的ArrayAdapter(此,
android.R.layout.simple\u微调器(项目、驱动器);
d、 设置适配器(spdrv);
t1.设置可见性(视图已消失);
mylist=新的ArrayList();
pos=新的ArrayList();
Bundle Bundle=getIntent().getExtras();
String stuff=bundle.getString(“stuff”);
Toast.makeText(getApplicationContext(),“Stuff=|“+Stuff+”|“,
Toast.LENGTH_LONG).show();
if(stuff.contains(“null”)){
t1.设置可见性(视图可见);
t1.setText(“未找到记录”);
Toast.makeText(getApplicationContext(),“未找到任何记录!”,
Toast.LENGTH_LONG).show();
}否则{
加载列表(stuff);//加载带值的列表
}
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
flag=1;
query=“从‘二手车’中选择品牌、型号、版本、预期价格、注册地点,其中注册地点=”
+““+j_reg_plc+””;
if(cb1.isChecked()){
query=query+“和传输='Yes'”;
}
if(cb2.isChecked()){
query=query+“和ac='Yes'”;
}
if(cb3.isChecked()){
query=query+“和car_lock='Yes'”;
}
if(cb4.isChecked()){
query=query+“和class='Yes'”;
}
如果(cb5.isChecked()){
query=query+“和window='Yes'”;
}
如果(cb6.isChecked()){
query=query+“和seats='Yes'”;
}
如果(cb7.isChecked()){
query=query+“和steering='Yes'”;
}
如果(cb8.isChecked()){
query=query+“和player='Yes'”;
}
if(cb9.isChecked()){
query=query+“并发出声音”\u system='Yes';
}
如果(cb10.isChecked()){
query=query+“AND='Yes'”;
}
查询=查询+“;”;
Toast.makeText(getApplicationContext(),“QUERY=“+QUERY,
Toast.LENGTH_LONG).show();
System.out.println(“QUERY=“+QUERY”);
startDownload();
mDrawer.animateClose();
}
});
setOnClickListener(新的OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(!mDrawer.isOpened())
mDrawer.animateOpen();
}
});
}
私有void startDownload(){
新建AppTask().execute(文件名);
}
公共类AppTask扩展了AsyncTask{
@凌驾
受保护的void onPreExecute(){
super.onPreExecute();
}
受保护的void onPostExecute(字符串结果){
super.onPostExecute(结果);
Toast.makeText(getApplicationContext(),“res”+结果,
Toast.LENGTH_LONG).show();
pos=新的ArrayList();
mylist.clear();
加载列表(结果);//用新值刷新列表
}
@凌驾
受保护的void onProgressUpdate(整型…值){
super.onProgressUpdate(值);
}
@凌驾
受保护的字符串doInBackground(字符串…参数){
HttpClient HttpClient=新的DefaultHttpClient();
HttpPost HttpPost=新的HttpPost(“http://animsinc.com/filter.php");
试一试{
List name valuepairs=new ArrayList(
5);
添加(新的BasicNameValuePair(“Qry”,查询));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
httpclient.execute(httppost);
HttpResponse
runOnUiThread(new Runnable() {
public void run() {
    adapter.notifyDataSetChanged();
 }
});
list.setAdapter(adapter);
adapter.notifyDatasetChanged();
((ItemArrayAdapter)lv.getAdapter()).notifyDataSetChanged() instead of adapter.notifyDataSetChanged()
ListAdapter adapter;
BaseAdapter adapter;