gpt4 book ai didi

android - gama wheel 菜单栏 - 如何在 Android 中为图标添加点击事件

转载 作者:太空狗 更新时间:2023-10-29 15:05:37 24 4
gpt4 key购买 nike

编辑:我又问了这个问题..因为我不能对这个问题做出正确的回答所以你可以寻找完整的答案

Answer this question

我尝试将此图标设为可点击,但我做不到。我怎样才能使这个图标点击事件你知道吗?

并且这些图标不在 xml 中。它们位于可绘制文件夹中。这是给出的方法,我们可以使用它吗 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);

}

}

最佳答案

您使用了错误的监听器。您需要使用此 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() 的帮助下,我在点击任何图像时成功地获得了结果。

关于android - gama wheel 菜单栏 - 如何在 Android 中为图标添加点击事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22243655/

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