2014-03-04 61 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