gpt4 book ai didi

android - 将 clickEvent 添加到 int 数组

转载 作者:行者123 更新时间:2023-11-30 03:03:34 26 4
gpt4 key购买 nike

共有三个图标。我把图标放在整数数组上。我怎样才能给他们点击监听器事件。 icon0、icon1、icon2 事件不同。我想给他们点击事件。但我做不到。如何分别给图标点击事件

我使用 wheel.gama jar 并且这个图标不在 xml 中。它们在 drawable 文件夹中

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();
}



}

最佳答案

drawables 没有 onClick-Events。您需要将事件监听器设置为 Wheel(例如 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;
}
}
}

关于android - 将 clickEvent 添加到 int 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22185054/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com