EditText txtInput; Button btnAdd; Button btnSave; ListView list; ArrayList<string> lists; ArrayAdapter<string> aa; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtInput = (EditText)findViewById(R.id.txtInput); btnAdd = (Button)findViewById(R.id.btnAdd); btnSave = (Button)findViewById(R.id.btnSave); list = (ListView)findViewById(R.id.list); btnAdd.setOnClickListener(this); //txtInput.setOnKeyListener(this); lists = new ArrayList<string>(); aa = new ArrayAdapter<string>(this, android.R.layout.simple_list_item_1, lists); list.setAdapter(aa); btnSave.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //still dont know what to do here list.getAdapter(); } }); list.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView int position, long id) { String text = parent.getItemAtPosition(position).toString(); txtInput.setText(text); } }); list.setOnItemLongClickListener(new OnItemLongClickListener(){ @Override public boolean onItemLongClick(AdapterView int position, long id) { Toast.makeText(MainActivity.this, "Deleted!", Toast.LENGTH_SHORT).show(); aa.remove((String) list.getAdapter().getItem(position)); return true; }}); } private void ADD(String item){ if(item.length() > 0){ this.lists.add(item); this.aa.notifyDataSetChanged(); this.txtInput.setText(""); } } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void onClick(View v) { if(v == this.btnAdd){ this.ADD(this.txtInput.getText().toString()); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)