On nothing selected event
package app.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
public class Test extends Activity {
ListView listView;
private String[] data = { "1", "2", "3","4", "5", "6" };
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView = new ListView(this);
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, data));
setContentView(listView);
OnItemSelectedListener itemSelectedListener = new OnItemSelectedListener(){
@Override
public void onItemSelected(AdapterView<?> parent, View arg1,
int position, long arg3) {
setTitle("t: "+parent.getItemAtPosition(position).toString());
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
setTitle("");
}
};
listView.setOnItemSelectedListener(itemSelectedListener);
}
}
Related examples in the same category