Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/231.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在Baseadapter中获得位置_Android_Android Listview_Baseadapter_Android Viewholder - Fatal编程技术网

Android 如何在Baseadapter中获得位置

Android 如何在Baseadapter中获得位置,android,android-listview,baseadapter,android-viewholder,Android,Android Listview,Baseadapter,Android Viewholder,我从服务器获得响应并在listview中显示它,但如何在baseadapter中获得位置,我在listitem中有一个imageview,我想根据选择获取用户id,现在我在单击imageview时在每个列表项中获得最后6个id 这是我的回答 { "searchresult": [ { "user_id": "5", }, { "user_id": "6", } ]

我从服务器获得响应并在listview中显示它,但如何在baseadapter中获得位置,我在listitem中有一个imageview,我想根据选择获取用户id,现在我在单击imageview时在每个列表项中获得最后6个id

这是我的回答

 {
    "searchresult": [
        {
            "user_id": "5",

        },
        {
            "user_id": "6",

        }
    ]
}
我的适配器

 public class CustomAdapterAccept extends BaseAdapter{

        private Context context;
        private ArrayList<HashMap<String,String>> listData;
        private AQuery aQuery;

        private  String TAGs_NAME="user_fname";
        private  String TAG_FRIENDID="user_id";
        private String TAGs_IMAGES="user_pic";
        private  String TAGs_CITY="user_city";


        public CustomAdapterAccept(Context context,ArrayList<HashMap<String,String>> listData) {
            this.context = context;
            this.listData=listData;
            aQuery = new AQuery(this.context);
        }

        @Override
        public int getCount() {
            return listData.size();
        }

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

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

        @Override
        public View getView( final int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if (convertView == null) {
                holder = new ViewHolder();
                convertView = LayoutInflater.from(context).inflate(R.layout.list_item_balloonationsearch, null);
                holder.propics = (ImageView) convertView.findViewById(R.id.list_item_ballonationsearch_propic);
                holder.txtproname = (TextView) convertView.findViewById(R.id.list_item_ballonationsearch_username);

                holder.addfriend=(ImageView) convertView.findViewById(R.id.addfriend_after_searchs);
                holder.city=(TextView) convertView.findViewById(R.id.serach_city);



                convertView.setTag(holder);
            }else{
                holder = (ViewHolder) convertView.getTag();
            }

             holder.addfriend.setTag(position);
        holder.addfriend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final int position = (int) view.getTag();
                frindsids=listData.get(position).get(TAG_FRIENDID);
                System.out.println("HWIHC ID"+frindsids);
            }
        });

            holder.txtproname.setText(listData.get(position).get(TAGs_NAME));
            holder.city.setText(listData.get(position).get(TAGs_CITY));
            aQuery.id(holder.propics).image(listData.get(position).get(TAGs_IMAGES),true,true,0,R.drawable.male);

            // image parameter : 1 : memory cache,2:file cache,3:target width,4:fallback image
            return convertView;
        }
        class ViewHolder{
            ImageView propics;
            TextView txtproname,city;
            TextView txtproid;
            TextView txtprofilecast;
            TextView txtprofileage;
            TextView txtprofileplace;
            public ImageView addfriend;
        }

    }
公共类CustomAdapterAccept扩展BaseAdapter{
私人语境;
私有数组列表数据;
私人水渠;
私有字符串标记\u NAME=“user\u fname”;
私有字符串TAG\u FRIENDID=“user\u id”;
私有字符串标记\u IMAGES=“user\u pic”;
私有字符串标记\u CITY=“user\u CITY”;
公共CustomAdapterAccept(上下文,ArrayList listData){
this.context=上下文;
this.listData=listData;
aQuery=新的aQuery(this.context);
}
@凌驾
public int getCount(){
返回listData.size();
}
@凌驾
公共对象getItem(int位置){
返回listData.get(位置);
}
@凌驾
公共长getItemId(int位置){
返回位置;
}
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
视窗座;
if(convertView==null){
holder=新的ViewHolder();
convertView=LayoutInflater.from(context).flate(R.layout.list\u item\u balloationsearch,null);
holder.propics=(ImageView)convertView.findViewById(R.id.list\u item\u balloationsearch\u propic);
holder.txtproname=(TextView)convertView.findViewById(R.id.list\u item\u balloationsearch\u用户名);
holder.addfriend=(ImageView)convertView.findViewById(R.id.addfriend\u搜索后);
holder.city=(TextView)convertView.findViewById(R.id.Serachu_city);
convertView.setTag(支架);
}否则{
holder=(ViewHolder)convertView.getTag();
}
holder.addfriend.setTag(位置);
holder.addfriend.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图){
final int position=(int)view.getTag();
frindsids=listData.get(position).get(TAG\u-FRIENDID);
System.out.println(“HWIHC ID”+FRINDSID);
}
});
holder.txtproname.setText(listData.get(position.get(TAGs_NAME));
holder.city.setText(listData.get(position.get(TAGs_city));
id(holder.propics).image(listData.get(position).get(TAGs_IMAGES),true,true,0,R.drawable.male);
//图像参数:1:内存缓存,2:文件缓存,3:目标宽度,4:回退图像
返回视图;
}
类视图持有者{
图像视图;
TextView txtproname,城市;
TextView txtproid;
TextView txtprofilecast;
TextView-txtprofileage;
TextView txtprofileplace;
公众形象;
}
}

我已经编辑了您的代码,请检查并重试

         holder.addfriend=(ImageView) convertView.findViewById(R.id.addfriend_after_searchs);
holder.addfriend.setTag(position);
                holder.city=(TextView) convertView.findViewById(R.id.serach_city);



                convertView.setTag(holder);
            }else{
                holder = (ViewHolder) convertView.getTag();
            }

             holder.addfriend.setTag(position);
        holder.addfriend.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
  int posi = (Integer) view.getTag();

                frindsids=listData.get(posi).get(TAG_FRIENDID);
                System.out.println("HWIHC ID"+frindsids);
            }
        });

            holder.txtproname.setText(listData.get(position).get(TAGs_NAME));
            holder.city.setText(listData.get(position).get(TAGs_CITY));
            aQuery.id(holder.propics).image(listData.get(position).get(TAGs_IMAGES),true,true,0,R.drawable.male);

            // image parameter : 1 : memory cache,2:file cache,3:target width,4:fallback image
            return convertView;
        }
        class ViewHolder{
            ImageView propics;
            TextView txtproname,city;
            TextView txtproid;
            TextView txtprofilecast;
            TextView txtprofileage;
            TextView txtprofileplace;
            public ImageView addfriend;
        }

    }

怎么做?你能吗tell@MikeM. 5.我不知道该怎么做它不起作用了