编辑:我再次问了这个问题。因为我无法对这个问题采取真实的答案,所以你可以寻找完整的答案
我尝试将此图标点击,但我无法做到。我怎么能知道这个图标clickevent你知道吗?
并且这些图标不在xml中。它们位于drawable文件夹中。 这是方法,我们可以使用它methods about gama wheel library
这是我的尝试
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.ImageButton;
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);
}
/*I am delete it
@Override
public void onResume(){
//first try
ImageView iconsa[] = new ImageView[icons[0]];
ImageView iconsa1[] = new ImageView[icons[1]];
ImageView iconsa2[] = new ImageView[icons[1]];
//second try
String arrayStr = Arrays.toString (icons);
String[] aa = arrayStr.split(",");
String[] strArray = new String[] {arrayStr};
for(int i=0;i<strArray.length;i++)
{
iconsa[i] = new ImageView(wheel.getContext());
iconsa[i].setOnClickListener(onClick());
}
}
*/
// I am delete it too
/* private OnClickListener onClick() {
Toast.makeText(SampleWheelActivity.this, "test", Toast.LENGTH_SHORT).show();
// how can ı Reach id on drawable folder icons
return null;
} */
private Drawable[] getDrawableFromData(int[] data) {
Drawable[] ret = new Drawable[data.length];
for (int i = 0; i < data.length; i++) {
ret[i] = res.getDrawable(data[i]);
}
return ret;
}
//I try it but how can I give clickevent icon1.. when click icon1 it should go other page
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ImageView iv = new ImageView(this);
iv.setImageResource(R.drawable.icon1);
}
}
答案 0 :(得分:0)
你正在使用错误的倾听者。您需要使用此Reference中的WheelAdapter.OnItemSelectionUpdatedListener
。
这是我的工作代码。
public class SampleWheelActivity extends Activity implements OnItemClickListener
{
private Wheel wheel;
private Resources res;
private int[] icons =
{
R.drawable.icon00, R.drawable.icon01, R.drawable.icon02,
R.drawable.icon03, R.drawable.icon04, R.drawable.icon05,
R.drawable.icon06, R.drawable.icon07, R.drawable.icon08,
R.drawable.icon09, R.drawable.icon10, R.drawable.icon11 };
@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(800);
wheel.setOnItemClickListener(this);
}
private Drawable[] getDrawableFromData(int[] data)
{
Drawable[] ret = new Drawable[data.length];
for (int i = 0; i < data.length; i++) {
ret[i] = res.getDrawable(data[i]);
}
return ret;
}
// This method will get fire when you click on any image.
@Override
public void onItemClick(WheelAdapter<?> parent, View view, int position, long id)
{
System.out.println ( "id :" + id );
}
}
在onItemClick()的帮助下点击任何图像,我成功地获得了结果。