设置Listview项的FrameLayout小部件的可见性

时间:2014-10-16 14:47:19

标签: android android-listview baseadapter android-framelayout

我已经使用了一个自定义BaseAdapter类实现了一个listview。当用户在其中一个Listview项目上单击FrameLayout时,其可见性应设置为GONE。 我已经在onClickListener方法中将FrameLayout的可见性设置为GONE。在这里,当我按下FrameLayout时,它没有设置为GONE,而是其他项目的其他FrameLayout设置为GONE。 如何处理这个问题。请在下面找到BaseAdapter类的代码。

public class RewardsAllAdapter extends BaseAdapter {

    private Context context;
    private RewardsAll obj;
    private ArrayList<Rewards> rewds;
    private int flag = 0;
    private ViewHolder holder = null;

    public RewardsAllAdapter(Context context, RewardsAll obj) {
        // TODO Auto-generated constructor stub
        this.context = context;
        this.obj = obj;
        this.rewds = obj.getAllRewards();
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return rewds.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return rewds.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return 0;
    }

    @Override
    public View getView(final int position, View view, ViewGroup parent) {
        // TODO Auto-generated method stub

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (view == null) {
            view = inflater.inflate(R.layout.rewards_listview_item, null);
            holder = new ViewHolder();
            holder.imageViewAdpIv = (ImageView) view
                    .findViewById(R.id.imageView1);
            holder.titleAdpTv = (TextView) view.findViewById(R.id.textView1);
            holder.merNameAdpTv = (TextView) view.findViewById(R.id.textView2);
            holder.refCodeAdpTv = (TextView) view.findViewById(R.id.textView3);
            holder.claimAdpFl = (FrameLayout) view
                    .findViewById(R.id.frameLayout1);
            view.setTag(holder);
        } else
            holder = (ViewHolder) view.getTag();

        holder.titleAdpTv.setText(rewds.get(position).getRewardName());
        holder.merNameAdpTv.setText("Merchant: "
                + rewds.get(position).getMerchantName());
        holder.refCodeAdpTv.setText("Referral code: "
                + rewds.get(position).getRewardCode());
        holder.claimAdpFl.setVisibility(View.VISIBLE);

        holder.claimAdpFl.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub

                String rewardId = rewds.get(position).getId();
                Intent subIntent = new Intent(context,
                        ClaimRewardsService.class);
                subIntent.putExtra("REWARD_ID", rewardId);
                context.startService(subIntent);
                holder.claimAdpFl.setVisibility(View.GONE);

            }
        });

        return view;
    }

    private static class ViewHolder {

        private ImageView imageViewAdpIv;
        private TextView titleAdpTv;
        private TextView merNameAdpTv;
        private TextView refCodeAdpTv;
        private FrameLayout claimAdpFl;
    }

}

0 个答案:

没有答案