本文介绍了Android的retreiving图片和文字从parse.com和适配器使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其实,我想使用这个库蚜虫FlipView库做翻转的动画。我想翻转图像和文字来自Parse.com。我已经可以通过以下方式联系翻转图像。


这里是个code.First一半的活动,我添加了从parse.com retreived的图像转换成一个ArrayList所谓的笔记,并在适配器中使用它。

Actually, I want to use this library"Aphid-FlipView-Library"to do an animation of flipping. The images and texts I want to flip are from Parse.com. I've already could flip the images by using the way below.

Here is th code.First half of the activity, I add the images which retreived from parse.com into an arraylist called notes and use it in an adapter.

@Override
protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.rotate);
   FlipViewController flipView = new FlipViewController(this, FlipViewController.HORIZONTAL);
   final NoteViewAdapter mAdapter = new NoteViewAdapter(this);
   flipView.setAdapter(mAdapter);
   setContentView(flipView);  
   final ArrayList<Bitmap> notes = new ArrayList<Bitmap>();
   @@@final ArrayList<String> texts = new ArrayList<String>();@@@

   ParseQuery<ParseObject> query = new ParseQuery<ParseObject>("Card");
   query.getInBackground("wxYBHhRlhZ", new GetCallback<ParseObject>() {

       @Override
       public void done(ParseObject object, ParseException e) {
         if(e == null){
           ParseFile fileObject1 = (ParseFile) object.get("Photoin1");
           fileObject1.getDataInBackground(new GetDataCallback(){

               @Override
               public void done(byte[] data, ParseException e) {
                     notes.add(BitmapFactory.decodeByteArray(data,0,data.length));
                     mAdapter.setNotes(notes);
               }
           });
           @@@String playerName = object.getString("Textin1");@@@
           @@@texts.add(playerName);@@@
           @@@mAdapter.setTexts(texts);@@@
         }else{
             //nothing
         }  
       }
   });    
}

然后,这是一个适配器活动的下半年,显示如下。

And then, second half of the activity that is a adapter is showed below.

public class NoteViewAdapter extends BaseAdapter {
    private LayoutInflater inflater;        
    private ArrayList<Bitmap> notes;
    @@@private ArrayList<String> texts;@@@     

    public NoteViewAdapter(Context currentContext) {
        inflater = LayoutInflater.from(currentContext);        
    }

    @Override
    public int getCount() {
        return notes == null ? 0 : notes.size()
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setNotes(ArrayList notes) {
        this.notes = notes;
        notifyDataSetChanged();
    }
    @@@public void setTexts(ArrayList texts) {@@@
    @@@    this.texts = texts;                @@@
    @@@    notifyDataSetChanged();            @@@
    @@@}                                      @@@
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View layout = convertView;

        if (convertView == null) {
            layout = inflater.inflate(R.layout.rotate, null);
        }            


        Bitmap note = notes.get(position);
        @@@String text = texts.get(position);@@@

        ImageView tView = (ImageView) layout.findViewById(R.id.picture);
        @@@TextView view = (TextView) layout.findViewById(R.id.text);@@@   

        tView.setImageBitmap(note);
        @@@view.setText(text);@@@

        return layout;
    }
}

我可以告诉already.I希望通过使用同样的方式来显示附近图像文字的形象,但我得到了错误后,我添加了code,在@@@,并举行###。请帮我说清楚。

I could show the image already.I want to show the texts near by the image by using the same way, but I got the error after I add the code that held in @@@ and @@@. Please help me to make it clear.

下面是日志,

4月8日至22日:11:55.348:E / AndroidRuntime(3756):致命异常:主要
4月8日至22日:11:55.348:E / AndroidRuntime(3756):junit.framework.AssertionFailedError:无效的选择位置
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在junit.framework.Assert.fail(Assert.java:50)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在junit.framework.Assert.assertTrue(Assert.java:20)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.aphidmobile.flip.FlipViewController.setSelection(FlipViewController.java:312)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.aphidmobile.flip.FlipViewController.onDataChanged(FlipViewController.java:606)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.aphidmobile.flip.FlipViewController.access $ 2(FlipViewController.java:596)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.aphidmobile.flip.FlipViewController $ MyDataSetObserver.onChanged(FlipViewController.java:613)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.example.bookard.TestQAQActivity $ NoteViewAdapter.setTexts(TestQAQActivity.java:100)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.example.bookard.TestQAQActivity $ 1.done(TestQAQActivity.java:58)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.example.bookard.TestQAQActivity $ 1.done(TestQAQActivity.java:1)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.parse.ParseTaskUtils $ 2 $ 1.run(ParseTaskUtils.java:107)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在android.os.Handler.handleCallback(Handler.java:730)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在android.os.Handler.dispatchMessage(Handler.java:92)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在android.os.Looper.loop(Looper.java:137)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在android.app.ActivityThread.main(ActivityThread.java:5103)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在java.lang.reflect.Method.invokeNative(本机方法)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在java.lang.reflect.Method.invoke(Method.java:525)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:737)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
4月8日至22日:11:55.348:E / AndroidRuntime(3756):在dalvik.system.NativeStart.main(本机方法)

推荐答案

在适配器,文本应该是的ArrayList&LT;弦乐&GT; ,而不是的ArrayList&LT;&位图GT; 。我不知道如果这能解决,但肯定是一个问题。

In the adapter, texts should be an ArrayList<String>, not an ArrayList<Bitmap>. I don't know if this fixes but surely is an issue.

这篇关于Android的retreiving图片和文字从parse.com和适配器使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 08:25