【发布时间】:2015-07-19 08:34:43
【问题描述】:
我正在使用解析数据填充列表视图,并且正在查询数据。我只想显示等于来自另一个活动的字符串的行。
我得到了字符串,因为我有一个显示字符串的 toast,但是 query.whereEqualTo 中的字符串是无效的。
如何在 doInBackground 中传递字符串变量的值?
这是我的代码,
公共类 ListadoMusica 扩展 Activity {
String año; String artista; // Declare Variables ListView listview; List<ParseObject> ob; ProgressDialog mProgressDialog; CustomAdapter adapter; private List<Musica> musica = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get the view from listview_main.xml setContentView(R.layout.activity_listado_musica); año = getIntent().getStringExtra("myaño"); artista = getIntent().getStringExtra("myartista"); Toast.makeText(getApplicationContext(),año, Toast.LENGTH_SHORT).show(); // Execute RemoteDataTask AsyncTask new RemoteDataTask().execute(); } // RemoteDataTask AsyncTask private class RemoteDataTask extends AsyncTask<Void, Void, Void> { @Override protected void onPreExecute() { super.onPreExecute(); // Create a progressdialog mProgressDialog = new ProgressDialog(ListadoMusica.this); // Set progressdialog title mProgressDialog.setTitle("Cargando..."); // Set progressdialog message mProgressDialog.setMessage("Loading..."); mProgressDialog.setIndeterminate(false); // Show progressdialog mProgressDialog.show(); } @Override protected Void doInBackground(Void... params) { // Create the array musica = new ArrayList<Musica>(); try { // Locate the class table named "Country" in Parse.com ParseQuery<ParseObject> query = new ParseQuery<ParseObject>( "Musica"); // Locate the column named "ranknum" in Parse.com and order list // by ascending //query.orderByAscending("createdAt"); query.whereEqualTo("año", año); query.whereEqualTo("artista", artista); ob = query.find(); for (ParseObject country : ob) { // Locate images in flag column ParseFile image = (ParseFile) country.get("imagen"); Musica map = new Musica(); map.setTitulo((String) country.get("titulo")); map.setArtista((String) country.get("artista")); map.setAño((String) country.get("año")); map.setFoto(image.getUrl()); musica.add(map); } } catch (ParseException e) { Log.e("Error", e.getMessage()); e.printStackTrace(); } return null; } @Override protected void onPostExecute(Void result) { // Locate the listview in listview_main.xml listview = (ListView) findViewById(R.id.listview); // Pass the results into ListViewAdapter.java adapter = new CustomAdapter(ListadoMusica.this, musica); // Binds the Adapter to the ListView listview.setAdapter(adapter); // Close the progressdialog mProgressDialog.dismiss(); } }}
提前致谢,
【问题讨论】:
标签: android listview parse-platform android-asynctask