Hi
i made a small test app with 2 screens. the first screen contains an EditText and a Button. The second screen is just a simple ListActivity showing 3 static items. The ListActivity is started when the user clicks the Button on the first screen or when the enter key was hit in the TextEdit. The weird thing is if the ListActivity was started by pressing the enter key in the EditText view, then the first list item is selected right after the startup. if it was started by hitting the button, everything is normal - no list item is selected.
that's the code that starts the ListActivity.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.startup);
final Button b = (Button)findViewById(R.id.but);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startList();
}
});
final EditText t = (EditText)findViewById(R.id.in_text);
t.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
startList();
return true;
}
});
}
public void startList(){
Intent i = new Intent(this, TestList.class);
startActivity(i);
}
and this is the code of the ListActivity
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
String[] str = {"a", "b", "c"};
ListAdapter adapter = new ArrayAdapter<String>(this, R.layout.list_item, str){
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row =
null == convertView ?
inflater.inflate(R.layout.list_item, null) :
convertView;
String s = getItem(position);
TextView tvid = (TextView)row.findViewById(R.id.word_suggestion_item_text);
tvid.setText(s);
return row;
}
};
setListAdapter(adapter);
}
any ideas why that happens?
Simon