将微调器添加到listview项

时间:2011-09-01 03:43:00

标签: android android-listview spinner

我对listview感到困扰。我有一个listview,其中包含spinner里面的列表项。图像应该是这样的..

![spinner里面的列表视图] [1]

当我更改其中一个中的项目时,其他人也发生了变化。例如,当我向下滚动时,微调器编号为7的微调器编号为1时,值为2。我已经实现了基础适配器来实现它。这是代码:

package org.data.provider.model.adapter;

    public class Text3Adapter extends BaseAdapter {

    private Activity activity;
    private String[] title;
    private String[] value;
    public Spinner [] spinner;
    private static LayoutInflater inflater = null;

    public Activity getActivity() {
        return activity;
    }

    public void setActivity(Activity activity) {
        this.activity = activity;
    }

    public String[] getValue() {
        return value;
    }

    public void setValue(String[] value) {
        this.value = value;
    }



    public static LayoutInflater getInflater() {
        return inflater;
    }

    public static void setInflater(LayoutInflater inflater) {
        Text3Adapter.inflater = inflater;
    }

    public String[] getTitle() {
        return title;
    }

    public void setTitle(String[] title) {
        this.title = title;
    }

    public Text3Adapter(Activity a, String[] title, String[] value) {
        this.value=value;
        activity = a;
        activity.setTheme(android.R.style.Theme_Light);
        this.title = title;
        this.spinner=new Spinner[title.length];
        ArrayAdapter<String> adapter2=new ArrayAdapter<String>(activity, android.R.layout.simple_spinner_item,activity.getResources().getStringArray(R.array.tipe_nilai_pernyataan));
        //ganti dropdown resource
        adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        for(int i=0;i<this.value.length;i++){
            Spinner s=new Spinner(a);
            s.setAdapter(adapter2);
            this.spinner[i]=s;
        }
        inflater = (LayoutInflater) activity
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

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

    public static class ViewHolder {
        public TextView textDesc;
        public TextView textValue;
        public LinearLayout layout;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi = convertView;
        ViewHolder holder;
        if (convertView == null) {
            vi = inflater.inflate(R.layout.row_pernyataan, null);
            holder = new ViewHolder();
            holder.textDesc = (TextView) vi.findViewById(R.id.text_item);
            holder.textValue = (TextView) vi.findViewById(R.id.no);
            holder.layout=(LinearLayout) vi.findViewById(R.id.layout_spinner_pernyataan);
            holder.layout.addView(this.spinner[position]);
            vi.setTag(holder);
        } else{
            holder = (ViewHolder) vi.getTag();
        }
        holder.textDesc.setText(title[position]+" position="+position);
        holder.textValue.setText(value[position]);
        return vi;
    }

    @Override
    public int getCount() {
        return title.length;
    }
}

如何设置微调器而不更改其他微调器?我一直在这里。帮助

0 个答案:

没有答案