-1

我找到了另一个有同样问题的帖子,但那个答案对我不起作用,所以我希望有人能帮我解决这个问题。

我有多个表格,每个表格都有一个EditText和一个按钮。Button用于将 的值存储在EditText变量中。

这是我的桌面适配器。

    package com.example.vanhulzenapp;

    import java.util.List;
    
    import android.content.Context;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.BaseAdapter;
    import android.widget.EditText;
    import android.widget.ImageButton;
    import android.widget.TextView;
    
    public class ProductListAdapter extends BaseAdapter {
    
    private final List<TableRow> rows;
    /**
     * Adapter for TableRow-objects 
     */
    public ProductListAdapter(final Context context, final int itemResId, final List<TableRow> items){
        this.rows = items;
    }
    
    public int getCount(){
        return this.rows.size();
    }
    public Object getItem(int position){
        return this.rows.get(position);
    }
    public long getItemId(int position){
        return position;
    }
    
    
    /**
     * Set the content for a row here
     */
    
    
    public View getView(int position, View convertView, ViewGroup parent){
        final TableRow row = this.rows.get(position);
        View itemView = null;
        
        if (convertView == null){
            LayoutInflater inflater = (LayoutInflater)     parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            itemView = inflater.inflate(R.layout.list_item,null);
        } else {
            itemView = convertView;
        }
        
        // Set the text of the row
        TextView productname = (TextView) itemView.findViewById(R.id.productName);
        productname.setText(row.getName());
        
        TextView productprice = (TextView) itemView.findViewById(R.id.productPrice);
        productprice.setText(row.getPrice());
        
        /*EditText productvalue = (EditText) itemView.findViewById(R.id.editValue);
        productvalue.setText(Integer.toString(row.getValue()));*/
        
        // Remember the row for each button so that we can refer to
        // it when the button is clicked
        ImageButton addItemButton = (ImageButton) itemView.findViewById(R.id.addItemButton);
        addItemButton.setTag(row);      
        
        
        
        return itemView;
    }
}

这是TableRow

    package com.example.vanhulzenapp;

    public class TableRow{
    private String name;
    private String price;
    private int value;
    
    
    public TableRow(String name, String price){
        this.name = name;
        this.price = price;
    }
    public void setName(String name){
        this.name = name;;
    }
    public String getName(){
        return name;
    }
    public void setValue(int value){
        this.value = value;
    }
    public int getValue(){
        return value;
    }
    public void setPrice(String price){
        this.price = price;
    }
    public String getPrice(){
        return price;
    }
}

以及单击事件发生的主类。按钮通过使用知道它在哪一行,gettag() 但我无法EditText知道它在哪一行。

4

1 回答 1

0

您也可以在 EditText 上设置标签。

于 2013-09-30T08:45:10.150 回答