2013-09-30 1 views
-1

Я нашел еще одну тему с тем же вопросом, но этот ответ не сработал для меня, поэтому я надеюсь, что кто-то может мне помочь в этом.Как получить значения из EditText в TableRow

У меня есть несколько таблеток с каждым 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; 
} 

}

и основной класс, где происходит событие щелчка .. кнопка знает Wich строке это с помощью gettag() Но я не могу получить EditText, чтобы знать, в какой строке это.

+0

Обновить значения в массиве. – Yugesh

+0

Я не знаю, что вы имеете в виду. Не могли бы вы привести пример? – Crimson

+0

как загрузить данные в виде списка. – Yugesh

ответ

0

Вы также можете установить тег на EditText.

+0

Простое решение, но это сработало для меня .. TNX – Crimson