2015-01-06 2 views
0

У меня есть сетка. У меня есть строка row.xml, которую я раздуваю в классе адаптера. Моя строка xml имеет два макета (один видимый, а другой невидим.) Я делаю флип-анимацию. Когда я нажимаю на любой элемент gridview, происходит переключение анимации, и я делаю видимый скрытый макет и скрываю эту видимую макет. Анимация работает отлично. Но проблема в том, что, когда я нажимаю на любой элемент, и прокрутка других элементов также переворачивается. Так как я понимаю, что я не получаю конкретную позицию. Я пробовал следующий код.Flip Animation не работает должным образом в GridView после onItemClick

 @Override 
public View getView(final int position, View convertView, ViewGroup parent) { 

    View row; 

    final RecordHolder holder = new RecordHolder(); 

    animation1 = AnimationUtils.loadAnimation(context, R.anim.to_middle); 
    animation2 = AnimationUtils.loadAnimation(context, R.anim.from_middle); 

    if (convertView == null) { 
     row = View.inflate(context, R.layout.row_phone_and_tablet1, null); 
    } else { 
     //row = View.inflate(context, R.layout.row_phone_and_tablet1, null); 
     row = convertView; 
    } 

    holder.frontImage = (ImageView) row.findViewById(R.id.myimage_imgvw); 
    holder.frontMobileName = (TextView) row.findViewById(R.id.name_txtvw); 
    holder.frontPrice = (TextView) row.findViewById(R.id.price_txtvw); 
    holder.backMobileName = (TextView) row 
      .findViewById(R.id.tv_device_name); 
    holder.descOne = (TextView) row.findViewById(R.id.tv_desc_first); 
    holder.descTwo = (TextView) row.findViewById(R.id.tv_desc_second); 
    holder.descThree = (TextView) row.findViewById(R.id.tv_desc_third); 
    holder.descFour = (TextView) row.findViewById(R.id.tv_desc_fourth); 
    holder.ccEmi = (TextView) row.findViewById(R.id.tv_price_ccemi); 
    holder.financeEmi = (TextView) row.findViewById(R.id.tv_price_finance); 
    holder.frontlayout = (LinearLayout) row.findViewById(R.id.frontlayout); 
    holder.backlayout = (LinearLayout) row.findViewById(R.id.backlayout); 
    holder.viewdetails = (Button) row.findViewById(R.id.viewdetails); 
    holder.tv_front_inr = (TextView) row.findViewById(R.id.tv_front_inr); 
    holder.tv_description = (TextView) row 
      .findViewById(R.id.tv_description); 
    holder.tv_price_ccemi_inr = (TextView) row 
      .findViewById(R.id.tv_price_ccemi_inr); 
    holder.tv_ccemi_price = (TextView) row 
      .findViewById(R.id.tv_ccemi_price); 
    holder.tv_price_finance_inr = (TextView) row 
      .findViewById(R.id.tv_price_finance_inr); 
    holder.tv_financeemi_price = (TextView) row 
      .findViewById(R.id.tv_financeemi_price); 
    holder.parentLayout = (LinearLayout) row 
      .findViewById(R.id.parentLayout); 




    final PhoneAndTabletItem phoneAndTableItem = data.get(position); 
    holder.viewdetails.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      Intent i = new Intent(context, ViewPhoneInformation.class); 
      i.putExtra("SKU_CODE", phoneAndTableItem.getSku_code()); 
      context.startActivity(i); 
     } 
    }); 

    // row.setTag(holder); 



    holder.frontMobileName.setText(phoneAndTableItem.getModel_name()); 
    holder.frontPrice.setText(phoneAndTableItem.getCc_emi()); 
    holder.backMobileName.setText(phoneAndTableItem.getModel_name()); 
    holder.descOne.setText(phoneAndTableItem.getKey_feat_1()); 
    holder.descTwo.setText(phoneAndTableItem.getKey_feat_2()); 
    holder.descThree.setText(phoneAndTableItem.getKey_feat_3()); 
    holder.descFour.setText(phoneAndTableItem.getKey_feat_4()); 
    holder.ccEmi.setText(phoneAndTableItem.getCc_emi()); 
    holder.financeEmi.setText(phoneAndTableItem.getFinance_emi()); 

    holder.frontMobileName.setTypeface(tvHalvetica); 
    holder.frontPrice.setTypeface(tvHalvetica); 
    holder.backMobileName.setTypeface(tvHalvetica); 
    holder.descOne.setTypeface(tvHalvetica); 
    holder.descTwo.setTypeface(tvHalvetica); 
    holder.descThree.setTypeface(tvHalvetica); 
    holder.descFour.setTypeface(tvHalvetica); 
    holder.ccEmi.setTypeface(tvHalvetica); 
    holder.financeEmi.setTypeface(tvHalvetica); 
    holder.tv_front_inr.setTypeface(tvHalvetica); 
    holder.tv_description.setTypeface(tvHalvetica); 
    holder.tv_price_ccemi_inr.setTypeface(tvHalvetica); 
    holder.tv_ccemi_price.setTypeface(tvHalvetica); 
    holder.tv_price_finance_inr.setTypeface(tvHalvetica); 
    holder.tv_financeemi_price.setTypeface(tvHalvetica); 

    // here we are rotating the LinearLayout... 
    holder.parentLayout.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      v.setTag(position); 
      // Start Array Check... 
      Toast.makeText(context, "onClick id: " + v.getTag(), Toast.LENGTH_SHORT).show(); 

      if (selected_views.contains((Integer) v.getTag())) { 

       holder.frontlayout.clearAnimation(); 
       holder.frontlayout.setAnimation(animation1); 
       holder.frontlayout.startAnimation(animation1); 

       HashSet hs = new HashSet(); 
       hs.addAll(selected_views); 
       selected_views.clear(); 
       selected_views.addAll(hs); 
       selected_views.remove((Integer) v.getTag()); 
       notifyDataSetChanged(); 

       isBackOfCardShowing = true; 
      } else { 
       if (selected_views.size() == 0) { 
        holder.frontlayout.clearAnimation(); 
        holder.frontlayout.setAnimation(animation1); 
        holder.frontlayout.startAnimation(animation1); 
        selected_views.add((Integer) v.getTag()); 
        notifyDataSetChanged(); 
        array_size = selected_views.size(); 
        isBackOfCardShowing = false; 
       } 
       else { 
        holder.frontlayout.clearAnimation(); 
        holder.frontlayout.setAnimation(animation1); 
        holder.frontlayout.startAnimation(animation1); 
        selected_views.add((Integer) v.getTag()); 
        notifyDataSetChanged(); 
        isBackOfCardShowing = false; 
       } 
      } 
      // End Array Check... 

      animation1.setAnimationListener(new AnimationListener() { 

       @Override 
       public void onAnimationStart(Animation animation) { 
       } 

       @Override 
       public void onAnimationRepeat(Animation animation) { 
       } 

       @Override 
       public void onAnimationEnd(Animation animation) { 

         if (isBackOfCardShowing) { 
          holder.frontlayout.setVisibility(View.VISIBLE); 
          holder.backlayout.setVisibility(View.GONE); 
          // holder.frontImage.setImageResource(R.drawable.accesories_dashboard); 
         } else { 
          holder.backlayout.setVisibility(View.VISIBLE); 
          holder.frontlayout.setVisibility(View.GONE); 
          // holder.frontImage.setImageResource(R.drawable.vas_dashboard); 
         } 
         holder.frontlayout.clearAnimation(); 
         holder.frontlayout.setAnimation(animation2); 
         holder.frontlayout.startAnimation(animation2); 
       } 
      }); 
     } 
    }); 
    holder.parentLayout.setOnLongClickListener(new OnLongClickListener() { 

     @Override 
     public boolean onLongClick(View v) { 

      String inserted=""; 
      final String SKV_CODE = phoneAndTableItem.getSku_code().toString(); 
      handler.open(); 
       inserted = handler.insertData(phoneAndTableItem.getModel_name(),  
               phoneAndTableItem.getKey_feat_1(), 
               phoneAndTableItem.getKey_feat_2(), 
               phoneAndTableItem.getKey_feat_3(),  
               phoneAndTableItem.getKey_feat_4(), 
               phoneAndTableItem.getCc_emi(),   
               phoneAndTableItem.getFinance_emi(), 
               SKV_CODE); 
       handler.close(); 

       if (inserted.equals("inserted")) { 
        Toast.makeText(context, " Added to Shortlist " , Toast.LENGTH_SHORT).show(); 
       } else if(inserted.equals("error")){ 
        Toast.makeText(context, " Already present in Shortlist " , Toast.LENGTH_SHORT).show(); 
       }else { 
        Toast.makeText(context, " Try again " , Toast.LENGTH_SHORT).show(); 
       } 

      return true; 
     } 
    }); 

    return row; 
} 
static class RecordHolder { 
    ImageView frontImage; 
    TextView frontMobileName; 
    TextView frontPrice; 
    TextView backMobileName; 
    TextView descOne; 
    TextView descTwo; 
    TextView descThree; 
    TextView descFour; 
    TextView ccEmi; 
    TextView financeEmi; 
    LinearLayout frontlayout, backlayout, parentLayout; 
    Button viewdetails; 
    TextView tv_front_inr, tv_description, tv_price_ccemi_inr, 
      tv_ccemi_price, tv_price_finance_inr, tv_financeemi_price; 

} 

