Note that there are some explanatory texts on larger screens.

plurals
  1. PODynamically adding items to listview
    primarykey
    data
    text
    <p>I am making an android application that needs to use a ListView. Once a user presses a menubutton, it pops up a popupwindow containing a TextView, EditText and two Buttons, "Ok" and "Cancel". Once the user presses "Ok", the text inside the EditText should be added to the ListView. And the cancel Button is obvious. I also want to be able to long press on a ListView item to open a popupwindow containing a delete Button. How can I make this possible? I am using this code so far:</p> <pre><code>public class NotesActivity extends ListActivity { /** Called when the activity is first created. */ Button AddItemToListView; static final String[] COUNTRIES = new String[] { "Matte på A1 med Ole", "Engelsk på klasserommet", "Film på A1 etter friminuttet" }; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notes); setListAdapter((ListAdapter) new ArrayAdapter&lt;String&gt;(this, R.layout.list_item, COUNTRIES)); ListView lv = getListView(); lv.setTextFilterEnabled(true); lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) { // When clicked, show a toast with the TextView text Toast.makeText(getApplicationContext(), "Note: " + ((TextView) view).getText(), Toast.LENGTH_SHORT).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu meny) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.listviewmenubuttons, meny); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case R.id.AddItemToListView: Toast.makeText(NotesActivity.this, "Add note button pressed", Toast.LENGTH_SHORT) .show(); break; } return true; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload