车轮菜单栏我怎么能给点击动作图标 [英] wheel menu bar how can I give click action to icons

查看:170
本文介绍了车轮菜单栏我怎么能给点击动作图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我问这个问题。他们说add方法。我说,但我怎么给点击事件icon0。这是问题,我仍然..

<一个href=\"http://stackoverflow.com/questions/22243655/gama-wheel-menu-bar-how-to-add-click-events-to-icons-in-android\">first问题

和这些图标在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延伸活动{    私有静态最后弦乐TAG = 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);        在里面();
      //第一个例子:我尝试onitemclickListenner但我不能再工作点击ICON1事件       / * setListAdapter(新ArrayAdapter(在此,R.layout.main,图标[1]));       ListView控件的ListView = getListView();
       listView.setTextFilterEnabled(真);       listView.setOnItemClickListener(新OnItemClickListener(){
       公共无效onItemClick(适配器视图父母,观景,INT位置,长的id){
       Toast.makeText(getApplicationContext(),hahhaa,Toast.LENGTH_SHORT).show();
    }
});
* /
    }    私人无效的init(){
        RES = getApplicationContext()getResources()。
        轮=(轮)findViewById(R.id.wheel);
        wheel.setItems(getDrawableFromData(图标));
        wheel.setWheelDiameter(400);
         //我尝试这种新的
              wheel.setOnItemClickListener(新WheelAdapter.OnItemClickListener(){        @覆盖
        公共无效onItemClick(WheelAdapter&LT;&GT;母公司,观景,
                INT位置,长的id){
         //我怎么能达到ICON1?
             //我尝试根据Ȃŵåiṩĸîŋg答案但我仍然不能达到ICON1
         串选择;             选择= parent.getItemAtPosition(icons.length +位置)的ToString();
                如果(selected.equals(icon0)){
                      Toast.makeText(getApplicationContext(),+icon0,Toast.LENGTH_SHORT).show();                }
                否则如果(selected.equals(ICON1)){
                     Toast.makeText(getApplicationContext(),+ICON1,Toast.LENGTH_SHORT).show();                }
                否则如果(selected.equals(图标2)){
        Toast.makeText(getApplicationContext(),+图标2,Toast.LENGTH_SHORT).show();                }
        }});    }    私人绘制对象[] 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);            //我怎么能当我点击这个ICON1做,这是去其他网页?
            //该怎么办给予的点击动作
            //我应该怎么填这个方法}}

这是我的xml文件没有对XML没有ID的图标。他们在平局能够文件夹..

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT; LinearLayout中的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直
    机器人:背景=@绘制/ cell_bg
    &GT;    &LT;的TextView
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =WRAP_CONTENT
        机器人:文字=你好,GAMA! /&GT;    &LT;的LinearLayout
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =500dp
        机器人:方向=垂直
        机器人:背景=@绘制/ belirtec9_2bg
        机器人:paddingTop =10px的
    &GT;    &LT; com.digitalaria.gama.wheel.Wheel
        机器人:ID =@ + ID /轮
        机器人:paddingTop =10px的
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_gravity =中心/&GT;    &LT; / LinearLayout中&GT;&LT; / LinearLayout中&GT;


解决方案

试试这个:

  wheel.setOnItemClickListener(新WheelAdapter.OnItemClickListener(){
    @覆盖
    公共无效onItemClick(WheelAdapter&LT;&GT;母公司,观景,INT位置,长的id){
        //这里我使用的项目preSS要打开其他的活动,
        //你可以使用你喜欢的任何其他行动。
        如果(位置== 0){
            //首先图标pressed
            意向意图=新意图(背景下,MyNewClass.class);
            startActivity(意向);
        }否则如果(位置== 1){
            //第二个图标是pressed
            意向意图=新意图(背景下,MySecondClass.class);
            startActivity(意向);
        }
    }
});

Before I asked this question. They said add method. I added but how can I give click event icon0. It is problem for me still..

first question

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

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();
      //first example:I try onitemclickListenner but I could not work again click event on icon1

       /*   setListAdapter(new ArrayAdapter(this, R.layout.main ,icons[1] ));

       ListView listView = getListView();
       listView.setTextFilterEnabled(true);

       listView.setOnItemClickListener(new OnItemClickListener() {
       public void onItemClick(AdapterView parent, View view, int position, long id) {               
       Toast.makeText(getApplicationContext(),"hahhaa",            Toast.LENGTH_SHORT).show();               
    }
});
*/
    }

    private void init() {
        res = getApplicationContext().getResources();
        wheel = (Wheel) findViewById(R.id.wheel);       
        wheel.setItems(getDrawableFromData(icons));
        wheel.setWheelDiameter(400);
         //I try this new
              wheel.setOnItemClickListener(new WheelAdapter.OnItemClickListener(){

        @Override
        public void onItemClick(WheelAdapter<?> parent, View view,
                int position, long id) {
         //how can I reach icon1 ?
             //I try it according to Ȃŵåiṩ ĸîŋg answer but still I can not reach icon1
         String selected;

             selected = parent.getItemAtPosition(icons.length + position).toString();
                if( selected.equals("icon0") ){
                      Toast.makeText(getApplicationContext(), ""+"icon0", Toast.LENGTH_SHORT).show();

                }
                else if( selected.equals("icon1")){
                     Toast.makeText(getApplicationContext(), ""+"icon1", Toast.LENGTH_SHORT).show();

                }
                else if(  selected.equals("icon2")){
        Toast.makeText(getApplicationContext(), ""+"icon2", Toast.LENGTH_SHORT).show();

                }


        }});



    }



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

            //how can I do when I click this icon1 , it is go other page ???
            // how can do give click action
            // how should I fill this method



}

}

And this is my xml file there is no id icons on xml. They are at draw able folder..

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" 
    android:background="@drawable/cell_bg"
    >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Hello, GAMA!" />

    <LinearLayout 
        android:layout_width="wrap_content"
        android:layout_height="500dp"
        android:orientation="vertical" 
        android:background="@drawable/belirtec9_2bg"
        android:paddingTop="10px"
    >

    <com.digitalaria.gama.wheel.Wheel
        android:id="@+id/wheel"
        android:paddingTop="10px" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>

    </LinearLayout>

</LinearLayout>

解决方案

try this:

wheel.setOnItemClickListener(new WheelAdapter.OnItemClickListener() {
    @Override
    public void onItemClick(WheelAdapter<?> parent, View view, int position, long id) {
        // Here I am using other activities to be opened on item press,
        // you can use any other action which you like.
        if (position == 0) {
            // First icon is pressed
            Intent intent = new Intent(context, MyNewClass.class);
            startActivity(intent);
        } else if (position == 1) {
            // Second icon is pressed
            Intent intent = new Intent(context, MySecondClass.class);
            startActivity(intent);
        }
    }
});

这篇关于车轮菜单栏我怎么能给点击动作图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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