作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 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/
我在使用 android 连接到 php 的代码中出现错误。这是代码,错误发生在加载 错误在于:(loadAllcars extends AsyncTask),这是我有错误的一些代码 load()
我是一名优秀的程序员,十分优秀!