0

我制作了一个列表视图,其中有 2 个对象,名称和电话。现在,我想单击列表视图并使用列出的电话号码拨打电话。

我不知道该怎么做。请帮忙。谢谢。

import java.util.ArrayList;
import java.util.HashMap;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleAdapter;

public class Express extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            activitylink.getInstance().addActivity(this);

            final String Item_Name = "NAME", Item_Hotline = "HOTLINE";

            ArrayList<HashMap<String,String>> myListData = new ArrayList<HashMap<String,String>>();

            String[] hotlines = new String[]{ "11112222" , "22223333", "44445555" };

            for( int i=0;i<getResources().getStringArray(R.array.item).length ; ++i) {
                    HashMap<String,String> item = new HashMap<String,String>();
                    item.put(Item_Name,getResources().getStringArray(R.array.item)[i]);
                    item.put(Item_Hotline,hotlines[i]);
                    myListData.add(item);
            }

            setListAdapter( new SimpleAdapter(
                    this,
                    myListData,
                    R.layout.list_item,
                    new String[] { Item_Name, Item_Hotline },
                    new int[] { android.R.id.text1, android.R.id.text2 } )
            );
    }
    @Override
    public void onListItemClick(ListView list, View v, int position, long id) {


        }
    }
}
4

3 回答 3

0

试试这个,希望对你有帮助...

@Override
public void onListItemClick(ListView list, View v, int position, long id) {
       String hotline = (String) myListData.get((int) id)
                        .values().toArray()[1];

       Log.d("hotline", hotline);
       callHotline(hotline);
    }
}
private void callHotline(String hotlineStr){ 
   Intent callIntent = new Intent(Intent.ACTION_CALL);
   callIntent.setData(Uri.parse("tel:"+hotlineStr));
   startActivity(callIntent);
}
于 2013-03-14T12:53:19.273 回答
0

@Override public void onListItemClick(ListView list, View v, int position, long id) { String hotline = myListData.get(position);

          Intent tocall = new Intent(Intent.ACTION_CALL);
         tocall.setData(Uri.parse("tel:"+hotline ));
          startActivity(tocall);
    }
}
于 2013-03-26T18:13:33.143 回答
0

OnItemClickListener

@Override
public void onListItemClick(ListView list, View v, int position, long id) {

    Intent callIntent = new Intent(Intent.ACTION_CALL);
    callIntent.setData(Uri.parse("tel:" + hotlines[position]));
    startActivity(callIntent);

    }
}
于 2013-09-23T19:52:53.567 回答