如何使用imageviews和Textview创建微调器

时间:2013-04-18 22:13:05

标签: java android spinner adapter

我想创建一个带有名称列表的微调器,以及许多.jpg的ID列表

我有一个带有String []的类,其中包含名称,以及带有drawable的ID的Integer []。

我的主要课程是下一个

public class Settings extends Activity{


private Button btnGuardar, btnCerrar;
private Spinner spOperadoras, spTarifas;
private Operadoras op = new Operadoras();


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.settings);


    btnGuardar = (Button)findViewById(R.id.buttonSave);
    btnCerrar = (Button)findViewById(R.id.buttonClose);
    spOperadoras = (Spinner)findViewById(R.id.spinnerOperador);
    spTarifas = (Spinner)findViewById(R.id.spinnerTarifas);

    OperadorAdapter adapter = new OperadorAdapter(this,    R.layout.custom_spinner, op);
    spOperadoras.setAdapter(adapter);
}

}

然后我的适配器是:

public class OperadorAdapter extends BaseAdapter implements SpinnerAdapter{

Activity context;
int spLayoutId;
Operadoras operadoras;

public OperadorAdapter(Activity context, int id, Operadoras op){
    //super(context, id, op);
    this.context = context;
    this.operadoras = op;
    this.spLayoutId = id;

}
@Override
 public View getDropDownView(int position, View convertView, ViewGroup parent) {
     return getCustomView(position, convertView, parent);
 }

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    return getCustomView(position, convertView, parent);
}

public View getCustomView(int position, View convertView, ViewGroup parent) {

    View item = convertView;
    TextView opName;
    ImageView opIcon;

        LayoutInflater inflater = context.getLayoutInflater();
        item = inflater.inflate(spLayoutId, null);
        opName = (TextView) item.findViewById(R.id.nombreOperador);


        opIcon = (ImageView) item.findViewById(R.id.imageOperador);


    opName.setText(operadoras.getOperador(position).toString());
    opIcon.setImageResource(operadoras.getLogo(position));
    return item;
}
@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 0;
}
@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return null;
}
@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return 0;
}

但我的旋转器没有任何结果。

问题是什么???

感谢。

1 个答案:

答案 0 :(得分:0)

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 0;
}

返回实际的数量。