0

我是 Android Programming 的新手。我使用以下链接将 Android 3D Carousel 应用程序集成到我的应用程序中 http://www.codeproject.com/Articles/146145/Android-3D-Carousel 它工作正常。但我的要求不是我需要将多个按钮作为一个视图放置,如附加的屏幕截图所示。

请建议我如何进行?提前致谢在此处输入图像描述

4

2 回答 2

0

在问任何事情之前,您是否先尝试过任何事情。你能发布你尝试过的代码吗?从那里我们可以继续前进

于 2013-05-09T11:03:02.230 回答
0

像这样写你的适配器

package com.example.uitest;

import java.util.ArrayList;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Toast;

public class  CarouselAdapter  extends BaseAdapter {

    private ArrayList<String> array;
    private Activity mContext;

    LayoutInflater inflator=null;
    public CarouselAdapter(Activity context,ArrayList<String>array) {
        mContext = context;
        this.array=array;
    }

    /*public void setData(ArrayList<Integer> data) {
        mData = data;
    }*/

    @Override
    public int getCount() {
        return array.size();
    }

    @Override
    public Object getItem(int pos) {
        return array.get(pos);
    }

    @Override
    public long getItemId(int pos) {
        return pos;
    }

    @Override
    public View getView(int arg0, View convertview, ViewGroup arg2) {
        if(convertview==null)
        {
            ViewHolder holder=new ViewHolder();
            convertview=mContext.getLayoutInflater().inflate(R.layout.carousellayout,null);
            holder.btn1=(Button)convertview.findViewById(R.id.button1);
            holder.btn2=(Button)convertview.findViewById(R.id.button2);
            holder.btn3=(Button)convertview.findViewById(R.id.button3);
            holder.btn4=(Button)convertview.findViewById(R.id.button4);
            convertview.setTag(holder);     
        }
        ViewHolder hold=(ViewHolder)convertview.getTag();
        hold.btn1.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(mContext, "Clicked on button 1", Toast.LENGTH_SHORT).show();
            }
        });
        hold.btn2.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(mContext, "Clicked on button 2", Toast.LENGTH_SHORT).show();
            }
        });
        hold.btn3.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(mContext, "Clicked on button 3", Toast.LENGTH_SHORT).show();
            }
        });
        hold.btn4.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                Toast.makeText(mContext, "Clicked on button 4", Toast.LENGTH_SHORT).show();
            }
        });

        return convertview;
    }

    static class ViewHolder
    {
        Button btn1,btn2,btn3,btn4;
    }
}
于 2013-05-09T17:25:09.917 回答