0
我們已經試過您的解決方案,它很好地工作,但所有的答案去陣列0和結合在一起一切,所以你能解決這個問題我的應用程序的答案去陣列0和組合都在一起
我用這個收集從用戶數據
public class profile extends AppCompatActivity {
EditText name1 , surname1 , idnumber1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_profile);
name1 = (EditText)findViewById(R.id.name);
surname1 = (EditText)findViewById(R.id.surname);
idnumber1 = (EditText)findViewById(R.id.Idnumber);
}
public void save(View view){
String name2 = name1.getText().toString();
String surname2 = surname1.getText().toString();
String idnumber2 = idnumber1.getText().toString();
File file = null;
name2 = name2+"";
surname2 = surname2+"";
FileOutputStream fileOutputStream = null;
try {
file = getFilesDir();
fileOutputStream = openFileOutput("Rank It Up.txt" , Context.MODE_PRIVATE);
fileOutputStream.write(name2.getBytes());
fileOutputStream.write(surname2.getBytes());
fileOutputStream.write(idnumber2.getBytes());
} catch (IOException e) {
Log.d("Rank It Up", e.toString());
}
finally {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Toast.makeText(this, "Save successfully"+file+"/Rank It Up.txt", Toast.LENGTH_LONG).show();
}
public void next(View view){
Toast.makeText(this, "Database page",Toast.LENGTH_LONG).show();
Intent intent = new Intent(this, DBActivity.class);
startActivity(intent);
}
}
,然後這對從用戶那裏收集的數據顯示
public class DBActivity extends AppCompatActivity {
TextView name1 , surname1 , idnumber1;
@Override
protected void onCreate(Bundle saveInstanceState){
super.onCreate(saveInstanceState);
setContentView(R.layout.activity_db);
name1 = (TextView)findViewById(R.id.name);
surname1 = (TextView)findViewById(R.id.surname);
idnumber1 = (TextView)findViewById(R.id.idnumber);
}
public void show(View view){
try {
FileInputStream fileInputStream = openFileInput("Rank It Up.txt");
int read = -1;
StringBuffer buffer = new StringBuffer();
while ((read=fileInputStream.read()) != -1)
{
buffer.append((char) read);
}
Log.d("Rank It Up",buffer.toString());
String m = buffer.toString();
String[] data = m.split(" ");
String[] data = m.split(" ");
String name2 = (data.length > 0) ? data[0] : "";
String surname2 = (data.length > 1) ? data[1] : "";
String idnumber2 = (data.length > 2) ? data[2] : "";
name1.setText(name2);
surname1.setText(surname2);
idnumber1.setText(idnumber2);
} catch (FileNotFoundException e) {
Toast.makeText(this, "File Not Found", Toast.LENGTH_LONG).show();
} catch (IOException e){
e.printStackTrace();
}
Toast.makeText(this, "Data found", Toast.LENGTH_LONG).show();
}
public void back(View view){
Toast.makeText(this, "Main page",Toast.LENGTH_LONG).show();
Intent intent = new Intent(this, profile.class);
startActivity(intent);
}
的問題是,爲什麼所有的數據都顯示在一行
謝謝你的回答。 – RankItUpProject
我可以成功。非常感謝你。 – RankItUpProject