Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 控制盘菜单栏如何为图标提供单击操作_Android_Android Wheel - Fatal编程技术网

Android 控制盘菜单栏如何为图标提供单击操作

Android 控制盘菜单栏如何为图标提供单击操作,android,android-wheel,Android,Android Wheel,在我问这个问题之前。他们说添加方法。我添加了,但我如何给点击事件图标0。这对我来说仍然是个问题 这些图标不是xml格式的。它们位于可绘制文件夹上。 这是我们可以使用的方法 这是我的努力 package com.myproject.gama; import java.util.Arrays; import com.digitalaria.gama.wheel.Wheel; import com.digitalaria.gama.wheel.WheelAdapter; import andr

在我问这个问题之前。他们说添加方法。我添加了,但我如何给点击事件图标0。这对我来说仍然是个问题

这些图标不是xml格式的。它们位于可绘制文件夹上。 这是我们可以使用的方法

这是我的努力

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



}

}
package com.myproject.gama;
导入java.util.array;
导入com.digitalia.gama.wheel.wheel;
导入com.digitalia.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();
私人车轮;
公共车轮适配器;
私人资源;
公共int[]图标={
R.drawable.icon1,R.drawable.icon0,R.drawable.icon2};
图像视图t;
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
//第一个示例:我尝试使用McClickListenner,但无法再次使用icon1上的单击事件
/*setListAdapter(新的ArrayAdapter(this,R.layout.main,icons[1]);
ListView ListView=getListView();
setTextFilterEnabled(true);
setOnItemClickListener(新的OnItemClickListener(){
public void onItemClick(AdapterView父对象、视图、int位置、长id){
Toast.makeText(getApplicationContext(),“哈哈”,Toast.LENGTH\u SHORT.show();
}
});
*/
}
私有void init(){
res=getApplicationContext().getResources();
wheel=(wheel)findViewById(R.id.wheel);
wheel.setItems(getDrawableFromData(图标));
车轮。设置车轮直径(400);
//我试试这个新的
wheel.setOnItemClickListener(新的WheelAdapter.OnItemClickListener(){
@凌驾
public void onItemClick(车轮适配器父级、视图、,
内部位置,长id){
//我怎样才能到达icon1?
//我根据我的想法去尝试ṩ 我的答案是,但我仍然无法联系到icon1
选择字符串;
selected=parent.getItemAtPosition(icons.length+position).toString();
如果(选定。等于(“icon0”)){
Toast.makeText(getApplicationContext(),“”+“icon0”,Toast.LENGTH\u SHORT.show();
}
else if(选定的。等于(“icon1”)){
Toast.makeText(getApplicationContext(),“+”icon1”,Toast.LENGTH\u SHORT.show();
}
else if(已选择。等于(“icon2”)){
Toast.makeText(getApplicationContext(),“+”icon2”,Toast.LENGTH\u SHORT.show();
}
}});
}
私有可提取[]getDrawableFromData(int[]数据){
Drawable[]ret=新的可绘制[data.length];
对于(int i=0;i
这是我的xml文件,xml上没有id图标。它们位于可绘制文件夹中。

<?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>

试试这个:

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);
        }
    }
});
wheel.setOnItemClickListener(新的WheelAdapter.OnItemClickListener(){
@凌驾
public void onItemClick(WheelAdapter父级、视图、整数位置、长id){
//在这里,我使用其他活动在项目新闻上打开,
//你可以使用任何其他你喜欢的动作。
如果(位置==0){
//按下第一个图标
意向意向=新意向(上下文,MyNewClass.class);
星触觉(意向);
}否则如果(位置==1){
//按下第二个图标
意向意向=新意向(上下文,MySecondClass.class);
星触觉(意向);
}
}
});
试试这个:

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);
        }
    }
});
wheel.setOnItemClickListener(新的WheelAdapter.OnItemClickListener(){
@凌驾
public void onItemClick(WheelAdapter父级、视图、整数位置、长id){
//在这里,我使用其他活动在项目新闻上打开,
//你可以使用任何其他你喜欢的动作。
如果(位置==0){
//按下第一个图标
意向意向=新意向(上下文,MyNewClass.class);
星触觉(意向);
}否则如果(位置==1){
//按下第二个图标
意向意向=新意向(上下文,MySecondClass.class);
星触觉(意向);
}
}
});

此代码仅在项目上添加圆圈:

    wheel.setOnItemClickListener(new WheelAdapter.OnItemClickListener() {
        @Override
        public void onItemClick(WheelAdapter<?> parent, View view, int position, long id) {
            ImageView v = (ImageView) parent.getItemAtPosition(position);
            Drawable pd = (Drawable) v.getDrawable();
            Paint paint = new Paint(); paint.setStyle(Paint.Style.STROKE);
            //TODO: Set Color and width of circle
            paint.setColor(Color.BLUE);
            paint.setStrokeWidth(4);

            Bitmap mutableBitmap = Bitmap.createBitmap(((BitmapDrawable)pd).getBitmap()).copy(Bitmap.Config.ARGB_8888, true);
            Canvas canvas = new Canvas(mutableBitmap);
            canvas.drawCircle(((BitmapDrawable)pd).getBitmap().getWidth()/2, ((BitmapDrawable)pd).getBitmap().getHeight()/2, 30, paint);
            v.setImageBitmap(mutableBitmap);
        }
    });
wheel.setOnItemClickListener(新的WheelAdapter.OnItemClickListener(){
@凌驾
public void onItemClick(WheelAdapter父级、视图、整数位置、长id){
ImageView v=(ImageView)父级.getItemAtPosition(位置);
Drawable pd=(Drawable)v.getDrawable();
Paint Paint=new Paint();Paint.setStyle(Paint.Style.STROKE);
//TODO:设置圆的颜色和宽度
油漆。设置颜色(颜色。蓝色);
油漆。设置行程宽度(4);
一点