如何从TableRow中的EditText获取值

时间:2013-09-30 07:59:28

标签: android android-edittext tablerow

我找到了另一个带有相同问题的帖子,但答案对我不起作用,所以我希望有人能帮助我。

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

这是我的tablerow适配器。

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;
}

}

以及发生click事件的主类..按钮通过使用gettag()知道它在哪一行 但我不能让EditText知道它是什么行。

1 个答案:

答案 0 :(得分:0)

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