2013-12-10 104 views
2

我正在做的一個應用我試圖填充listView與從parse.com獲得的數據使用自定義parsequeryadapter子類。基本上它只是在打開活動時顯示空白活動。Android ListView沒有被自定義ParseQueryAdapter填充

適配器代碼

package com.example.battlesim; 

import java.util.ArrayList; 
import java.util.List; 

import android.content.Context; 
import android.util.Log; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.TextView; 

import com.parse.FindCallback; 
import com.parse.ParseException; 
import com.parse.ParseQuery; 
import com.parse.ParseQueryAdapter; 
import com.parse.ParseObject; 

public class LeaderboardAdapter extends ParseQueryAdapter<ParseObject> { 
    public Context context; 

    public LeaderboardAdapter(Context c) { 
     super(c, new ParseQueryAdapter.QueryFactory<ParseObject>(){ 


      public ParseQuery<ParseObject> create(){ 
//   public final ArrayList<String> leadersName; 
//   public final ArrayList<Integer> leadersScore; 
      ParseQuery<ParseObject> queryL = ParseQuery.getQuery("Character"); 
      queryL = queryL.whereNotEqualTo("name", null); 
      queryL = queryL.orderByDescending("level"); 
      queryL.setLimit(10); 
      try { 
       queryL.find(); 
      } catch (ParseException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 

      return queryL; 

//   queryL.findInBackground(new FindCallback<ParseObject>() { 
//    public void done(List<ParseObject> scoreList, ParseException e) { 
//     if (e == null) { 
//      for(int i = 0; i < 10; i++){ 
//       leadersName.add(scoreList.get(i).getString("name")); 
//       leadersScore.add(scoreList.get(i).getInt("level")); 
//      } 
//     } else { 
//      Log.d("level", "Error: " + e.getMessage()); 
//     } 
//    } 

      } 
     }); 
     this.context = c; 
    } 



    public View getItemView(ParseObject o, View convertView, ViewGroup parent){ 
     View vi = convertView; 
     if(convertView == null) vi = View.inflate(getContext(), R.layout.board, null); 
     super.getItemView(o, convertView, parent); 
     TextView name = (TextView) vi.findViewById(R.id.name); 
     TextView level = (TextView) vi.findViewById(R.id.level); 

     name.setText(o.getString("name")); 
     level.setText(o.getInt("level")); 

     return vi; 
    } 

} 

活動的onCreate代碼

LeaderboardAdapter adapter = new LeaderboardAdapter(this); 
    adapter.loadObjects(); 

    ListView lv = (ListView) findViewById(R.id.listView1); 
    lv.setAdapter(adapter); 

Board.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <TextView 
     android:id="@+id/name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:text="TextView" 
     android:textSize="25dip"/> 

    <TextView 
     android:id="@+id/level" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignParentTop="true" 
     android:text="TextView" 
     android:textSize="25dip"/> 

</RelativeLayout> 

索爾如果我格式化了任何奇怪的東西或忘記包含任何東西。我是新來StackExchange和有些新的程序設計的Android

+0

你可以在這裏提供任何錯誤消息? – kgdesouz

+0

不幸的是,鑑於當前的代碼沒有錯誤消息。至少不是我所知道的,因爲代碼不會導致應用程序崩潰。我應該嘗試在代碼中的某處放置日誌消息,以查看哪些內容不起作用?如果是這樣,那麼最適合放哪個的地方呢? – natemccord

+0

我會在程序開始附近設置一個斷點。然後F6(逐步),直到你沒有看到你想要的結果。 F5,如果你想深入挖掘代碼。請注意,您也可以在代碼中放置調試行,但不要依賴於此,因爲您無法真正瞭解發生了什麼;調試器是你的朋友。 – kgdesouz

回答

1

更換queryL.whereNotEqualTo("name", null);queryL.whereExists("name");