gpt4 book ai didi

android - 滚轮菜单栏如何为图标提供点击操作

转载 作者:行者123 更新时间:2023-11-29 16:02:47 25 4
gpt4 key购买 nike

在我问这个问题之前。他们说添加方法。我添加了但是我怎么能给点击事件icon0。这对我来说仍然是个问题..

first question

并且这些图标不在 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



}

}

这是我的 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);
}
}
});

关于android - 滚轮菜单栏如何为图标提供点击操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22435794/

25 4 0