我想輸出一個可讀的html或文本文件的數組列表。我認爲這應該是非常簡單的,但它只是在逃避我。所以在這裏。我有一個日誌文件,當玩家被淘汰出局時,這些日誌文件就會被填充。這裏的屏幕截圖:
簡單的ArrayList到可讀的HTML
然後我點擊保存日誌按鈕將其導出到一個文件。無論該文件是HTML或TXT,輸出實在是不可用的:
那麼,如何讓我的HTML或文本文件,以表明它在做屏幕上的活動?
感謝, Hendo
下面是該活動的代碼...
import static com.feltinghendo.www.pokerdbtest.MainActivity.userList;
公共類GameLog擴展AppCompatActivity { 私有靜態最後絃樂TAG = 「GameLog」;
TextView gameLog;
ListView lvLog;
Button btnSave, btnClear;
private static ArrayList<String> bustOutLog = new ArrayList<>();
ArrayAdapter arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game_log);
gameLog = (TextView) findViewById(R.id.tvGameLog);
lvLog = (ListView) findViewById(R.id.lvLog);
btnSave = (Button) findViewById(R.id.btnSave);
btnClear = (Button) findViewById(R.id.btnClear);
gameLog.setText("Game Log");
Bundle extras = getIntent().getExtras();
if (extras != null) {
String bustLog = extras.getString("BUSTED");
Log.d(TAG, "onCreate: " + bustLog);
bustOutLog.add(bustLog);
}
lvLog.setChoiceMode(ListView.CHOICE_MODE_NONE);
arrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, bustOutLog);
lvLog.setAdapter(arrayAdapter);
lvLog.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "onItemLongClick: starts");
String undoBust = bustOutLog.get(position);
Log.d(TAG, "onItemLongClick: UNDO str = " + undoBust);
String[] cut = undoBust.split(" ");
String undo = cut[0];
Log.d(TAG, "onItemLongClick: remove player " + undo);
String sql = "UPDATE players SET active = 1 WHERE name = '" + undo + "'";
Log.d(TAG, "onItemLongClick: undo sql" + sql);
userList.execSQL(sql);
// MainActivity.userList.execSQL( 「UPDATE SET玩家活性= 1 WHERE NAME = '」 +撤消+ 「'」);
UserList.boughtIn.add(undo);
bustOutLog.remove(position);
arrayAdapter.notifyDataSetChanged();
return true;
}
});
arrayAdapter.notifyDataSetChanged();
UserList.spinnerArrayAdapter.notifyDataSetChanged();
}
public void saveLog(View view) {
// get permission - if we don't already have permission, we must request it from the user.
// Very quick solution - DO NOT JUST DO THIS IN PRODUCTION CODE! Refer to Section 10.
int hasWriteESPermission = ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (hasWriteESPermission == PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "onCreate: permission granted");
} else {
Log.d(TAG, "onCreate: requesting permission");
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
}
try {
FileOutputStream fos =
new FileOutputStream(
new File(Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_DOWNLOADS), "gamelog.html"));
ObjectOutputStream os = new ObjectOutputStream(fos);
os.writeObject(bustOutLog);
os.close();
Log.d(TAG, "saveLog: File written");
Toast.makeText(this, "File Written", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, "saveLog: File Not Written");
Toast.makeText(this, "File Not Written", Toast.LENGTH_SHORT).show();
}
}
public void clearLog(View view) {
bustOutLog.clear();
arrayAdapter.notifyDataSetChanged();
}
}
你的代碼在哪裏? – DCON