想实现在ListFragment里面的ListView的item里面的Button的点击事件

想实现在ListFragment里面的ListView的item里面的Button的点击事件
重写了BaseAdapter 然后再ListFragment中的onCreated()方法中setAdapter一直出错  求大神
package com.example.cms.lizixiaoyuan.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.cms.lizixiaoyuan.Activity.Function_Biaoqian;
import com.example.cms.lizixiaoyuan.R;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by CMS on 2016/8/6.
 */
public class FunctionClassAdapter extends BaseAdapter {
    private class ViewHolder{
        ImageView f_c_rmnr_photo;
        TextView f_c_rmnr_title;
        TextView f_c_rmnr_bq;
        TextView f_c_rmnr_text1;
        TextView f_c_rmnr_text2;
        TextView f_c_rmnr_text3;
        TextView f_c_rmnr_num_comment;
        TextView f_c_rmnr_num_like;
        TextView f_c_rmnr_pf;
        TextView f_c_rmnr_dbq;
        TextView f_c_rmnr_author;
    }

    private List<Map<String, Object>> mAppList;
    private LayoutInflater mInflater;
    private Context mContext;
    private String[] keyString;
    private int[] valueViewID;
    private ViewHolder holder=null;

    public FunctionClassAdapter(Context c, List<Map<String, Object>> appList, int resource,
                                String[] from, int[] to) {
        mContext = c;
        mAppList = appList;
        mInflater = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        keyString = new String[from.length];
        valueViewID = new int[to.length];
        System.arraycopy(from, 0, keyString, 0, from.length);
        System.arraycopy(to, 0, valueViewID, 0, to.length);
    }
    @Override
    public int getCount() {
        return mAppList.size();
    }

    @Override
    public Object getItem(int position) {
        return mAppList.get(position);
    }

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

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView != null) {
            holder = (ViewHolder) convertView.getTag();
        } else {
            convertView = mInflater.inflate(R.layout.f_c_list_item, null);
            holder = new ViewHolder();
            holder.f_c_rmnr_photo= (ImageView) convertView.findViewById(valueViewID[0]);
            holder.f_c_rmnr_title= (TextView) convertView.findViewById(valueViewID[1]);
            holder.f_c_rmnr_bq= (TextView) convertView.findViewById(valueViewID[2]);
            holder.f_c_rmnr_text1= (TextView) convertView.findViewById(valueViewID[3]);
            holder.f_c_rmnr_text2= (TextView) convertView.findViewById(valueViewID[4]);
            holder.f_c_rmnr_text3= (TextView) convertView.findViewById(valueViewID[5]);
            holder.f_c_rmnr_num_comment= (TextView) convertView.findViewById(valueViewID[6]);
            holder.f_c_rmnr_num_like= (TextView) convertView.findViewById(valueViewID[7]);
            holder.f_c_rmnr_pf= (TextView) convertView.findViewById(valueViewID[8]);
            holder.f_c_rmnr_dbq= (TextView) convertView.findViewById(valueViewID[9]);
            holder.f_c_rmnr_author= (TextView) convertView.findViewById(valueViewID[10]);
            convertView.setTag(holder);
        }
        HashMap<String, Object> appInfo = (HashMap<String, Object>) mAppList.get(position);
        if (appInfo != null) {
            int f_c_rmnr_photo= (Integer) appInfo.get(keyString[0]);
            String f_c_rmnr_title= (String) appInfo.get(keyString[1]);
            String f_c_rmnr_bq= (String) appInfo.get(keyString[2]);
            String f_c_rmnr_text1= (String) appInfo.get(keyString[3]);
            String f_c_rmnr_text2= (String) appInfo.get(keyString[4]);
            String f_c_rmnr_text3= (String) appInfo.get(keyString[5]);
            String f_c_rmnr_num_comment= (String) appInfo.get(keyString[6]);
            String f_c_rmnr_num_like= (String) appInfo.get(keyString[7]);
            String f_c_rmnr_pf= (String) appInfo.get(keyString[8]);
            String f_c_rmnr_dbq= (String) appInfo.get(keyString[9]);
            String f_c_rmnr_author= (String) appInfo.get(keyString[10]);


            holder.f_c_rmnr_photo.setImageResource(f_c_rmnr_photo);    ///??????????????????????/
            holder.f_c_rmnr_title.setText(f_c_rmnr_title);
            holder.f_c_rmnr_bq.setText(f_c_rmnr_bq);
            holder.f_c_rmnr_text1.setText(f_c_rmnr_text1);
            holder.f_c_rmnr_text2.setText(f_c_rmnr_text2);
            holder.f_c_rmnr_text3.setText(f_c_rmnr_text3);
            holder.f_c_rmnr_num_comment.setText(f_c_rmnr_num_comment);
            holder.f_c_rmnr_num_like.setText(f_c_rmnr_num_like);
            holder.f_c_rmnr_pf.setText(f_c_rmnr_pf);
            holder.f_c_rmnr_dbq.setText(f_c_rmnr_dbq);
            holder.f_c_rmnr_author.setText(f_c_rmnr_author);
            holder.f_c_rmnr_dbq.setOnClickListener(new bqListener(position));

        }

        return convertView;
    }

    class bqListener implements View.OnClickListener {
        private int position;

        bqListener(int pos) {
            position = pos;
        }

        @Override
        public void onClick(View v) {
            Toast.makeText(mContext, "position"+position, Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 移动ListView中某一项的方法
     * @param position
     */
    public void removeItem(int position){
        mAppList.remove(position);
        this.notifyDataSetChanged();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值