从parse.com下载一些数据时的进度条

时间:2013-12-17 13:25:33

标签: java android-listview android-progressbar

我在Android中很新,所以我的问题听起来很常见。我试图在从parse.com下载一些数据时使其显示为进度条,并在数据下载完成后使其消失并已在listView中显示。我查看了Parse中的文档,但我不清楚如何使用他们的工具。我知道我必须使用一些线程才能在后台进行工作,而不是忙于操作UI ..请看下面的代码并帮助我了解我的管理方式..

ListViewsAllReports

public class ListViewsAllReports extends Activity implements OnClickListener{

    Button aReportsBackButton;
    ListView aReports;
    lvAdapterAllReports lvAdapterAllReports;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_list_views_all_reports);

        Parse.initialize(this, "hm9VwSWl4hyrI1ZbkrvEXXkwdvXSxZLZYbheDaFs", "4BmzC3n9qrt0OhceQJ8yzp3iKrIU7rdsAhf2FSQW");

        setUpUI();

    }//onCreate

    public void setUpUI(){
        aReportsBackButton=(Button)findViewById(R.id.AllReportsBackButton);
        aReportsBackButton.setOnClickListener(this);

        aReports=(ListView)findViewById(R.id.AllReportsLV);
        lvAdapterAllReports = new lvAdapterAllReports(getApplicationContext(), "Animal");
        aReports.setAdapter(lvAdapterAllReports);
        registerForContextMenu(aReports);
    }//void setUpUI()

lvAdapterAllReports

public class lvAdapterAllReports extends ParseQueryAdapter<ParseObject>  {

    private Vector<Animal> animalList ;

    public lvAdapterAllReports(Context context, String className){
        super(context, className);

        animalList = new Vector<Animal>();

        ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Animal");
        query.findInBackground(new FindCallback<ParseObject>() {

            @Override
            public void done(List<ParseObject> objects, ParseException e) {
                // TODO Auto-generated method stub
                if (e == null) {
                    for (int i = 0; i < objects.size(); i++) {
                        Animal animal = new Animal();
                        animal.setValueFromParse(objects.get(i));
                        animalList.add(animal);
                    }//for
                }//if
            }//void done()
        });//anonymous class

    }//constructor

    public View getItemView(ParseObject object, View v, ViewGroup parent) {
        LinearLayout linearLayout;
        if (v == null) {
            linearLayout = (LinearLayout)View.inflate(getContext(), R.layout.mycasesviews, null);
        }
        else{
            linearLayout = (LinearLayout)v;
        }
        super.getItemView(object, v, parent);
        final Animal a = new Animal();
        a.setValueFromParse(object);


        ((TextView)linearLayout.findViewById(R.id.myCaseViewLostOrFound)).setText(a.getmLostOrFound());
        ((TextView)linearLayout.findViewById(R.id.myCaseViewAnimalType)).setText(a.getmType());
        ((TextView)linearLayout.findViewById(R.id.myCaseViewDate)).setText(a.getmDate()+"");
        ((Button)linearLayout.findViewById(R.id.myCaseViewContactButton)).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Intent intent = new Intent(getContext(), ContactOwner.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("UserId", a.getmOwnerId());
                getContext().startActivity(intent);

            }
        });


        final ImageView img = (ImageView)linearLayout.findViewById(R.id.myCaseViewImage);

        ParseFile fileImage = (ParseFile)object.getParseFile("Image");
        if (fileImage != null) {

            fileImage.getDataInBackground(new GetDataCallback() {

                @Override
                public void done(byte[] data, ParseException e) {
                    if (e==null) {
                        Bitmap resultImage = BitmapFactory.decodeByteArray(data, 0, data.length);
                        img.setImageBitmap(resultImage);                    
                    }//if
                }//done
            });//anonymous class
        }//if fileImage

        return linearLayout;
    }//getItemView




}//class

1 个答案:

答案 0 :(得分:0)

您可以实现onLoaded方法来实现:

lvAdapterAllReports.addOnQueryLoadListener(new OnQueryLoadListener<ParseObject>() {
   public void onLoading() {
   } 
   public void onLoaded(List<ParseObject> objects, ParseException e) {
      // Dismiss your Progress Bar here
   }
});