伽马轮菜单栏 - 如何将点击事件添加到Android的图标 [英] gama wheel menu bar - how to add click events to icons in Android

查看:101
本文介绍了伽马轮菜单栏 - 如何将点击事件添加到Android的图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

编辑:我再次问到这个问题。因为我不能把真正的答案在这个问题上,所以你可以看看完整的答案

<一个href="http://stackoverflow.com/questions/22435794/wheel-menu-bar-how-can-i-give-click-action-to-icons/22449916?noredirect=1#22449916">Answer这个问题

和我尝试这个图标点击,但我不能这样做。我怎样才能makte这个图标clickevent你知道什么办法。

和这些图标在XML。他们对平局能够文件夹中。 这是给的方法我们可以用它

方法>

这是我努力

 包com.myproject.gama;

进口java.util.Arrays中;

进口com.digitalaria.gama.wheel.Wheel;
进口com.digitalaria.gama.wheel.WheelAdapter;

进口android.app.Activity;
进口android.content.res.Resources;
进口android.graphics.drawable.Drawable;
进口android.os.Bundle;
进口android.view.View;
进口android.view.View.OnClickListener;
进口android.widget *。
进口android.view.View *。
进口android.widget.AdapterView.OnItemClickListener;
进口android.widget.AdapterView.OnItemSelectedListener;
进口android.widget.ImageButton;
进口android.widget.ImageView;

进口android.util.Log;

公共类SampleWheelActivity延伸活动{

    私有静态最后字符串变量= SampleWheelActivity.class.getSimpleName();

    私人车轮轮;
    公共WheelAdapter&LT;适配器&GT;适配器;
    私人资源资源;
    公众诠释[]图标= {
         R.drawable.icon1,R.drawable.icon0,R.drawable.icon2};
    ImageView的吨;

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        在里面();
    }

    私人无效的init(){
        RES = getApplicationContext()getResources()。
        车轮=(轮)findViewById(R.id.wheel);
        wheel.setItems(getDrawableFromData(图标));
        wheel.setWheelDiameter(400);


    }
    / *我将其删除
    @覆盖
    公共无效onResume(){

        //第一次尝试
        ImageView的iconsa [] =新的ImageView [图标[0];
        ImageView的iconsa1 [] =新的ImageView [图标[1]];
        ImageView的iconsa2 [] =新的ImageView [图标[1]];

        //第二次尝试
        字符串arrayStr = Arrays.toString(图标);
        串[] AA = arrayStr.split(,);
        的String [] strArray =新的String [] {arrayStr};
        的for(int i = 0; I&LT; strArray.length;我++)
        {
            iconsa [I] =新的ImageView(wheel.getContext());
             iconsa [I] .setOnClickListener(的onClick());

        }
    }
   * /

//我删除它太

/ *私人OnClickListener的onClick(){
         Toast.makeText(SampleWheelActivity.this,测试,Toast.LENGTH_SHORT).show();

//我怎么能上绘制文件夹图标河段ID
        返回null;
    } * /



    私人绘制对象[] getDrawableFromData(INT []数据){
        绘制对象[] RET =新绘制对象[data.length]
        的for(int i = 0; I&LT; data.length;我++){
            RET [I] = res.getDrawable(数据[I]);
        }
        返回RET;
    }

//我尝试,但我怎么能放弃clickevent ICON1 ..当点击ICON1它应该去其他网页

@覆盖
公共无效onItemClick(适配器视图&LT;&GT;母公司视图中查看,INT位置,长的id){
    ImageView的IV =新ImageView的(这一点);
    iv.setImageResource(R.drawable.icon1);

}

}
 

解决方案

您使用的是错误的监听器。你需要使用 WheelAdapter.OnItemSelectionUpdatedListener 此的参考

这是我的工作$ C $下相同。

 公共类SampleWheelActivity扩展活动实现OnItemClickListener
{
    私人车轮轮;
    私人资源资源;
    私人INT []图标=
        {
            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};

    @覆盖
    公共无效的onCreate(包savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        在里面();
    }

    私人无效的init()
    {
        RES = getApplicationContext()getResources()。
        车轮=(轮)findViewById(R.id.wheel);

        wheel.setItems(getDrawableFromData(图标));
        wheel.setWheelDiameter(800);
        wheel.setOnItemClickListener(本);
    }

    私人绘制对象[] getDrawableFromData(INT []数据)
    {
        绘制对象[] RET =新绘制对象[data.length]
        的for(int i = 0; I&LT; data.length;我++){
            RET [I] = res.getDrawable(数据[I]);
        }
        返回RET;
    }


    //此方法将起火,当你点击任何图像。
    @覆盖
    公共无效onItemClick(WheelAdapter&LT;&GT;母公司视图中查看,INT位置,长ID)
    {
        的System.out.println(ID:+ ID);
    }
}
 

我能够成功与onItemClick的)帮助(在任何图像,当点击来获得结果。

edit: I asked this question again.. Because I can not take true answer on this question so you can look for full answer

Answer this question

And I try to this icon clickable but I can not do . How can I makte this icons clickevent do you know any way.

and these icons are not in xml. They are on draw able folder. this is gives methods can we use it methods about gama wheel library

And this is my trying

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

}

}

解决方案

You are using wrong listener. You need to use WheelAdapter.OnItemSelectionUpdatedListener from this Reference.

Here is my working code for same.

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

I am successfully able to get result when clicking on any image with the help of onItemClick().

这篇关于伽马轮菜单栏 - 如何将点击事件添加到Android的图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