错误里面列表视图按钮点击拨打电话 [英] Error in making call on Button click inside listview

查看:240
本文介绍了错误里面列表视图按钮点击拨打电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数字列表视图,并与每个数字图像布通。我想就按一下按钮调用行中的数字。我getview方法

I have a listview with number and an image buton with each number. I want to make call on button click to the number in the row. my getview method is

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View rowView = convertView;
    ContactStockView sv = null;
    if (rowView == null) {
        // Get a new instance of the row layout view
        LayoutInflater inflater = activity.getLayoutInflater();
        rowView = inflater.inflate(
                R.layout.activity_row, null);

        // Hold the view objects in an object,
        // so they don't need to be re-fetched
        sv = new ContactStockView();
        sv.name = (TextView) rowView.findViewById(R.id.textacti_row1);
        sv.number = (TextView) rowView.findViewById(R.id.textacti_row2);
        sv.btncall=(ImageButton)rowView.findViewById(R.id.imgbtn_call);
        //sv.btncall.setOnClickListener((OnClickListener) activity);
        rowView.setTag(sv);
        //ImageButton btn=(ImageButton)convertView.findViewById(R.id.btn_call);
      /*  */
    } else {
        sv = (ContactStockView) rowView.getTag();
    }

    // Transfer the stock data from the data object
    // to the view objects
    ContactStock currentStock = (ContactStock) stocks.get(position);
    sv.name.setText(currentStock.getName());
    number=currentStock.getNumber();
    sv.number.setText(number);
    //ImageButton btn=(ImageButton)rowView.findViewById(R.id.imgbtn_call);
    sv.btncall.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            // TODO Auto-generated method stub
            //Toast.makeText( activity, number, Toast.LENGTH_SHORT).show();
            String phoneCallUri = "tel:"+number;
            Intent phoneCallIntent = new Intent(Intent.ACTION_CALL);
            phoneCallIntent.setData(Uri.parse(phoneCallUri));
             activity.startActivity(phoneCallIntent);
        }
    });
    /*  btn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub



            //Toast.makeText( activity, "abc", Toast.LENGTH_SHORT).show();
        /*}
    });*/
    // TODO Auto-generated method stub
    return rowView;
}
 protected static class ContactStockView {
        protected TextView name;
        protected TextView number;
        protected ImageButton btncall;
    }

这是我的通话记录猫

My log cat on call is

推荐答案

您应该声明字符串数量即可。变化

you should declare the string number in get view method not outside it. change

number=currentStock.getNumber();

final String number=currentStock.getNumber();

和删除串(即数)禁区外getview方法

and delete the string(ie,number) from outside getview method

这篇关于错误里面列表视图按钮点击拨打电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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