問題が発生しました。sdcard ディレクトリから xml ファイルを読み取り、少なくとも内容を保存してから、xml タグ間の値を選択する必要がありますが、読み取りと文字列への変換を手伝っていただければ、すでに非常に便利です。
ファイルディレクトリ: Environment.getExternalStorageDirectory()+ "/SCity/"+now //currentmillis ファイル名: Notes.xml
SAX または DOM パーサーを使用して xml を解析する必要があります。次のリンクに従ってください。
http://developer.android.com/training/basics/network-ops/xml.html
ファイルをアセット フォルダーに配置します。
public class Main extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Load XML for parsing
AssetManager assetManager = getAssets();
InputStream inputStream = null;
try {
inputStream = assetManager.open("test.xml");
} catch (IOException e) {
}
String s = readTextFile(inputStream);
TextView tv = (TextView)findViewById(R.id.textView1);
tv.setText(s);
}
});
}
private String readTextFile(InputStream inputStream) {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
byte buf[] = new byte[1024];
int len;
try {
while ((len = inputStream.read(buf)) != -1) {
outputStream.write(buf, 0, len);
}
outputStream.close();
inputStream.close();
} catch (IOException e) {
}
return outputStream.toString();
}
}