想要做的事,以查看点击得到列表视图该项目 [英] Want to do something to view in item that got clicked in list view

查看:149
本文介绍了想要做的事,以查看点击得到列表视图该项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在被设置为不可见每个项目两个按钮。我想,当用户点击一个项目,该按钮只有在项目变成可见。

I have two buttons in each item that are set to invisible. I want, that when the user clicks on an item, the buttons only in that item turn to visible.

即时通讯使用自定义适配器为我的列表视图...

Im using a custom adapter for my list view...

public class LocationAdapter extends BaseAdapter{
    String [] n;
    Context context;
    String[] a;
    int bint = View.INVISIBLE;

    private static LayoutInflater inflater=null;
    public LocationAdapter(MainActivity mainActivity, String[] names, String[] addresses, int bint) {
        // TODO Auto-generated constructor stub
        this.bint = bint;
        n=names;
        context=mainActivity;
        a=addresses;
        inflater = ( LayoutInflater )context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return n.length;
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public class Holder
    {
        TextView name;
        TextView address;
        Button b1;
        Button b2;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        Holder holder=new Holder();
        View rowView;
        rowView = inflater.inflate(R.layout.rowlayout2, null);
        holder.name =(TextView) rowView.findViewById(R.id.EditTextName);
        holder.address =(TextView) rowView.findViewById(R.id.EditTextAddress);
        holder.b1 = (Button) rowView.findViewById(R.id.Edit);
        holder.b2 = (Button) rowView.findViewById(R.id.Delete);
        holder.b1.setVisibility(bint);
        holder.b2.setVisibility(bint);
        holder.name.setText(n[position]);
        holder.address.setText(a[position]);
        rowView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(context, "You Clicked "+n[position], Toast.LENGTH_LONG).show();
            }

        });
        return rowView;
    }
}

任何人都可以,请给我我需要怎么做到这一点的想法?

Can anyone please give me ideas on how i need to do this?

推荐答案

在这里你可以试试哪些
添加到onclicklsitener的BUTTOM整,而不是观点。内部按钮XML来要申请点击监听器添加下面两行

here is what you can try Add onclicklsitener to buttom instead of entire view. Inside buttons xml to which you want apply click listener add following two lines

android:focusable="false"
android:focusableInTouchMode="false"

现在申请监听器按钮如下:

now apply listener to button as follows

    holder.button.setOnClickListener(new OnClickListener()
      {
          @Override
          public void onClick(View v)
          {
              //set visibility of items here
              holder.buttonedit.setVisibility(View.GONE);
              holder.buttonedit.setVisibility(View.VISIBLE);

          }
      });

里面getview方法申报持有人最后

Inside getview method declare holder final

final Holder holder=new Holder();

和你做

这篇关于想要做的事,以查看点击得到列表视图该项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