关闭

Fragment1中自定义控件适配

465人阅读 评论(1) 收藏 举报
package com.gao.xuejun.makingfriends.find.Newactivitys.fragemt_.fragment_1.f1;

import android.app.AlertDialog;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.gao.xuejun.makingfriends.R;
import com.gao.xuejun.makingfriends.find.Newactivitys.fragemt_.fragment_1.Sqlite.Daos;
import com.gao.xuejun.makingfriends.find.Newactivitys.fragemt_.fragment_1.f1.bean.Data;
import com.gao.xuejun.makingfriends.find.Newactivitys.fragemt_.fragment_1.gridViews.Adapter_gridview_image;
import com.gao.xuejun.makingfriends.find.Newactivitys.fragemt_.fragment_1.gridViews.Adapter_gridview_zan_image;
import com.gao.xuejun.makingfriends.find.Newactivitys.fragemt_.fragment_1.gridViews.MyGridView;
import com.gao.xuejun.makingfriends.find.Newactivitys.fragemt_.fragment_1.listViews.Adapter_listview_comment;
import com.gao.xuejun.makingfriends.find.Newactivitys.fragemt_.fragment_1.listViews.MyListView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 张梦雨 on 2016/5/22 0022.
 */
public class f1_FriendAdapter extends BaseAdapter{
    EditText f1_edText;
    ImageView f1_sendImg;
    LinearLayout f1_ll;
    ArrayList<Data> data=new ArrayList<Data>();
    Context context;
    private Boolean flag;
    int num=2;
    List<String> list=new ArrayList<String>();
    private TextView texts;
    private ImageView sure;
    private AlertDialog dialog;
    String ping;
    private List<String> query;
    private int counts;

    public f1_FriendAdapter(Context context, LinearLayout f1_ll, EditText f1_edText, ImageView f1_sendImg) {
        this.context = context;
        this.f1_ll=f1_ll;
        this.f1_edText=f1_edText;
        this.f1_sendImg=f1_sendImg;
    }

//    public void addtest(ArrayList<Data> data) {
//        this.data.clear();
//        this.data.addAll(data);
//        this.notifyDataSetChanged();
//    }

    @Override
    public int getCount() {
        return 10;
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertview, ViewGroup viewGroup) {
        final ViewHolder holder;
        if(convertview==null){
            convertview=LayoutInflater.from(context).inflate(R.layout.f1_item,null);
            holder=new ViewHolder();
            //第一个布局
            holder.f1_img_title = (ImageView) convertview.findViewById(R.id.f1_img_title);
            holder.f1_nick_name = (TextView) convertview.findViewById(R.id.f1_nick_name);
            holder.f1_wangguan = (ImageView) convertview.findViewById(R.id.f1_wangguan);
            holder.f1_age_height_province_income = (TextView) convertview.findViewById(R.id.f1_age_height_province_income);
            holder.f1_title = (TextView) convertview.findViewById(R.id.f1_title);
                //gridview
            holder.gridView = (MyGridView) convertview.findViewById(R.id.gridView);
//             holder.adapter_gridview_image=new Adapter_gridview_image(context,data.get(position).imgs);
//                holder.gridView.setAdapter(holder.adapter_gridview_image);

            //第二个布局
            holder.f1_ll_reward = (LinearLayout) convertview.findViewById(R.id.f1_ll_reward);
            holder.f1_img_reward = (ImageView) convertview.findViewById(R.id.f1_img_reward);
            holder.f1_nick_name = (TextView) convertview.findViewById(R.id.f1_nick_name);
                    //赞
            holder.f1_ll_prize = (LinearLayout) convertview.findViewById(R.id.f1_ll_prize);
            holder.f1_img_prize = (ImageView) convertview.findViewById(R.id.f1_img_prize);
            holder.f1_text_prize = (TextView) convertview.findViewById(R.id.f1_text_prize);

            holder.f1_ll_comment = (LinearLayout) convertview.findViewById(R.id.f1_ll_comment);
            holder.f1_img_commnt = (ImageView) convertview.findViewById(R.id.f1_img_commnt);
            holder.f1_text_comment = (TextView) convertview.findViewById(R.id.f1_text_comment);

            //第三个布局
            holder.f1_gridview_zan_reward = (MyGridView) convertview.findViewById(R.id.f1_gridview_zan_reward);


            //第四个布局
            holder.f1_tv_prize_count = (TextView) convertview.findViewById(R.id.f1_tv_prize_count);
             holder.f1_listview_comment = (MyListView) convertview.findViewById(R.id.f1_listview_comment);



            convertview.setTag(holder);

        }else{
            holder = (ViewHolder) convertview.getTag();
        }


        Daos daos=new Daos(context);

        query = daos.query();

        holder.adapter_listview_comment=new Adapter_listview_comment(context);
        holder.f1_listview_comment.setAdapter(holder.adapter_listview_comment);

        holder.adapter_listview_comment.addtest(query);
        flag = true;

            holder.f1_ll_prize.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    String text = holder.f1_tv_prize_count.getText().toString().trim();
                    if (flag == true) {
                        holder.f1_tv_prize_count.setText(text + ",5楼");
                        flag = false;
                    }else{
                        holder.f1_tv_prize_count.setText("1楼,2楼,3楼,4楼");
                        flag = true;
                    }
                }
            });


        counts = 7;
        holder.adapter_gridview_zan_image=new Adapter_gridview_zan_image(context,counts);
        holder.f1_gridview_zan_reward.setAdapter(holder.adapter_gridview_zan_image);
        holder.f1_ll_reward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                counts++;
                holder.adapter_gridview_zan_image=new Adapter_gridview_zan_image(context,counts);
                holder.f1_gridview_zan_reward.setAdapter(holder.adapter_gridview_zan_image);
            }
        });
