我的想法是,如果有人点击列表中的某个联系人,他们会直接拨打,但我无法实施。 代码没有错误我唯一的问题是当我点击我只设法Toast“拷贝号”
package sampleapp.razen.com.sampleapp;
import android.content.Intent;
import android.os.Bundle;
import android.app.Activity;
import android.view.Gravity;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
public class MumActivity extends Activity {
// Array of strings...
String[] mobileArray = {" NAMES LOCATION & CODE CONTACTS ",
" 1.Jane Chebet Site(NJ01) 0722455795 ",
"2.Virginia Sakana Site(NJ02) 0722573859 ",
"3.Pamela Mwaka Site(NJ03) 0722650852 ",
"4.Esther Maina Site(NJ04) 0721688744",
"5.Catherine M. Site(NJ05) 0721401377",
"6.Esther Kamau Huru(NJ06) 0726677477",
"7.Julie Wanjiku Huru(NJ07) 0720590615",
"8.Elizabeth Muhia SiteNJ08) 0725212414",
"9.Hilda Wangechi Site(NJ09) 0702845060",
"10.Purity uthini Kobil(NJ10) 0723940761",
"11.Gladdies Wangari Huru(NJ11) 0726216744"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.contact);
ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_contact, mobileArray);
ListView listView = (ListView) findViewById(R.id.mobile_list);
listView.setAdapter(adapter);
}
public void call_id(View view){
Toast.makeText(getApplicationContext()," copy number ",Toast.LENGTH_LONG).show();
}
public void compose_email(View v){
String myEmail[]={"john@balloonventures.com"};
Intent sendMail = new Intent(Intent.ACTION_SEND);
sendMail.putExtra(Intent.EXTRA_EMAIL,myEmail);
sendMail.putExtra(Intent.EXTRA_SUBJECT,"(Host_home)emergency");
sendMail.setType("plain/text");
//incase you have to add something else put here
sendMail.putExtra(Intent.EXTRA_TEXT,"Your phone:+2547");
`` startActivity(sendMail);
}
}
答案 0 :(得分:0)
您的代码不完整,您没有为ListView设置项目单击侦听器。
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number"));
startActivity(intent);
}
});
另外,不要忘记为Manifest.xml添加适当的权限
<uses-permission android:name="android.permission.CALL_PHONE" />
答案 1 :(得分:0)
//where is your calling code , you didnit implement?
Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + "Your Phone_number"));
startActivity(intent);
//manifest
<uses-permission android:name="android.permission.CALL_PHONE" />
//put java code in call_id