2017-04-07 3 views
0

管理者がショーに車を追加できるショールームアプリケーションがあります。デザインは準備が整いました。私は、このファイルがデバイスの外部記憶装置に格納される単純なファイルにすべての値を格納する必要があります。Androidスタジオ:外部記憶装置のファイルに複数の編集テキストと画像を追加する必要があります

public EditText make; 
public EditText model; 
public EditText year; 
public EditText price; 
public EditText trans; 
public EditText color; 
public Button addcar; 
public Button uploadimg; 
public Button cancel; 

String[] toaddcar = { 
     make.getText().toString(), 
     model.getText().toString(), 
     year.getText().toString(), 
     price.getText().toString(), 
     trans.getText().toString(), 
     color.getText().toString() 
}; 
public String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/ListCars"; 

のOnCreateメソッドで私はちょうどこれを追加します:

make = (EditText)findViewById(R.id.txtMake); 
    model = (EditText)findViewById(R.id.txtModel); 
    year = (EditText)findViewById(R.id.txtYear); 
    price = (EditText)findViewById(R.id.txtPrice); 
    trans = (EditText)findViewById(R.id.txtTrans); 
    color = (EditText)findViewById(R.id.txtColor); 
    addcar = (Button)findViewById(R.id.btnAdd); 
    uploadimg = (Button)findViewById(R.id.btnUpload); 
    cancel = (Button)findViewById(R.id.btnCancel); 

    File dir = new File(path); 
    dir.mkdirs(); 

ザ・は私が作ったこの2つの方法:私はすべてのボタンとエディットテキストを宣言し

これは私のコードです
public void btnAdd(View view){ 
    File file = new File(path + "/SavedCars"); 
    String saveText = String.valueOf(toaddcar); 
    Toast.makeText(getApplicationContext(),"Saved", Toast.LENGTH_LONG).show(); 
     Save(file,saveText); 

} 
public static void Save(File file, String[] data) throws IOException { 
    FileOutputStream fos = null; 
    try 
    { 
     fos = new FileOutputStream(file); 
    } 
    catch (FileNotFoundException e) {e.printStackTrace();} 
    try 
    { 
     try 
     { 
      for (int i = 0; i<data.length; i++) 
      { 
       fos.write(data[i].getBytes()); 
       if (i < data.length-1) 
       { 
        fos.write("\n".getBytes()); 
       } 
      } 
     } 
     catch (IOException e) {e.printStackTrace();} 
    } 
    finally 
    { 
     fos.close(); 
    } 
} 

問題は、保存したいファイルにすべてのedittextを実装する方法がわかりませんさらに画像をアップロードしてこのファイルに保存することもできます。誰かが私を助けることができる場合、私は実際にそれをappreaciate :)

おかげ

答えて

1

を私はあなたに物事が行く方法&を読み取るかについて理論的な簡単なを与えるでしょう。

アクティビティでTabLayoutとViewPagerを追加して、タブ&の内容を表示します。各画面をタブクリックで表示するには、フラグメントを作成します。

フラグメンテーションのロード&の表示を管理するには、FragmentStatePagerAdapterを使用します。

Thisは非常に簡単です&良いチュートリアルです。

+0

ohhありがとうございました。私が漂着していたもの –

+0

大歓迎! :) –

関連する問題