实际上,我想使用这个库“Aphid-FlipView-Library”来做一个翻转动画。我要翻转的图片和文字来自Parse.com。我已经可以使用下面的方式翻转图像了。
这是代码。在活动的前半部分,我将从parse.com检索到的图像添加到名为notes的arraylist中,并在适配器中使用它。
@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
}
}
});
}
然后,作为适配器的活动的后半部分显示如下。
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;
}
}
我可以显示图像。我想用相同的方式显示图像附近的文本,但是在添加@@@和@@@中保存的代码后出现错误。请帮我说清楚。
这是日志,
08-22 04:11:55.348: E/AndroidRuntime(3756): FATAL EXCEPTION: main
08-22 04:11:55.348: E/AndroidRuntime(3756): junit.framework.AssertionFailedError: Invalid selection position
08-22 04:11:55.348: E/AndroidRuntime(3756): at junit.framework.Assert.fail(Assert.java:50)
08-22 04:11:55.348: E/AndroidRuntime(3756): at junit.framework.Assert.assertTrue(Assert.java:20)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.aphidmobile.flip.FlipViewController.setSelection(FlipViewController.java:312)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.aphidmobile.flip.FlipViewController.onDataChanged(FlipViewController.java:606)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.aphidmobile.flip.FlipViewController.access$2(FlipViewController.java:596)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.aphidmobile.flip.FlipViewController$MyDataSetObserver.onChanged(FlipViewController.java:613)
08-22 04:11:55.348: E/AndroidRuntime(3756): at android.database.DataSetObservable.notifyChanged(DataSetObservable.java:37)
08-22 04:11:55.348: E/AndroidRuntime(3756): at android.widget.BaseAdapter.notifyDataSetChanged(BaseAdapter.java:50)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.example.bookard.TestQAQActivity$NoteViewAdapter.setTexts(TestQAQActivity.java:100)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.example.bookard.TestQAQActivity$1.done(TestQAQActivity.java:58)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.example.bookard.TestQAQActivity$1.done(TestQAQActivity.java:1)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.parse.ParseTaskUtils$2$1.run(ParseTaskUtils.java:107)
08-22 04:11:55.348: E/AndroidRuntime(3756): at android.os.Handler.handleCallback(Handler.java:730)
08-22 04:11:55.348: E/AndroidRuntime(3756): at android.os.Handler.dispatchMessage(Handler.java:92)
08-22 04:11:55.348: E/AndroidRuntime(3756): at android.os.Looper.loop(Looper.java:137)
08-22 04:11:55.348: E/AndroidRuntime(3756): at android.app.ActivityThread.main(ActivityThread.java:5103)
08-22 04:11:55.348: E/AndroidRuntime(3756): at java.lang.reflect.Method.invokeNative(Native Method)
08-22 04:11:55.348: E/AndroidRuntime(3756): at java.lang.reflect.Method.invoke(Method.java:525)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
08-22 04:11:55.348: E/AndroidRuntime(3756): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-22 04:11:55.348: E/AndroidRuntime(3756): at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
在适配器中,texts
应为ArrayList<String>
,而不是ArrayList<Bitmap>
。我不知道这是否有问题,但肯定是个问题。