1

私は問題があります。私のアプリでは、各行に 2 つのボタンを持つカスタム ListView があります。ボタンの OnClickListner を管理しようとする ArrayAdapter を拡張するクラスを作成しましたが、機能しません。ボタンを押しても何も起こりません。これは私のクラスです:

public class AdapterMovimentazioni extends ArrayAdapter<ItemWithIdMov> {

private Context context;
private ArrayList<ItemWithIdMov> items;
private LayoutInflater vi;

public AdapterMovimentazioni(Context context, ArrayList<ItemWithIdMov> items) {
    super(context, 0, items);
    this.context = context;
    this.items = items;
    vi = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    ViewHolder holder;
    final ItemWithIdMov i = items.get(position);
    if (convertView == null) {
        convertView = vi.inflate(R.layout.item_movimentazioni, null);
        holder = new ViewHolder();
        holder.icon = (ImageView) convertView.findViewById(R.id.imageMov);
        holder.data = (TextView) convertView.findViewById(R.id.DataMov);
        holder.importo = (TextView) convertView.findViewById(R.id.ImportoMov);
        holder.locale = (TextView) convertView.findViewById(R.id.localeMov);
        holder.delete = (Button) convertView.findViewById(R.id.ButtonDeleteMov);
        holder.set = (Button) convertView.findViewById(R.id.ButtonSetMov);

        holder.delete.setTag(holder);
        holder.delete.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(context, "DELETEEEEEE", Toast.LENGTH_LONG);
            }
        });

        holder.set.setTag(holder);
        holder.set.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(context, "SET", Toast.LENGTH_LONG);

            }
        });
        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    if (i != null) {
        holder.icon.setImageResource(i.getIcon());
        holder.data.setText(i.getData());
        holder.importo.setText(i.getImporto());
        holder.locale.setText(i.getLocName());
    }

    return convertView;
}

private class ViewHolder {

    public ViewHolder() {

    }

    protected Button delete;
    protected Button set;
    protected ImageView icon;
    protected TextView data;
    protected TextView importo;
    protected TextView locale;

}

手伝って頂けますか??ありがとうございました

4

2 に答える 2

2

トーストライクを使う

Toast.makeText(context, "SET", Toast.LENGTH_LONG).show();
于 2013-10-21T10:51:45.783 に答える
0

ビュー宣言 onClicklistener を作成した後、getview メソッドを変更します。

public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    ViewHolder holder;
    final ItemWithIdMov i = items.get(position);
    if (convertView == null) {
        convertView = vi.inflate(R.layout.item_movimentazioni, null);
        holder = new ViewHolder();
        holder.icon = (ImageView) convertView.findViewById(R.id.imageMov);
        holder.data = (TextView) convertView.findViewById(R.id.DataMov);
        holder.importo = (TextView) convertView.findViewById(R.id.ImportoMov);
        holder.locale = (TextView) convertView.findViewById(R.id.localeMov);
        holder.delete = (Button) convertView.findViewById(R.id.ButtonDeleteMov);
        holder.set = (Button) convertView.findViewById(R.id.ButtonSetMov);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }


        holder.delete.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(context, "DELETEEEEEE", Toast.LENGTH_LONG);
            }
        });

        holder.set.setTag(holder);
        holder.set.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(context, "SET", Toast.LENGTH_LONG);

            }
        });

    if (i != null) {
        holder.icon.setImageResource(i.getIcon());
        holder.data.setText(i.getData());
        holder.importo.setText(i.getImporto());
        holder.locale.setText(i.getLocName());
    }

    return convertView;
}
于 2013-10-21T11:00:35.690 に答える