views:

70

answers:

1

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

+1  A: 

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.

If they use hardware input (e.g., Enter key) immediately before you start the ListActivity, they will not be in touch mode. If they use the touchscreen immediately before you start the ListActivity, they will be in touch mode. The selection highlight is not shown in touch mode. See here for more.

CommonsWare
oh I see, that's a feature and not a bug! now it makes totally sense!thanks
SimonSays