我的代码
NewsActivity
public class NewsActivity extends AppCompatActivity {Toolbar toolbar;// Progress Dialogprivate ProgressDialog pDialog;// Creating JsON Parser objectJsONParser jParser = new JsONParser();ArrayList<HashMap<String,String>> productsList;// url to get all products Listprivate static String url_all_products = "http://localhost/update.PHP";// JsON Node namesprivate static final String TAG_SUCCESS = "success";private static final String TAG_PRODUCTS = "updatedzc";private static final String TAG_PID = "pID";private static final String TAG_name = "name";private static final String TAG_VERSION = "version";private static final String TAG_DESC = "description";// products JsONArrayJsONArray products = null;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_news); // Hashmap for ListVIEw productsList = new ArrayList<HashMap<String,String>>(); // Loading products in Background Thread new LoadAllProducts().execute();}// Response from Edit Product Activity@OverrIDepublic 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); }}/** * Background Async Task to Load all product by making http Request * */class LoadAllProducts extends AsyncTask<String,String,String> { /** * Before starting background thread Show Progress Dialog * */ @OverrIDe protected voID onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(NewsActivity.this); pDialog.setMessage("Loading News. 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_products,"GET",params); // Check your log cat for JsON reponse Log.d("All Products: ",Json.toString()); try { // Checking for SUCCESS TAG int success = Json.getInt(TAG_SUCCESS); if (success == 1) { // products found // Getting Array of Products products = Json.getJsONArray(TAG_PRODUCTS); // looPing through All Products for (int i = 0; i < products.length(); i++) { JsONObject c = products.getJsONObject(i); // Storing each Json item in variable String ID = c.getString(TAG_PID); String name = c.getString(TAG_name); String version = c.getString(TAG_VERSION); String description = c.getString(TAG_DESC); // creating new HashMap HashMap<String,String> map = new HashMap<String,String>(); // adding each child node to HashMap key => value map.put(TAG_PID,ID); map.put(TAG_name,name); map.put(TAG_VERSION,version); map.put(TAG_DESC,description); // adding HashList to ArrayList productsList.add(map); } } else { Toast.makeText(getApplicationContext(),"doesn't have news Now",Toast.LENGTH_SHORT).show(); } } catch (JsONException e) { e.printstacktrace(); } return null; } /** * After completing background task dismiss the progress dialog * **/ protected voID onPostExecute(String file_url) { // dismiss the dialog after getting all products pDialog.dismiss(); // updating UI from Background Thread runOnUiThread(new Runnable() { public voID run() { /** * Updating parsed JsON data into ListVIEw * */ listadapter adapter = new SimpleAdapter( NewsActivity.this,productsList,R.layout.List_item,new String[] { TAG_PID,TAG_name,TAG_VERSION,TAG_DESC},new int[] { R.ID.pID,R.ID.name,R.ID.timestamp,R.ID.txtStatusMsg }); // updating ListvIEw setlistadapter(adapter); } }); }}}
得到错误
setlistadapter(adapter);
像这样的错误
Error:(182,21) error: cannot find symbol method setlistadapter(listadapter)
有人可以帮帮我吗?
解决方法 如果您的活动中包含以下ListVIEw<ListVIEw androID:ID="@+ID/mainListVIEw" androID:layout_height="fill_parent" androID:layout_wIDth="fill_parent" androID:layout_below="@ID/scan_content"/>
添加类似的东西
public ListVIEw mainListVIEw;
到NewsActivity和替换
setlistadapter(adapter);
同
mainListVIEw = (ListVIEw) findVIEwByID(R.ID.mainListVIEw); mainListVIEw.setAdapter(adapter);
除非我误解了这个问题,否则这应该有效.
总结以上是内存溢出为你收集整理的android – AppCompatActivity中的setListAdapter全部内容,希望文章能够帮你解决android – AppCompatActivity中的setListAdapter所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)