i create 1 LinearLayout внутри LinearLayout, который содержит 1 EditText и 1 TextView программно, и мне нужно получить текст из EditText и TextView. И это мой код:получить TextView и EditText от программно созданного
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);
}
Помоги мне, пожалуйста.
Я редактировать мой вопрос
На самом деле, мой случай выше случилось, когда я нажал AddItem(), мое приложение будет отображать новый TextView и EditText, так что если этот процесс будет завершен, и перейти к следующему Фрагмент, чтобы отобразить весь текст TextViews и EditTexts, как это с помощью StringBuilder:
Items Qtt
Cola......1
Chicken...1
Meat......2
Помоги мне.
да, но моя проблема, я хочу, чтобы получить весь текст от TextViews и все EditTexts от всех ChildLayout внутри LinearLayout. Существует больше TextView & EditText, а не только тот, который создан для условия. – wdyz
Итак, мы можем создать массив, чтобы получить все строки. Объявите вне списка 'for'' stringings = new ArrayList <>();' в конце для добавления их 'strings.add (str);' и 'strings.add (str2);' –
извините, i Я редактировал свои вопросы. Пожалуйста, проверьте выше. Спасибо – wdyz