//        Ion.with(context).load(data.get(position).headImg)
//                .withBitmap()
//                .placeholder(R.drawable.ic_launcher)
//                .error(R.drawable.ic_launcher)
//                .intoImageView(holder.f1_img_title);
//        holder.f1_nick_name.setText(data.get(position).nick_name);
//        holder.f1_age_height_province_income.setText(data.get(position).age+"  "+data.get(position).height+"  "+data.get(position).province+"  "+data.get(position).income);
//        holder.f1_title.setText(data.get(position).title);

        //楼数holder.f1_tv_prize_count
//        String prize="";
//        if(data.size()>4){
//            //大于4就固定4条
//            for (int i=0;i<4;i++){
//                prize+=data.get(position).pinglun.get(i).floor+",";
//            }
//        }else{
//            //小于4就按本身的数量
//            for (int i=0;i<data.get(position).pinglun.size();i++){
//                prize+=data.get(position).pinglun.get(i).floor+",";
//            }
//        }
//        holder.f1_tv_prize_count.setText(prize);

//         //判断是否是vip皇冠
//        int isvip = data.get(position).isvip;
//        if(isvip==0){
//            holder.f1_wangguan.setVisibility(View.INVISIBLE);
//        }else{
//            holder.f1_wangguan.setVisibility(View.VISIBLE);
//        }


        //评论显示输入文字的框
        holder.f1_text_comment.setOnClickListener(new View.OnClickListener() {


            @Override
            public void onClick(View view) {

                AlertDialog.Builder builder=new AlertDialog.Builder(context);
                dialog = builder.create();
                View view2=View.inflate(context, R.layout.dialoglayouti, null);
                texts = (TextView) view2.findViewById(R.id.dia_edText);
                sure = (ImageView) view2.findViewById(R.id.dia_sendImg);
                dialog.setView(view2);
                dialog.show();
                sure.setOnClickListener(new View.OnClickListener() {



                    @Override
                    public void onClick(View v) {
                         String text = texts.getText().toString().trim();
                        Toast.makeText(context,text,Toast.LENGTH_LONG).show();
                        Daos daos=new Daos(context);
                        daos.insert(text);
                      query = daos.query();


                        holder.adapter_listview_comment.addtest(query);

                        dialog.dismiss();
                    }
                });
//                f1_ll.setVisibility(View.VISIBLE);
//                f1_edText.setVisibility(View.VISIBLE);
//                f1_sendImg.setVisibility(View.VISIBLE);
            }
        });

        f1_sendImg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                f1_ll.setVisibility(View.GONE);
                f1_edText.setVisibility(View.GONE);
                f1_sendImg.setVisibility(View.GONE);
                String et_content = f1_edText.getText().toString().trim();
//

            }
        });


        return convertview;
    }



    class ViewHolder{
    //第一个布局的控件
        ImageView f1_img_title;
        TextView f1_nick_name;
        ImageView f1_wangguan;
        TextView f1_age_height_province_income;
        TextView f1_title;
        //图片展示自定义gridview
        MyGridView gridView;
        Adapter_gridview_image adapter_gridview_image;
    //第二个布局的控件
        LinearLayout f1_ll_reward;
        ImageView f1_img_reward;
        TextView f1_text_reward;

        LinearLayout f1_ll_prize;
        ImageView f1_img_prize;
        TextView f1_text_prize;

        LinearLayout f1_ll_comment;
        ImageView f1_img_commnt;
        TextView f1_text_comment;

        //第三个布局
        MyGridView f1_gridview_zan_reward;
        Adapter_gridview_zan_image adapter_gridview_zan_image;

        //第四个布局
        TextView f1_tv_prize_count;
        MyListView f1_listview_comment;
        Adapter_listview_comment adapter_listview_comment;
    }
}

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:15731次
    • 积分:726
    • 等级:
    • 排名:千里之外
    • 原创:59篇
    • 转载:0篇
    • 译文:0篇
    • 评论:6条