小编Jon*_*tan的帖子

如何使用自定义适配器的setTag和getTag

我被困了,我需要帮助.我正在尝试使用set并获取Tag但我无法了解它对此操作的工作原理:

  • 我正在使用列表视图来显示加载到扩展适配器的图像
  • 自定义适配器使用imageview_1,textview_1和button_1为布局充气
  • 在我的主要活动中,我有一个用于button_1的"Public Void OnClickHandler",并且在布局上配置了"android:onClick",所以当点击按钮时它会做一些事情
  • 单击button_1时,我想从该特定视图中获取textview_1中的文本,然后加载不同的图像.我想使用get和set TAGS来做到这一点,所以我需要使用button_1和imageview_1进行引用.这里是我的剪辑代码.先感谢您

自定义适配器

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

    LayoutInflater mInflater = (LayoutInflater) 
        context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);

    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.itemstartsession, null);
        holder = new ViewHolder();

        holder.image = (WebView)convertView.findViewById(R.id.img_session);
        //holder.image.setTag(position);

        holder.code = (TextView)convertView.findViewById(R.id.code_item_session_text);
        //holder.code.setTag(position);


        holder.share=(ImageButton)convertView.findViewById(R.id.share_item_session_button);
        holder.share.setTag(position);

        convertView.setTag(holder);
    // Check if my setTag is ok for button and get the reference to get 
        //text from textview and the referece to webview, then I gonna load a …
Run Code Online (Sandbox Code Playgroud)

tags android listview custom-adapter

12
推荐指数
2
解决办法
3万
查看次数

标签 统计

android ×1

custom-adapter ×1

listview ×1

tags ×1