gpt4 book ai didi

android - 公共(public)类 loadAllcars 扩展 AsyncTask {

转载 作者:行者123 更新时间:2023-11-30 00:45:40 24 4
gpt4 key购买 nike

我在使用 android 连接到 php 的代码中出现错误。这是代码,错误发生在加载

错误在于:(loadAllcars extends AsyncTask),这是我有错误的一些代码

  load().execute()? 
public class loadAllcars extends AsyncTask<String, String, String> {

carsList = new ArrayList<HashMap<String, String>>();
new loadAllcarsActivity().excute();


ListView lv = getListView();

lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id){
// getting values from selected ListItem
String casrtype = ((TextView) view.findViewById(R.id.casrtype)).getText()

.toString();
Intent in = new Intent(getApplicationContext(),
AllcarsActivity.class);

in.putExtra(TAG_TYPE, casrtype);

// starting new activity and expecting some response back
startActivityForResult(in, 100);

}
});

} protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// if result code 100
if (resultCode == 100) {
// if result code 100 is received
// means user edited/deleted product
// reload this screen again
Intent intent = getIntent();
finish();
startActivity(intent);
}

公共(public)类 loadAllcars 扩展 AsyncTask {

        /**
* Before starting background thread Show Progress Dialog
* */
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(AllcarsActivity.this);
pDialog.setMessage("Loading products. Please wait...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();
}

/**
* getting All products from url
* */
protected String doInBackground(String... args) {
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
// getting JSON string from URL
JSONObject json = jParser.makeHttpRequest(url_all_cars, "GET", params);

// Check your log cat for JSON reponse
Log.d("All cars: ", json.toString());

try {
// Checking for SUCCESS TAG
int success = json.getInt(TAG_MODEL);

if (success == 1) {
// products found
// Getting Array of Products
cars = json.getJSONArray(TAG_CARS);

// looping through All Products
for (int i = 0; i <cars.length(); i++) {
JSONObject c =cars.getJSONObject(i);


String id = c.getString(TAG_TYPE);
String name = c.getString(TAG_CARS);

// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();

// adding each child node to HashMap key => value
map.put(TAG_CARSTYPE, type);
map.put(TAG_CARSMODEL, model);

// adding HashList to ArrayList
carsList.add(map);

}

最佳答案

当您延长AsyncTask时与 AsyncTask<String, String, String>确保 doInBackgrund 的参数应该是:

protected String doInBackground(String... params) {

和 onPostExecute 应该是

  protected void onPostExecute(String result) {

关于android - 公共(public)类 loadAllcars 扩展 AsyncTask<String, String, String> {,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21376272/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com