Example usage for android.widget ListView.OnItemClickListener ListView.OnItemClickListener

List of usage examples for android.widget ListView.OnItemClickListener ListView.OnItemClickListener

Introduction

In this page you can find the example usage for android.widget ListView.OnItemClickListener ListView.OnItemClickListener.

Prototype

ListView.OnItemClickListener

Source Link

Usage

From source file:com.lingeringsocket.mobflare.Main.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);//  w  w  w . j av a  2 s  . co m
    emptyMessage = getString(R.string.empty_message);
    ListView flareListView = (ListView) findViewById(R.id.flare_list);
    flareList = new ArrayList<String>();
    arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, android.R.id.text1,
            flareList);
    flareListView.setAdapter(arrayAdapter);
    flareListView.setOnItemClickListener(new ListView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            String flareName = flareList.get((int) id);
            if (flareName.equals(emptyMessage)) {
                onCreateClicked(view);
                return;
            }
            Intent i = new Intent(Main.this, WaitFlare.class);
            i.putExtra(FlareTimer.FLARE_NAME, flareName);
            startActivity(i);
        }
    });

    rpcCoordinator = new RpcCoordinator(this);
    refresh();
}

From source file:com.torygaurnier.openpalette.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved_state) {
    view = inflater.inflate(R.layout.main_fragment, container, false);
    activity = (MainActivity) getActivity();
    clipboard = (ClipboardManager) activity.getSystemService(activity.CLIPBOARD_SERVICE);

    /**/*from  w w  w  . j av  a2  s .  c  om*/
     * Setup Drawer for list of Palettes
     */
    drawer_layout = (DrawerLayout) view.findViewById(R.id.rootDrawerLayout);
    drawer_toggle = new ActionBarDrawerToggle(activity, drawer_layout, R.drawable.ic_navigation_drawer,
            R.string.drawer_open, R.string.drawer_close) {
        // Called when drawer closes
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            activity.refresh();
        }

        // Called when drawer opens
        public void onDrawerOpened(View drawer_view) {
            super.onDrawerOpened(drawer_view);
            activity.refresh();
        }
    };

    drawer_layout.setDrawerListener(drawer_toggle);

    // Set onclick listeners for 'new palette' buttons
    view.findViewById(R.id.createFirstPaletteButton).setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            new EditPaletteDialog(activity).show();
        }
    });
    view.findViewById(R.id.newPaletteButton).setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            new EditPaletteDialog(activity).show();
        }
    });

    // Get palette list view by it's ID, setup PaletteList
    palette_list_view = (ListView) view.findViewById(R.id.paletteListView);
    palette_list = PaletteList.getInstance();
    palette_list_view.setAdapter(palette_list.getAdapter());

    // Set on click listener for palette list view
    palette_list_view.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView adapter_view, View view, int position, long id) {
            // User clicked a list item, select it
            palette_list.setSelectedPosition(position);
        }
    });

    /**
     * Setup list view for current Palette
     */
    // Get palette view by its ID
    palette_view = (DragSortListView) view.findViewById(R.id.paletteView);
    palette_view.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView adapter_view, View view, int position, long id) {
            String hex = ((HexColor) adapter_view.getItemAtPosition(position)).getHex();
            ClipData clip = ClipData.newPlainText("hex", hex);
            clipboard.setPrimaryClip(clip);
            Msg.log(Msg.INFO, "palette_view->onItemClick()", hex + " copied to clipboard");
        }
    });

    // Register context menu for color actions
    registerForContextMenu(palette_view);

    activity.getActionBar().setDisplayHomeAsUpEnabled(true);
    activity.getActionBar().setHomeButtonEnabled(true);

    activity.refresh();
    return view;
}

From source file:com.andreadec.musicplayer.MainActivity.java

