I am trying to get user input from Edit Text to a List List, I saw the answer to this similar question, but I cannot figure it out
I tried this, did not receive errors from the IDE, but it does not work
public class ListtestActivity extends Activity { Button bt; EditText et; TextView tv; ListView lv; ArrayAdapter<String> adapter; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bt = (Button) findViewById(R.id.button1); et = (EditText) findViewById(R.id.editText1); tv = (TextView) findViewById(R.id.textView1); lv = (ListView) findViewById(R.id.listView1); String input = et.getText().toString(); String[] values = new String[] {"", input}; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, values); lv.setAdapter(adapter);
I also tried
public class ListtestActivity extends Activity { ArrayAdapter<String> m_adapter; ArrayList<String> m_listItems = new ArrayList<String>(); Button bt; EditText et; TextView tv; ListView lv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); bt = (Button) findViewById(R.id.button1); et = (EditText) findViewById(R.id.editText1); tv = (TextView) findViewById(R.id.textView1); lv = (ListView) findViewById(R.id.listView1); m_adapter = new ArrayAdapter<String>(this, R.layout.main, m_listItems); lv.setAdapter(m_adapter); final String input = et.getText().toString(); bt.setOnClickListener(new View.OnClickListener() { public void onClick(View v) {
Any help would be greatly appreciated.
thanks
* Very new for Android / Java / SO
source share