2015-03-13 132 views
0

我試圖查詢基於一個字符串變量,而不是一個字符串值的parse.com表..Parse.com查詢字符串變量值

下面的作品,是什麼就是一個例子搜索。但

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

,而不是這個,我存儲在一個變量從微調..

query.whereEqualTo("movieCategory", derrick); 

我可以訪問此變量的其他方法就好了..除了解析查詢

想象變量「井架」包含另一個字符串,如「顫慄」

任何想法如何我可以實現這一點,而不是被限制爲我特別想要搜索?

的應用程序崩潰和的抱怨「android.view.WindowLeaked:」

我需要做它,就好像derrick.equals(「行動」),否則,如果derrick.equals(「浪漫」 )等...?因爲當我試圖發生同樣的崩潰。

在此先感謝

編輯

這是我DashboardActivity.class給我帶來了變量...

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

     return whatCategory; 
    } 

下面是從ResultsActivity整個try方法.class

// 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 
+0

什麼'derrick'? – 2015-03-13 17:10:25

+0

我不認爲'android.view.WindowLeaked'崩潰的應用程序。這可能是其他事情導致崩潰 – hoomi 2015-03-13 17:10:49

+0

@hoomi也許你是對的,但如果我直接搜索字符串像「動作」,我的功能工作.. – 2015-03-13 17:16:30

回答

1

你不能只是實例化一個新的活動,然後使用findViewById()。如果你的AsyncTask是你Activity的一部分,你應該可以調用DashboardActivity.this。 getCategory()代替。

剛纔看到有另一個活動涉及你沒有顯示,我不知道如何從DashboardActivity啓動ResultActivity。當您啓動ResultActivity時,您可能必須將該類別作爲額外項目傳遞。

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();