如何在项目点击方法上优化gridview?

时间:2014-11-12 10:35:52

标签: android performance android-layout onclicklistener android-gridview

我正在开发一个项目,其中gridview用于选择项目,一切正常,但还有另一个问题;工作流程只是感觉笨拙,就像你试图点击项目,GV滑动一点点击没有注册,现在或者你必须点击两次注册点击。如何实现响应?

是否有任何优化此类情况的指导方针或任何其他更可靠的方法?

public class CustomGridViewAdapter extends ArrayAdapter<Item> {
    Context context;
    int layoutResourceId;
    ArrayList<Item> data = new ArrayList<Item>();

    public CustomGridViewAdapter(Context context, int layoutResourceId,
                                 ArrayList<Item> data) {
        super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        ViewHolder holder = null;

        if (row == null) {
            LayoutInflater inflater = ((Activity) context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);

            holder = new ViewHolder();
            holder.linearLayout=(LinearLayout)row.findViewById(R.id.linearLayoutGridViewItem);
            holder.txtTitle = (TextView) row.findViewById(R.id.textViewGridItemName);
            holder.imageItem = (ImageView) row.findViewById(R.id.imageViewGridItemIcon);
            row.setTag(holder);
        } else {
            holder = (ViewHolder) row.getTag();
        }

        final Item item = data.get(position);
        holder.txtTitle.setText(item.getNaziv());


        byte[] image= new byte[0];
        try {
            image = Base64.decode(item.getArti_image().getBytes("UTF-8"), Base64.NO_WRAP);
            holder.imageItem.setImageBitmap(
                    BitmapFactory.decodeByteArray(image, 0, image.length)
            );
            //Log.v("test",image+"");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        //holder.imageItem.setImageDrawable(getActivity().getResources().getDrawable(R.drawable.ic_launcher));
        row.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //

            }
        });
        return row;

    }


}
static class ViewHolder {
    LinearLayout linearLayout;
    TextView txtTitle;
    ImageView imageItem;

}

0 个答案:

没有答案