gpt4 book ai didi

android - 使用 android 和 parse.com 进行缓慢的数据检索

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:26:35 25 4
gpt4 key购买 nike

我正在使用 parse.com 检索数据以供我的应用程序使用。问题是下载需要大约一分钟,而且只有 4 个小图像 (380x380) 和一个名称。这是我的代码:

package com.favega.groups;

import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;

import com.parse.*;

public class MainActivity extends ActionBarActivity implements CategoryFragment.OnFragmentInteractionListener, EventFragment.OnFragmentInteractionListener{

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

Parse.initialize(this, "xxxxxxxxxxx", "xxxxx");
ParseAnalytics.trackAppOpened(getIntent());
ParseObject.registerSubclass(Category.class);
ParseObject.registerSubclass(Event.class);

if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new CategoryFragment())
.commit();
}
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}

@Override
public void onFragmentInteraction(Uri uri) {

}

@Override
public void onFragmentInteraction(String id) {

}
}

还有我的适配器:

package com.favega.groups;

import android.app.Activity;
import android.content.Context;
import android.graphics.Typeface;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.text.method.CharacterPickerDialog;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseQueryAdapter;
import com.squareup.picasso.Picasso;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class CategoryAdapter extends ParseQueryAdapter<Category>{

MainActivity mContext;

public CategoryAdapter(Context context) {
super(context, "Category");
this.mContext = (MainActivity) context;
}

@Override
public final View getItemView(final Category object, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = ((Activity) mContext).getLayoutInflater().inflate(R.layout.category, parent, false);
}
TextView categoryName = (TextView) convertView.findViewById(R.id.categoryName);
categoryName.setText(object.getName());
categoryName.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "fonts/Roboto-Light.ttf"));
final TextView eventNum = (TextView) convertView.findViewById(R.id.eventNum);
eventNum.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "fonts/Roboto-Light.ttf"));
ParseQuery<Event> query = ParseQuery.getQuery("Event");
query.whereEqualTo("parent", object);
query.findInBackground(new FindCallback<Event>() {
@Override
public void done(List<Event> events, ParseException e) {
eventNum.setText(events.size() + " " + mContext.getString(R.string.events));
notifyDataSetChanged();
}
});

SquareImageView imageView = (SquareImageView) convertView.findViewById(R.id.image);
Picasso.with(mContext).load(object.getImage().getUrl()).placeholder(new ColorDrawable(object.getColor())).into(imageView);
convertView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
FragmentTransaction fragmentTransaction = mContext.getSupportFragmentManager().beginTransaction();
Bundle args = new Bundle();
args.putString("ARGS_CATEGORY", object.getName());
EventFragment eventFragment = new EventFragment();
eventFragment.setArguments(args);
fragmentTransaction.replace(R.id.container, eventFragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
return convertView;
}
}

最佳答案

在 parse 中检索图像的更简单方法如下:

for(ParseObject obj : objects)
{
ParseFile file = obj.getParseFile("Column_Name");
try
{
Bitmap bit = BitmapFactory.decodeByteArray(file.getData(),0,file.getData().length);
}
catch(ParseException e1)
{}
}

这有助于我更快地下载图像。我建议将它放在 Asynctask 中

关于android - 使用 android 和 parse.com 进行缓慢的数据检索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20938831/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com