i erstellen 1 Linearlayout innerhalb Linearlayouts, die mit 1 EditText enthält und 1 Textview programmatisch und ich brauche Text von EditText und Textview zu erhalten. Und dies ist mein Code:erhalten Textview und EditText von Programatically erstellt
main.xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="10dp" >
<LinearLayout
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:gravity="right"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
MainActivity.java:
linearLayout = (LinearLayout) view.findViewById(R.id.result);
.......
public void addItem(){
LinearLayout childLayout = new LinearLayout(context);
LinearLayout.LayoutParams linearParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
childLayout.setLayoutParams(linearParams);
childLayout.setTag(item_name);
childLayout.setOrientation(LinearLayout.HORIZONTAL);
TextView item = new TextView(context);
item.setTag(item_name);
item.setText(item_name);
item.setTextSize(16);
item.setGravity(Gravity.LEFT);
LinearLayout.LayoutParams llp1 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llp1.setMargins(0, 0, 15, 0);
item.setLayoutParams(llp1);
item.setTextColor(context.getResources().getColor(android.R.color.black));
EditText quantity = new EditText(context);
quantity.setText(nama_barang);
quantity.setTextSize(16);
quantity.setGravity(Gravity.CENTER_HORIZONTAL);
LinearLayout.LayoutParams llp2 = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
llp2.setMargins(10, 0, 15, 0);
quantity.setLayoutParams(llp2);
quantity.setTextColor(context.getResources().getColor(android.R.color.black));
childLayout.addView(item);
childLayout.addView(quantity);
linearLayout.addView(childLayout);
}
Helfen Sie mir, bitte.
Ich habe bearbeiten meine Frage
Eigentlich mein Fall oben passierte, wenn ich addItem geklickt(), wird meine app neue Textview und EditText angezeigt werden, so dass, wenn dieser Prozess abgeschlossen ist, und zum nächsten Fragment angezeigt all den Text von Textviews und EditTexts wie dieser mit String:
Items Qtt
Cola......1
Chicken...1
Meat......2
mir Hilfe.
ja, aber mein Problem ist, ich will alle Texte aus der Textviews bekommen und alle EditTexts von allen ChildLayout innerhalb Linearlayouts. Es gibt mehr TextView & EditText, nicht nur einen, der von for condition erstellt wurde. – wdyz
Ok, wir können ein Array erstellen, um alle Zeichenfolgen zu erhalten. Deklarieren außerhalb der '' for' Liste Strings = new Arraylist <>(); 'am Ende für fügen Sie' strings.add (str); 'und' strings.add (STR2); ' –
sorry, i habe meine Fragen bearbeitet. Bitte überprüfen Sie oben. Danke – wdyz