我有一个扩展BaseAdapter的ListView。我有一个数组列表。 ListView正确地膨胀和填充。我正在使用翻板视图将布局更改为另一个,但问题是当我点击它旋转的第一个项目但第三行或第六行的项目也将旋转 列表视图如何修复它我只希望图像是所选项目的更改
ArrayList<product_data> al=new ArrayList<product_data>();
class product_data
{
String post_title;
String newprice;
String oldprice;
String image;
String id;
product_data(String post_title,String newprice,String oldprice,String image,String id)
{
this.post_title=post_title;
this.newprice=newprice;
this.oldprice=oldprice;
this.image=image;
this.id=id;
}
}
在arraylist中添加数据
try {
JSONObject parentObject = new JSONObject(json.toString());
JSONObject userDetails = parentObject.getJSONObject("response");
JSONArray jarray=userDetails.getJSONArray("products_data");
for(int i=0;i<jarray.length();i++)
{
System.out.println("From the Dataaaa");
JSONObject c = jarray.getJSONObject(i);
String details=c.getString("details");
String image=c.getString("image");
String catagory=c.getString("catagory");
String new_price=c.getString("new_price");
String title=c.getString("title");
String id1=c.getString("id");
System.out.println("from ther first image"+image);
System.out.println("from the sdafdfadf"+details);
al.add(new product_data(title, new_price, new_price, image, id1));
适配器类
class MyAdapter extends BaseAdapter
{
@Override
public int getCount() {
// TODO Auto-generated method stub
return al.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return al.get(position);
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View singleView, ViewGroup parent) {
// TODO Auto-generated method stub
final int ok=position;
if(singleView==null)
{
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
singleView = inflater.inflate(R.layout.product_ist_layout,parent,false);
System.out.println("from the if"+position);
viewAnimator = (ViewAnimator)singleView.findViewById(R.id.viewFlipper);
rootLayout = (View)singleView.findViewById(R.id.main_activity_root);
cardFace = (View)singleView.findViewById(R.id.main_activity_card_face);
cardBack = (View) singleView.findViewById(R.id.main_activity_card_back);
}
System.out.println("from the else");
System.out.println("Position in else"+position);
product_data a=al.get(position);
TextView tv1=(TextView)singleView.findViewById(R.id.textView2);
TextView tv2=(TextView)singleView.findViewById(R.id.textView3);
TextView tv3=(TextView)singleView.findViewById(R.id.textView1);
/**
* Bind a click listener to initiate the flip transitions
*/
viewAnimator.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// This is all you need to do to 3D flip
AnimationFactory.flipTransition(viewAnimator, FlipDirection.LEFT_RIGHT);
}
});
cardFace.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("positon"+ok);
AnimationFactory.flipTransition(viewAnimator, FlipDirection.LEFT_RIGHT);
}
});
cardBack.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
AnimationFactory.flipTransition(viewAnimator, FlipDirection.LEFT_RIGHT);
}
});
imgview1=(ImageView)singleView.findViewById(R.id.imageView4);
imgview1.setTag(position);
imgview1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int position1=(Integer)v.getTag();
System.out.println(position1);
String id=al.get(position1).id;
System.out.println("id from the list"+id);
Intent in=new Intent(product_list_Activity.this,rating_dialog.class);
in.putExtra("id",id);
startActivity(in);
}
});
ImageView imgview2=(ImageView)singleView.findViewById(R.id.imageView5);
imgview2.setTag(position);
imgview2.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int position1=(Integer)v.getTag();
System.out.println(position1);
String id=al.get(position1).id;
System.out.println("id from the list"+id);
Intent in=new Intent(product_list_Activity.this,product_review.class);
in.putExtra("id",id);
startActivity(in);
}
});
tv3.setTag(position);
tv3.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
int position1=(Integer)v.getTag();
System.out.println("from the review "+position1);
String id=al.get(position1).id;
globalvariables.product_id=id;
Intent in=new Intent(getApplicationContext(),review_product_tabbar.class);
startActivity(in);
}
});
tv1.setText(a.post_title);
tv2.setText("$"+a.oldprice);
tv1.setTypeface(tf);
tv2.setTypeface(tf);
tv3.setTypeface(tf);
int loader = R.drawable.ic_launcher;
ImageView image = (ImageView)singleView. findViewById(R.id.imageView1);
imgLoader.DisplayImage(a.image, loader, image);
Animation anim = new Rotate3dAnimation(90.0f, 0.0f, 100.0f, false, singleView);
anim.setDuration(1000l);
singleView.startAnimation(anim);
return singleView;
}
}
}
当我点击它旋转的第一个项目而另一个视图即将到来时
但是当我滚动下面图像中的第四个项目时也会旋转
我在相对视图中使用on click listner,如代码
答案 0 :(得分:0)
我对点击图片有一个想法,首先尝试获取位置,当您获得位置时,然后在该位置设置新的图像背景。