I am trying to enter something into two different EditTexts, then display them onto one item of a list. My code looks like this, and compiles, but does not add the item. Any help appreciated.
package com.painLogger;
import java.util.ArrayList; ///ALL IMPORTS
public class PainLoggerActivity extends Activity implements OnClickListener,
OnKeyListener {
/** Called when the activity is first created. */
EditText txtItem;
EditText txtItem2;
Button btnAdd;
ListView listItems;
ArrayAdapter<String> aa;
List<HashMap<String, String>> painItems = new ArrayList<HashMap<String, String>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtItem = (EditText)findViewById(R.id.txtItem);
txtItem2 = (EditText)findViewById(R.id.txtItem2);
btnAdd = (Button)findViewById(R.id.btnAdd);
listItems = (ListView)findViewById(R.id.listItems);
btnAdd.setOnClickListener(this);
String[] from = new String[] {"row_1", "row_2"};
int[] to = new int[] { R.id.row1, R.id.row2};
SimpleAdapter adapter = new SimpleAdapter(this, painItems, R.layout.mylistlayout,
from, to);
listItems.setAdapter(adapter);
}
private void addItem(){
HashMap<String,String>map = new HashMap<String, String>();
map.put("row_1",txtItem.getText().toString());
map.put("row_2",txtItem2.getText().toString());
painItems.add(map);
}
@Override
public void onClick(View v) {
if(v == this.btnAdd)
addItem();
}
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN && keyCode ==
KeyEvent.KEYCODE_DPAD_CENTER){
this.addItem();
}
return false;
}
}
Have you tried manually updating the display with
that may help or try to log exactly what is going in and out of your list.