在Android的列表视图卡翻转
我需要做一个视图是一个列表视图。这应该是EA自定义列表,因为我想触摸时列表中的每一个项目是一个图像视图whioch翻转显示的细节。
I need to make a View which is a list view. This is supposed to e a custom list as I want each item of the list to be an image view whioch when touched flips to show details.
我期待到每android的参考卡吸顶视图(使用片段),但我觉得我失去了一些东西非常关键,因为这感觉不对。下面是我的自定义适配器的code将显示在前端。我有一个关于如何将我翻转视图中的另一个疑问。不幸的是,andrdoid教程是不是非常有帮助。
I am looking into Card Filp view (using fragments) per the android reference but I feel I am missing something very crucial as this doesn't feel right. below is the code of my custom adapter that will display the front side. I have another doubt regarding how would I flip the view. Unfortunately the andrdoid tutorials are not very helpful
public class CustomCardAdapter extends ArrayAdapter<String> {
private int textViewResourceId;
private Context mContext;
private List<String> list;
private FragmentManager fm;
public CustomCardAdapter(FragmentManager fm, Context context, int textViewResourceId,
List<String> list) {
super(context, textViewResourceId, list);
mContext = context;
this.textViewResourceId = textViewResourceId;
this.list = list;
this.fm = fm;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = mInflater.inflate(textViewResourceId, parent);
fm.beginTransaction()
.add(R.id.rowItem, new CardFrontFragment())
.commit();
String frontText = list.get(position);
String bsckText = frontText+"...back side";
TextView tvFront = (TextView)rowView.findViewById(R.id.frontSide);
tvFront.setText(frontText);
return rowView;
}
}
/这将只显示,如果这项工作过,前插卡fragment.How做我炫的看法?这是怎么回事是通过附加一个onClickListner。
/this will only show, if this work ever, the front card fragment.How do i "flip" the view? is this going to be via attaching an onClickListner.
有没有人碰到这种prblem?任何帮助将是巨大的!
Has anyone come across this prblem? any help will be great!
请指教?
要了解怎样做我会做一个简单的例子来翻转无任何碎片和FragmentManager的意见。 然后在你的适配器的getView方法是这样的:
To understand what to do I would make a simple example to flip the views without any fragments and FragmentManager. Then your getView method in your adapter would look like this:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = mInflater.inflate(textViewResourceId, parent);
String frontText = list.get(position);
String backText = frontText+"...back side";
TextView tvFront = (TextView)rowView.findViewById(R.id.frontSide);
tvFront.setText(frontText);
// set View visible
tvFront.setVisibility(View.VISIBLE);
TextView tvBack = (TextView)rowView.findViewById(R.id.backSide);
tvBack.setText(backText);
// disable visiblity of view
tvBack.setVisibility(View.GONE);
// add both textViews to your row:
rowView.removeAllViews();
rowView.addView(tvFront);
rowView.addView(tvBack);
// now set a clickListener to your row
rowView.setOnClickListener(new MyFlipListener(tvFront, tvBack));
return rowView;
}
class MyFlipListener implements OnClickListener{
TextView mTvFront;
TextView mTvBack;
public MyFlipListener(TextView tvFront, TextView tvBack){
mTvFront = tvFront;
mTvBack = tvBack;
}
@Override
public void onClick(){
// check which text is actually shown and make your changes
if(mTvFront.isVisible){
mTvFront.setVisibility(View.GONE);
mTvBack.setVisibility(View.VISIBLE);
}else{
mTvFront.setVisibility(View.VISIBLE);
mTvBack.setVisibility(View.GONE);
}
}
}
要使用你的片段,我会用同样的方式:
To use your Fragments I would use the same way:
- 先添加到每个rowItem您CardFrontFragment
- ,然后添加到您的rowItem一个clickListener调用flipCard()
我看到这里的问题是,你需要一个唯一的ID为每个的listItem否则你FragmentManager不知道哪个CardFrontFragment已被翻转(上例中只有一个CardFrontFragment和CardBacktFragment - 但是你有多个CardFrontFragment和CardBackFragment)。 几个星期前,我试着用一个GridView类似的东西。但是,这并不为我工作,所以我采取与欣赏其他的解决办法。
The problem I see here is that you need a unique id for each listItem otherwise your FragmentManager doesn't know which CardFrontFragment has to be flipped (the example shows just one CardFrontFragment and CardBacktFragment - however you have multiple CardFrontFragment and CardBackFragment). A few weeks ago I tried something similar with a GridView. But it didn't work for me, so I take the other solution with the views.
我希望这将帮助你:)