On nothing selected event : ListView « UI « Android






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

1.Using ExpandableListView
2.Using ListView
3.Using SimpleAdapter to fill data to ListView
4.Custom cell Renderer for ListView
5.Provide xml layout for ListView Item
6.Fill contact information to ListView
7.ListView.CHOICE_MODE_MULTIPLE
8.Use AbsListView OnScrollListener(AbsListView.OnScrollListener), AbsListView#setOnItemScrollListener(AbsListView.OnItemScrollListener)} to display the first letter of the visible range of cheeses.
9.This demo illustrates the use of CHOICE_MODE_MULTIPLE_MODAL, a.k.a. selection mode on ListView.
10.FileList extends ListView
11.set ListView Height Based On Children
12.Adding a List
13.Lunch List
14.Get Item index in item click event
15.Create List