0
목록보기의 파일에 저장된 연락처 정보를 보여주고 싶습니다. 각 연락처를 같은 장소에 모두 표시하지 않고 별도의 셀에 표시하고 싶습니다. 모두 연락처가 목록보기의 단일 셀에 표시됩니다. 특수 문자를 사용하여 연락처 정보의 끝을 확인했습니다.안드로이드의 목록보기에 showstrings을 표시하는 방법
public void show_contacts()
{
final ListView listview = (ListView) findViewById(R.id.listview);
final ArrayList<String> list = new ArrayList<String>();
final ArrayAdapter adapter = new ArrayAdapter(this,
android.R.layout.simple_list_item_1, list);
String data_read="";
String FILENAME = "myfile.txt";
StringBuffer fileContent = new StringBuffer("");
FileInputStream fis = null;
String s1="";
try {
fis = openFileInput("myfile.txt");
byte[] buffer = new byte[1];
while (fis.read(buffer) != -1) {
if(s1.endsWith("."))
{
data_read=fileContent.toString();
list.add(data_read);
}
else
s1+=buffer.toString();
fileContent.append(new String(buffer));
}
} catch (Exception e) {
e.printStackTrace();
}
data_read=fileContent.toString();
list.add(data_read);
listview.setAdapter(adapter);
}
public void Write_to_file(String cName2,String cNumber2)
{
String string=cName2+"--"+cNumber2;
String FILENAME="myfile.txt";
FileOutputStream fos = null;
Context c=this.getBaseContext();
try {
String s=".";
fos = c.openFileOutput(FILENAME, Context.MODE_APPEND);
fos.write(string.getBytes());
fos.write(s.getBytes());
fos.close();
}
catch (Exception e) {
e.printStackTrace();
}
}