Parse.com查询字符串变量值

时间:2015-03-13 17:07:49

标签: android variables android-asynctask parse-platform

我正在尝试根据字符串变量的值而不是字符串来查询parse.com表。

以下内容有效,是搜索内容的一个示例。

query.whereEqualTo("movieCategory", "Action");

但是我没有将这个变量存储在Spinner中。

query.whereEqualTo("movieCategory", derrick);

我可以从其他方法中访问这个变量..除了解析查询

想象一下变量“derrick”包含另一个字符串,例如“Thriller”

关于如何实现这一目标的任何想法,而不是受限于我特别想要搜索的内容?

应用程序崩溃并抱怨“android.view.WindowLeaked:”

我是否需要像derrick.equals(“action”)那样做,否则如果derrick.equals(“浪漫”)等......?因为当我尝试同样的崩溃时。

提前致谢

修改

这是我的DashboardActivity.class,我正在获取变量......

public String getCategory() {
        Spinner spinCategory = (Spinner) findViewById(R.id.spin_category);
        String whatCategory = spinCategory.getSelectedItem().toString();

        return whatCategory;
    }

以下是ResultsActivity.class

中的整个try方法
// RemoteDataTask AsyncTask
    private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            // Create a progressdialog
            mProgressDialog = new ProgressDialog(ResultsActivity.this);
            // Set progressdialog title
            mProgressDialog.setTitle("");
            // Set progressdialog message
            mProgressDialog.setMessage("Loading...");
            mProgressDialog.setIndeterminate(false);
            // Show progressdialog
            mProgressDialog.show();
        }

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

            DashboardActivity  cls2= new DashboardActivity();
            cls2.getCategory();
            String derrick = cls2.getCategory();

            // Create the array
            movielist = new ArrayList<movieListGroup>();

            try {
                // Locate the class table named "Movie" in Parse.com
                ParseQuery<ParseObject> query = new ParseQuery<ParseObject>(
                        "Movie");

                query.whereEqualTo("movieCategory", derrick);

//                if (derrick.equals ("Action")) {
//                    query.whereEqualTo("movieCategory", "Action");
//
//                } else if (derrick.equals ("Romance")) {
//                    query.whereEqualTo("movieCategory", "Romance");
//
//                } else if (derrick.equals("Comedy")) {
//                    query.whereEqualTo("movieCategory", "Comedy");
//
//                }

                //query.whereEqualTo("movieCategory", "Romance");
                query.orderByAscending("movieNum");

                ob = query.find();
                for (ParseObject movie : ob) {
                    // Locate images in flag column
                    ParseFile image = (ParseFile) movie.get("movieImage");

                    movieListGroup map = new movieListGroup();
                    map.setNumber((String) movie.get("movieNum"));
                    map.setCategory((String) movie.get("movieCategory"));
                    map.setTitle((String) movie.get("movieTitle"));
                    map.setDescription((String) movie.get("movieDesc"));
                    map.setDirector((String) movie.get("movieDirector"));
                    map.setFlag(image.getUrl());
                    movielist.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 ListViewAdapter(ResultsActivity.this,
                    movielist);
            // Binds the Adapter to the ListView
            listview.setAdapter(adapter);
            // Close the progressdialog
            mProgressDialog.dismiss();
        }
    }

和原木猫.....

03-13 17:40:52.575    5980-5980/com.example.derrick.moveed E/WindowManager﹕ android.view.WindowLeaked: Activity com.example.derrick.moveed.ResultsActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView{339cf210 V.E..... R.....ID 0,0-1026,288} that was originally added here
            at android.view.ViewRootImpl.<init>(ViewRootImpl.java:363)
            at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:261)
            at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
            at android.app.Dialog.show(Dialog.java:298)
            at com.example.derrick.moveed.ResultsActivity$RemoteDataTask.onPreExecute(ResultsActivity.java:77)
            at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
            at android.os.AsyncTask.execute(AsyncTask.java:535)
            at com.example.derrick.moveed.ResultsActivity.onCreate(ResultsActivity.java:61)
            at android.app.Activity.performCreate(Activity.java:5933)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
            at android.app.ActivityThread.access$800(ActivityThread.java:144)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:135)
            at android.app.ActivityThread.main(ActivityThread.java:5221)
            at java.lang.reflect.Method.invoke(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:372)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
03-13 17:40:59.376    5980-6003/com.example.derrick.moveed I/Process﹕ Sending signal. PID: 5980 SIG: 9

2 个答案:

答案 0 :(得分:1)

您不能仅使用new实例化Activity,然后使用findViewById()。如果您的AsyncTask是您的Activity的一部分,您应该能够调用DashboardActivity.this。取而代之的是getCategory()。

刚看到还有另一个Activity没有显示,我不确定如何从DashboardActivity启动ResultActivity。启动ResultActivity时,您可能必须将该类别作为额外内容传递。

答案 1 :(得分:0)

试试这个,它帮助了我,我也遇到了同样的错误。

private class RemoteDataTask extends AsyncTask<Void, Void, Void> {
     ProgressDialog mProgressDialog ;
    Context c;
     public RemoteDataTask(Context c){
    this.c =c;
    }
     @Override
            protected void onPreExecute() {
                super.onPreExecute();
                // Create a progressdialog
                mProgressDialog = new ProgressDialog(ResultsActivity.this);
                // Set progressdialog title
    ........
    }

    }

现在正在调用此任务:

new RemoteDataTask(MainActivity.this).execute();