gpt4 book ai didi

java - ListView显示txt文件中的联系人-Android Studio

转载 作者:行者123 更新时间:2023-11-30 01:21:25 25 4
gpt4 key购买 nike

您好,我需要创建一个 ListView 来显示存储在文本文件中的所有联系人。要添加联系人,用户必须自己输入详细信息,因此这些信息将保存在文本文件中。现在我需要创建一个 ListView 以在列表中显示这些联系人,并且还会为每个联系人显示一个按钮。至于现在我的代码所做的只是在 Toast 中显示联系人。

public void ViewContacts(View v)
{
//reading contacts from textfile
try{
FileInputStream fileIn=openFileInput("mytextfile.txt");
InputStreamReader InputRead=new InputStreamReader(fileIn);

char[] inputBuffer=new char[READ_BLOCK_SIZE];
String s="";
int charRead;

while((charRead=InputRead.read(inputBuffer))>0)
{
//char to string conversion
String readstring=String.copyValueOf(inputBuffer,0,charRead);
s+=readstring;
}
InputRead.close();
Toast.makeText(getBaseContext(),s,Toast.LENGTH_SHORT).show();
} catch(Exception e)
{
e.printStackTrace();
}
}

最佳答案

您可以将所有联系人详细信息存储在一个 json 字符串类型的文本文件中。然后解析该 json 字符串并在需要时创建数据列表。在 ListView 中填充该列表。

You can follow this link to convert string to json

Parse your json data - example

关于java - ListView显示txt文件中的联系人-Android Studio,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37047110/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com