如何获取对象按钮?

时间:2015-09-12 19:11:01

标签: java android listview object button

我有自定义对象的ListView。该对象包含一个名为text_name的TextView,一个值为text_value的TextView和一个在EditText button_add中添加值的Button field_value,它属于该对象,到text_value。这是对象类:

package rafaelmarinho.pague10;

import static java.lang.Math.*;

public class Element
{
    private String _name;
    private int _value;
    public Element(String name, int value)
    {
        _name=name;
        _value=value;
    }
    public void setValue(int value)
    {
        _value=value;
    }
    public void percentIncrease()
    {
        _value=(int)ceil(_value * 1.1);
    }
    public String getName()
    {
        return _name;
    }
    public int getValue()
    {
        return _value;
    }
}

这是对象的自定义适配器:

   class elementAdapter extends ArrayAdapter<Element>
{
    public elementAdapter()
    {
        super (MainActivity.this, R.layout.item_layout, elements);
    }

    @Override
    public View getView(int position, View view, ViewGroup parent)
    {
        if(view == null)
        {
            view = getLayoutInflater().inflate(R.layout.item_layout,parent,false);
        }

        Element currentElement = elements.get(position);

        TextView name = (TextView) view.findViewById(R.id.text_name);
        name.setText(currentElement.getName());
        TextView value = (TextView) view.findViewById(R.id.text_value);
        value.setText(String.valueOf(currentElement.getValue()));

        return view;
    }
}

我有一个按下按钮时调用的函数,但我尝试将其添加到field_valuetext_value的值。那么,我该怎么办?

0 个答案:

没有答案