EditText / TextView到ListView

我有两个活动。 FirstActivity包含一个转到SecondActivity的onClick按钮。 SecondActivity包含多个EditText和一个Save按钮。单击保存按钮后,我想在ListView的FirstActivity中显示所有数据。我在FirstActivity中使用TextView做到了,但是我无法使用ListAdapter。

public class MainActivity extends AppCompatActivity{

    private ListView list_view;
    List list;
    private Button FloatingActionButton;

    private TextView vortext;
    private TextView nachtext;
    private TextView strtext;
    private TextView orttext;
    private TextView text1;

    private ArrayAdapter<String> ArrayAdapter;




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);




        vortext = (TextView) findViewById(R.id.vortext);
        nachtext = (TextView) findViewById(R.id.nachtext);
        strtext = (TextView) findViewById(R.id.strtext);
        orttext = (TextView) findViewById(R.id.orttext);
        list = new ArrayList<String>();






        vortext.setText(getIntent().getStringExtra("Vorname"));
        nachtext.setText(getIntent().getStringExtra("Nachname"));
        strtext.setText(getIntent().getStringExtra("Strasse"));
        orttext.setText(getIntent().getStringExtra("Ort"));



        list_view =  (ListView) findViewById(R.id.list_view);


        String [] strings = new String[] {};
        ArrayAdapter<HashMap<String,String>> listItem = new ArrayAdapter<HashMap<String, String>>();
       HashMap<String,String>map;

       map = new HashMap<String, String>();
       map.put();
       listItem.add(map);


        ArrayAdapter = new ArrayAdapter<String>(this,R.layout.listitem,strings);

        FloatingActionButton myFab =  findViewById(R.id.fab);
        myFab.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                startActivityForResult(new Intent(MainActivity.this, DetailActivity.class), 12);

            }




        });
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode == 12) {
            String vs = data.getExtras().getString("vs");
            Log.d("MainActivity",vs);

            String ns = data.getExtras().getString("ns");
            Log.d("MainActivity",ns);

            String ss = data.getExtras().getString("ss");
            Log.d("MainActivity",ss);

    String os = data.getExtras().getString("os");
            Log.d("MainActivity",os);
        }


    }
}

这是我的详细信息

public class DetailActivity extends AppCompatActivity {


    private  EditText Vorname;
    private  EditText Nachname;
    private  EditText Strasse;
    private  EditText Ort;
    private  Button Save;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);

        Vorname  = (EditText) findViewById(R.id.Vorname);
        Nachname  =  (EditText)findViewById(R.id.Nachname);
        Strasse  =  (EditText)findViewById(R.id.Strasse);
        Ort  = (EditText) findViewById(R.id.Ort);
        Save    =  (Button) findViewById(R.id.Save);

        Save.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String vs = Vorname.getText().toString();
                String ns = Nachname.getText().toString();
                String ss = Strasse.getText().toString();
                String os = Ort.getText().toString();






                Intent intent = new Intent(getBaseContext(),MainActivity.class);
                intent.putExtra("vs", vs);
                intent.putExtra("ns",ns);
                intent.putExtra("ss",ss);
                intent.putExtra("os",os);


                setResult(RESULT_OK, intent);
                finish();
            }
        });

    }

}
评论