ich eine Liste der Elemente haben, wie folgt:EditText nicht den Text halten eingegeben, dh er löscht
private void getProducts() {
List<Product> listProducts = Product.getListProduct(true);
if (listProducts != null && listProducts.size() > 0) {
ProductAdapter m_adapterProduct = new ProductAdapter(this, listProducts);
mlvwProducts.setAdapter(m_adapterProduct);
}
}
Die ProductAdapter Klasse ist wie folgt:
public class ProductAdapter extends ArrayAdapter<Product> {
private Context context;
private List<Product> mdata;
public ProductAdapter(Context context, List<Product> mdata) {
super(context, R.layout.act_item_product_adapter, mdata);
this.context = context;
this.mdata = mdata;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View item = LayoutInflater.from(context).inflate(R.layout.act_item_product_adapter,null);
TextView m_product_name = (TextView) item.findViewById(R.id.adapter_product_nameProduct);
TextView m_product_cost = (TextView) item.findViewById(R.id.adapter_product_cost);
TextView m_product_stock = (TextView) item.findViewById(R.id.adapter_product_stock);
EditText m_product_amount = (EditText) item.findViewById(R.id.adapter_product_amount);
ImageView m_product_photo = (ImageView) item.findViewById(R.id.adapter_product_photo);
m_product_name.setText(datos.get(position).getNombreProducto());
m_product_cost.setText(" Cost: " + String.format("%.2f",mdata.get(position).getCostSold()));
m_product_stock.setText(" Stock: " + Integer.toString(mdata.get(position).getStock()));
//m_product_amout.setText("0");
if (datos.get(position).getimagenProduct() != null){
byte[] decodedString = Base64.decode(mdata.get(position).getimagenProduct(), Base64.DEFAULT);
m_product_photo.setImageBitmap(BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length));
}
return item;
}
}
Alles funktioniert sehr gut, ich kann die Informationen der Produkte abrufen und sie in der Liste anzeigen, aber wenn ich in EditText (m_product_amount) einen Wert eingeben und auf ein anderes Objekt der Aktivität klicken, wird die eingegebene Nummer gelöscht und bleibt bei 0 Das war die Standardnummer im Layout.
Was mache ich falsch?
Irgendwelche Ideen oder Vorschläge sind willkommen
Dank
============= Frage Aktuelles ===============
act_item_product_adapter.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/adapter_product_photo"
android:layout_width="80dp"
android:layout_height="80dp"
android:scaleType="centerInside"
android:background="@android:color/white"
android:cropToPadding="true"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_toRightOf="@id/adapter_product_photo"
android:id="@+id/linearLayout2">
<TextView
android:id="@+id/adapter_product_nameProducto"
android:layout_width = "match_parent"
android:layout_height = "37dp"
android:gravity="center"
android:textSize="20dp"
android:text="Name of product"/>
</LinearLayout>
<LinearLayout
android:layout_width= "170dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/linearLayout3"
android:layout_below="@+id/linearLayout2"
android:layout_toRightOf="@+id/adapter_product_photo"
android:layout_alignBottom="@+id/adapter_product_photo">
<TextView
android:id="@+id/adapter_product_cost"
android:layout_width = "170dp"
android:layout_height = "wrap_content"
android:text="cost"/>
<TextView
android:id="@+id/adapter_product_stock"
android:layout_width="170dp"
android:layout_height="wrap_content"
android:text="stock"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_below="@+id/linearLayout2"
android:layout_toEndOf="@+id/linearLayout3"
android:layout_toRightOf="@+id/linearLayout3"
android:orientation="horizontal"
android:layout_alignBottom="@+id/linearLayout3">
<TextView
android:layout_width = "wrap_content"
android:layout_height = "match_parent"
android:gravity="center"
android:textSize="20dp"
android:text="Amount"/>
<EditText
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:inputType="number"
android:id="@+id/adapter_product_amount"
android:gravity="center"
android:text="0"/>
</LinearLayout>
</RelativeLayout>
Ich schlage vor, Sie Ihr Layout erstellen (s). Ich schlage vor, dass Sie einen RecyclerView verwenden. –
Ok, ich werde die Frage mit dem Layout aktualisieren. Danke –
Ich sehe nicht, wo Sie abholen, was Sie in das 'EditText'-Feld eingegeben haben ... – DigitalNinja