2013-09-30 3 views
-1

J'ai trouvé un autre fil avec la même question mais cette réponse n'a pas fonctionné pour moi donc j'espère que quelqu'un peut m'aider avec ceci.Comment obtenir des valeurs de EditText dans TableRow

J'ai plusieurs tablerows avec chacun EditText et un bouton dedans. Le Button est utilisé pour stocker la valeur du EditText dans une variable.

Ceci est mon adaptateur 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; 
} 

}

C'est la TableRow classe

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

}

et la classe principale où l'événement click se produit .. Le bouton sait dans Wich ligne est à l'aide le gettag() Mais je ne peux pas obtenir le EditText pour savoir dans quelle rangée il est.

+0

mettre à jour les valeurs dans le tableau. – Yugesh

+0

Je ne sais pas ce que tu veux dire. Pourriez-vous donner un exemple? – Crimson

+0

comment charger les données en mode liste. – Yugesh

Répondre

0

Vous pouvez également définir une balise sur EditText.

+0

Solution simple mais ça a marché pour moi .. TNX – Crimson

Questions connexes