@SuppressLint({ "InlinedApi", "NewApi" })
@Override//from w  ww  .  j ava 2  s.com
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    if (preferences.getBoolean(Constants.PREFERENCE_DISABLELOCKSCREEN, Constants.DEFAULT_DISABLELOCKSCREEN)) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); // Disable lock screen for this activity
    }

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    if (preferences.getBoolean(Constants.PREFERENCE_SHOWHELPOVERLAYMAINACTIVITY, true)) {
        final FrameLayout frameLayout = new FrameLayout(this);
        LayoutInflater layoutInflater = getLayoutInflater();
        layoutInflater.inflate(R.layout.layout_main, frameLayout);
        layoutInflater.inflate(R.layout.layout_helpoverlay_main, frameLayout);
        final View overlayView = frameLayout.getChildAt(1);
        overlayView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                frameLayout.removeView(overlayView);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean(Constants.PREFERENCE_SHOWHELPOVERLAYMAINACTIVITY, false);
                editor.commit();
            }
        });
        setContentView(frameLayout);
    } else {
        setContentView(R.layout.layout_main);
    }

    pages = new String[4];
    pages[PAGE_BROWSER] = getResources().getString(R.string.browser);
    pages[PAGE_PLAYLISTS] = getResources().getString(R.string.playlist);
    pages[PAGE_RADIOS] = getResources().getString(R.string.radio);
    pages[PAGE_PODCASTS] = getResources().getString(R.string.podcasts);
    fragmentManager = getSupportFragmentManager();
    setTitle(pages[currentPage]);

    /* NAVIGATION DRAWER */
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            setTitle(pages[currentPage]);
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            setTitle(getResources().getString(R.string.app_name));
        }
    };
    drawerLayout.setDrawerListener(drawerToggle);
    if (Build.VERSION.SDK_INT >= 11)
        getActionBar().setDisplayHomeAsUpEnabled(true);
    drawerContainer = (RelativeLayout) findViewById(R.id.navigation_container);
    drawerList = (ListView) findViewById(R.id.navigation_list);
    navigationAdapter = new NavigationDrawerArrayAdapter(this, pages);
    drawerList.setAdapter(navigationAdapter);
    drawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(@SuppressWarnings("rawtypes") AdapterView parent, View view, int position,
                long id) {
            openPage(position);
            drawerLayout.closeDrawer(drawerContainer);
        }
    });
    buttonQuit = findViewById(R.id.navigation_buttonQuit);
    buttonQuit.setOnClickListener(this);

    if (Build.VERSION.SDK_INT >= 19) {
        // Android 4.4+ only
        boolean translucentStatus = preferences.getBoolean(Constants.PREFERENCE_TRANSLUCENTSTATUSBAR,
                Constants.DEFAULT_TRANSLUCENTSTATUSBAR);
        boolean translucentNavigation = preferences.getBoolean(Constants.PREFERENCE_TRANSLUCENTNAVIGATIONBAR,
                Constants.DEFAULT_TRANSLUCENTNAVIGATIONBAR);

        if (translucentStatus)
            getWindow().addFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (translucentNavigation)
            getWindow().addFlags(LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        if (translucentStatus) {
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.actionBarBackground);
        }
    }

    textViewArtist = (TextView) findViewById(R.id.textViewArtist);
    textViewTitle = (TextView) findViewById(R.id.textViewTitle);
    textViewTime = (TextView) findViewById(R.id.textViewTime);
    imageViewSongImage = (ImageView) findViewById(R.id.imageViewSongImage);
    imageButtonPrevious = (ImageButton) findViewById(R.id.imageButtonPrevious);
    imageButtonPlayPause = (ImageButton) findViewById(R.id.imageButtonPlayPause);
    imageButtonNext = (ImageButton) findViewById(R.id.imageButtonNext);
    seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
    seekBar2 = (SeekBar) findViewById(R.id.seekBar2);
    imageButtonShowSeekbar2 = (ImageButton) findViewById(R.id.imageButtonShowSeekbar2);
    imageButtonShuffle = (ImageButton) findViewById(R.id.imageButtonShuffle);
    imageButtonRepeat = (ImageButton) findViewById(R.id.imageButtonRepeat);
    imageButtonRepeatAll = (ImageButton) findViewById(R.id.imageButtonRepeatAll);
    buttonBassBoost = (Button) findViewById(R.id.buttonBassBoost);
    buttonEqualizer = (Button) findViewById(R.id.buttonEqualizer);
    buttonShake = (Button) findViewById(R.id.buttonShake);

    imageButtonShuffle.setOnClickListener(this);
    imageButtonRepeat.setOnClickListener(this);
    imageButtonRepeatAll.setOnClickListener(this);
    buttonBassBoost.setOnClickListener(this);
    buttonEqualizer.setOnClickListener(this);
    buttonShake.setOnClickListener(this);

    imageButtonShowSeekbar2.setOnClickListener(this);
    imageButtonPrevious.setOnClickListener(this);
    imageButtonPlayPause.setOnClickListener(this);
    imageButtonNext.setOnClickListener(this);
    seekBar1.setOnSeekBarChangeListener(this);
    seekBar1.setClickable(false);
    seekBar2.setOnSeekBarChangeListener(this);
    textViewTime.setOnClickListener(this);

    showSongImage = preferences.getBoolean(Constants.PREFERENCE_SHOWSONGIMAGE, Constants.DEFAULT_SHOWSONGIMAGE);
    imagesCache = new LruCache<String, Bitmap>(Constants.IMAGES_CACHE_SIZE);

    serviceIntent = new Intent(this, MusicService.class);
    startService(serviceIntent); // Starts the service if it is not running

    if (preferences.getBoolean(Constants.PREFERENCE_OPENLASTPAGEONSTART,
            Constants.DEFAULT_OPENLASTPAGEONSTART)) {
        openPage(preferences.getInt(Constants.PREFERENCE_LASTPAGE, Constants.DEFAULT_LASTPAGE));
    } else {
        openPage(PAGE_BROWSER);
    }
    loadSongFromIntent();

    layoutPlaybackControls = findViewById(R.id.layoutPlaybackControls);
    if (preferences.getBoolean(Constants.PREFERENCE_ENABLEGESTURES, Constants.DEFAULT_ENABLEGESTURES)) {
        final GestureDetectorCompat gestureDetector = new GestureDetectorCompat(this,
                new PlayerGestureListener());
        View layoutTop = findViewById(R.id.layoutTop);
        layoutTop.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }
        });
        if (preferences.getBoolean(Constants.PREFERENCE_SHOWPLAYBACKCONTROLS,
                Constants.DEFAULT_SHOWPLAYBACKCONTROLS)) {
            layoutPlaybackControls.setVisibility(View.VISIBLE);
        }
    } else {
        layoutPlaybackControls.setVisibility(View.VISIBLE);
    }
}