listView elemento dinámico añadir
solíaListView
para agregar dinámicamente el elemento, pero hay un problema acerca de no Agregar con suavidad. hay textView y button en mi listaActividad, quiero presionar el botón, luegoTextView
El texto puede agregarse automáticamente aListView
, pero presioné el botón, no funciona, a menos que después de ingresar el contenido, presione la tecla "OK", luego presione el botón,TextView's
el texto se puede agregar automáticamente aListView
. No se por que. Si continúo presionando el botón 3 veces, luego presione la tecla "Ok", el contenido
añadir lista automáticamente
Ver pero 3 veces.
public class DynamicListItems extends ListActivity {
private static final String ITEM_KEY = "key";
ArrayList<HashMap<String, String>> list= new ArrayList<HashMap<String, String>>();
private SimpleAdapter adapter;
private EditText newValue;@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dynamic_list);
newValue = (EditText) findViewById(R.id.new_value_field);
setListAdapter(new SimpleAdapter(this, list, R.layout.row, new String[] { ITEM_KEY }, new int[] { R.id.list_value }));
((ImageButton) findViewById(R.id.button)).setOnClickListener(getBtnClickListener());
}
private OnClickListener getBtnClickListener() {
return new OnClickListener() {
public void onClick(View view) {
try {
HashMap<String, String> item = new HashMap<String, String>();
item.put(ITEM_KEY, newValue.getText().toString());
list.add(item);
adapter.notifyDataSetChanged();
} catch (NullPointerException e) {
Log.i("[Dynamic Items]", "Tried to add null value");
}
}
};
}}
¿Cómo eliminar dinámicamente el elemento?
dynamic_list.xml solo contiene listView, button, textViewrow.xml contieneTextView