2014-03-04 59 views
1

有三個圖標。我把圖標放在整數數組上。我該如何給他們點擊監聽器事件。 icon0,icon1,icon2事件不同。我想給他們點擊事件。但我做不到。我怎樣才能單獨給點擊事件圖標將clickEvent添加到int數組

我用wheel.gama jar和這個圖標不在xml中。他們在可繪製的文件夾

package com.myproject.gama; 

import java.util.Arrays; 

import com.digitalaria.gama.wheel.Wheel; 
import com.digitalaria.gama.wheel.WheelAdapter; 
import android.app.Activity; 
import android.content.res.Resources; 
import android.graphics.drawable.Drawable; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.*; 
import android.view.View.*; 
import android.widget.AdapterView.OnItemClickListener; 
import android.widget.AdapterView.OnItemSelectedListener; 
import android.widget.ImageView; 

import android.util.Log; 

public class SampleWheelActivity extends Activity { 

    private static final String TAG = SampleWheelActivity.class.getSimpleName(); 

    private Wheel wheel; 
    public WheelAdapter<Adapter> adapter; 
    private Resources res; 
    public int[] icons = { 
     R.drawable.icon1, R.drawable.icon0 , R.drawable.icon2}; 
    ImageView t; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.main); 

     init(); 
    } 

    private void init() { 
     res = getApplicationContext().getResources(); 
     wheel = (Wheel) findViewById(R.id.wheel);  
     wheel.setItems(getDrawableFromData(icons)); 
     wheel.setWheelDiameter(400); 
    } 

    @Override 
    public void onResume(){ 

     for (int i = 0; i < icons.length; i++) { 
      t= new ImageView(SampleWheelActivity.this); 
       t.setId(i); 
       t.setOnClickListener((OnClickListener) this); 
        super.onResume(); 
    } 



} 

回答

1

繪圖並沒有onClick事件。您需要將事件監聽器設置爲滾輪(例如OnWheelChangedListener),然後處理該事件。在那裏你可以打開車輪的選定ID。

編輯:

代碼:

wheel.addChangingListener(new OnWheelChangedListener() { 
    public void onChanged(WheelView wheel, int oldValue, int newValue) { 
     switch(newValue) { 
      case 0: 
       // icon1 is selected as it has index 0 
       // do something 
       break; 
      case 1: 
       // icon0 is selected as it has index 1 
       // do something else 
       break; 
      case 2: 
       // icon2 is selected as it has index 2 
       // and again something else 
       break; 
     } 
    } 
} 
+0

我能否改變它的ImageView – 19052013

+0

和哪能事件監聽器設置爲輪.. :( – 19052013

+0

例如添加爲您初始化方法 – Christian