Fragment1中自定义控件适配

原创 2016年06月02日 08:12:56
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;
    }
}

Android中Fragment嵌套Fragment,切换Fragment时不显示视图的原因及解决方法

项目中经常会用到ViewPager配合Fragment进行滑动视图的实现,经常配合FragmentPagerAdapter一起使用。 当需要在Fragment(姑且叫做A)中嵌套另外一个Fragmen...
  • gxp1182893781
  • gxp1182893781
  • 2017年04月06日 15:15
  • 2120

Fragment的布局中自定义Layout的onSizeChanged添加组件失败的问题

今天想做点东西,有些部分觉得用fragment比较合适,而且自己
  • chzphoenix
  • chzphoenix
  • 2014年05月10日 22:28
  • 1812

第三章 自定义控件和Fragment

1.大小、长度单位 px :像素点   —— 一般不用做长度单位,因为不同型号的手机的像素密度是不一样的,以它为单位的话会造成控件在不同手机的长度不一样; dp:与像素点密度密切相关         ...
  • qq_35469331
  • qq_35469331
  • 2016年07月25日 11:03
  • 1455

Android开发之ViewPager使用详解(一)

ViewPager的用法详解
  • dmk877
  • dmk877
  • 2015年11月30日 09:27
  • 3744

fragment1

package com.bwie.test.fragment; import java.util.ArrayList; import me.maxwin.view.XListVie...
  • qq_35547678
  • qq_35547678
  • 2016年07月27日 19:45
  • 133

Fragment1

import java.io.IOException; import java.util.List;import org.apache.http.HttpEntity; import org.ap...
  • Cotent
  • Cotent
  • 2016年08月26日 13:49
  • 221

Android Fragment中嵌套Fragment,不显示view

先看一段错误代码,这段代码写在一个 Fragment 中:private void initView(){ mViewPageAdpater = new ViewPageAdpater( ge...
  • jdsjlzx
  • jdsjlzx
  • 2016年09月17日 11:14
  • 4790

Android Fragment中嵌套Fragment,不显示view

原文链接:http://www.jianshu.com/p/e146698482f5先看一段错误代码,这段代码写在一个 Fragment 中:private void initView(){ ...
  • axi295309066
  • axi295309066
  • 2016年11月28日 16:26
  • 472

FragmentTableHost+Fragment

团购商城的框架:FragmentTableHost+Fragment //添加fragment的数组,主要是为了动态的改变APP以及界面的个数,如果要添加新的模块,只需要在这里添加一个fragm...
  • hatsune39
  • hatsune39
  • 2016年12月01日 16:24
  • 351
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Fragment1中自定义控件适配
举报原因:
原因补充:

(最多只允许输入30个字)