Этот код правильно показывает положение, но ниже, когда я прокрутки, то все равно я получаю переворачивается другие элементы также. Пожалуйста, помогите мне.

+0

можете ли вы разместить свой код адаптера? –

+0

сейчас проверка Я отредактировал вопрос. –

ответ

0

Чтобы получить точное положение пункта щелкнул в GridView, вам нужно использовать setOnItemClickListener на вашем GridView ссылки, пример:

 GridView g = (GridView) findViewById(R.id.gridView1); 

     g.setAdapter(new ImageAdopterShow(this)); // your custom adaptor object goes here 


     g.setOnItemClickListener(new OnItemClickListener() { 

     @Override 
     public void onItemClick(AdapterView<?> arg0, View arg1, int position, 
       long arg3) { 


      Toast.makeText(getBaseContext(), "position of item is " +position, Toast.LENGTH_SHORT).show(); 


     } 
    }); 

Это путь я получить позицию любого элемента в моей GridView. Надеюсь, что это ответ на ваш вопрос.

Ваш вопрос вводит в заблуждение. Если вы можете получить позицию позиции, вам нужно изменить свой вопрос, чтобы анимации не работали в GridView должным образом.

+0

Я применяю анимацию определенного элемента сетки, но одновременно отражает анимацию на других элементах gridview. –

+0

Я не могу использовать onItemClickListener(). Мне нужно использовать layoutClickListener() в классе адаптера. Мои требования немного разные. –

+0

Можете ли вы опубликовать код всего своего класса? Где «держатель», «backlayout» и «frontlayout» –

Смежные вопросы