name="android.permission.CALL_PHONE"/>
android:
allowBackup="true"
android:
icon="@drawable/su"
android:
label="@string/app_name"
android:
theme="@style/AppTheme"
>
android:
name="com.sdwu.io.MainActivity"
android:
label="@string/app_name">
name="android.intent.action.MAIN"/>
name="android.intent.category.LAUNCHER"/>
name="com.sdwu.io.showActivity">
//showActivity.java
packagecom.sdwu.io;
importjava.io.File;
importjava.io.FileInputStream;
importjava.io.FileNotFoundException;
importjava.io.FileOutputStream;
importjava.io.InputStream;
importjava.io.OutputStream;
importandroid.app.Activity;
importandroid.app.ActionBar;
importandroid.app.AlertDialog;
importandroid.app.Fragment;
importandroid.content.Context;
importandroid.content.Intent;
importandroid.graphics.drawable.GradientDrawable.Orientation;
import.Uri;
importandroid.os.Bundle;
importandroid.view.LayoutInflater;
importandroid.view.Menu;
importandroid.view.MenuItem;
importandroid.view.View;
importandroid.view.View.OnClickListener;
importandroid.view.ViewGroup;
importandroid.widget.Button;
importandroid.widget.EditText;
importandroid.widget.ImageButton;
importandroid.widget.LinearLayout;
importandroid.widget.TextView;
importandroid.widget.Toast;
importandroid.os.Build;
publicclassshowActivityextendsActivity{
LinearLayoutll;
@Override
protectedvoidonCreate(BundlesavedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.show);
//获取到id为ll的线性布局
ll=(LinearLayout)findViewById(R.id.show_layout);
find();
}
publicvoidfind(){
//获取保存文件的路径data/data/com.sdwu.io/files
Filefile=getFilesDir();
//将file文件夹内的所有文件以及子文件夹的名称返回
StringfileName[]=file.list();//list是file的类,
//声明输入流对象
FileInputStreamfis;
for(Stringname:
fileName){
try{
//获取输入流
fis=openFileInput(name);
byteb[]=newbyte[1024];
//读文件
fis.read(b);
fis.close();
finalStringinfo=newString(b).trim();//string加成final
//定义一个现行布局,存一个人的信息
LinearLayoutlinearLayout=newLinearLayout(this);
//存放联系人的姓名和号码
TextViewtv=newTextView(this);
tv.setText(info);
//hujiao
//ImageButtonbutton=newImageButton(this);
Buttonbutton=newButton(this);
button.setText("呼叫");
//编辑
Buttonbj=newButton(this);
bj.setText("编辑");
Buttondel=newButton(this);
del.setText("删除");
//为按钮添加单击事件
button.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewarg0){
//TODOAuto-generatedmethodstub
//Math.random();
Toast.makeText(showActivity.this,info.split("\r\n")[1],Toast.LENGTH_LONG).show();
Intentin=newIntent(Intent.ACTION_CALL,Uri.parse("tel:
"+info.split("\r\n")[1]));
//Intentin=newIntent(Intent.ACTION_CALL,Uri.parse("tel:
"+"12345678900"));
startActivity(in);
}
});
bj.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
Toast.makeText(showActivity.this,info.split("\r\n")[0],Toast.LENGTH_LONG).show();
//Intentin=newIntent(Intent.ACTION_CALL,Uri.parse("tel:
"+info.split("\r\n")[1]));
//Intentin=newIntent(Intent.ACTION_CALL,Uri.parse("tel:
"+"12345678900"));
//startActivity(in);
}
});
del.setOnClickListener(newOnClickListener(){
@Override
publicvoidonClick(Viewv){
Toast.makeText(showActivity.this,"确定要删除此联系人吗?
",Toast.LENGTH_LONG).show();
}
});
linearLayout.addView(tv);
linearLayout.addView(button);
//后来添加的
linearLayout.addView(bj);
//删除
linearLayout.addView(del);
ll.addView(linearLayout);
}catch(Exceptione){
e.printStackTrace();
}
}
}
}
//show.xml
android="
xmlns:
tools="
android:
layout_width="match_parent"
android:
layout_height="match_parent"
android:
background="@drawable/bf"
android:
measureAllChildren="false">
android:
layout_width="match_parent"
android:
layout_height="match_parent"
android:
orientation="vertical"
android:
id="@+id/show_layout">