I want the text from Edittext with one activation to be included in the Listview, which is located in the other activation. I wrote the code, it seems to be working, yes, not a damn .... It does not give out any errors, but after I type the text and press the button, the application stupidly closes ....

I would be extremely grateful for the help.

Listview id = listView; Button id = button; Edittext id = setText; 

Here is the code.

This is MainActivity

 public class MainActivity extends AppCompatActivity implements View.OnClickListener { EditText setText; Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setText = (EditText) findViewById(R.id.setText); button = (Button) findViewById(R.id.button); button.setOnClickListener(this); } @Override public void onClick(View v) { Intent intent = new Intent(); intent.putExtra("text", setText.getText().toString()); setResult(RESULT_OK, intent); finish(); } } 

This is the second activation where the listview is located.

 public class Intent_Activity extends AppCompatActivity { ListView listView; ArrayList<HashMap<String, Object>> data = new ArrayList<>(); HashMap<String, Object> map; final String TEXT = "text"; String text = ""; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.intent_activity); listView = (ListView) findViewById(R.id.listView); Intent intent = new Intent(this, Intent_Activity.class); startActivityForResult(intent, 1); data.add(map); String[] from = {TEXT}; int[] to = {R.id.textView}; SimpleAdapter adapter = new SimpleAdapter(this, data, R.layout.item, from, to); listView.setAdapter(adapter); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (data == null) { return; } text = data.getStringExtra("text"); map = new HashMap<>(); map.put(TEXT, text); } } 
  • one
    Look in the LogCat , there will be a stack-trace exception. - post_zeew
  • Lay out a draft of this on the git hub, then maybe I will solve this problem - NeDoProgrammer

0