저는 Android 개발의 초보자이며이 점에 대해 도움을 주시면 감사하겠습니다.Android - 활동이 시작된 후에 추가 된 개체에 액세스하십시오.
사용자가 버튼을 클릭 할 때 Checkbox 및 EditText를 만드는 Android 액티비티가 있습니다. 사용자는 그가 원하는만큼 많은 체크 박스/편집 텍스트를 자유롭게 추가 할 수 있습니다.
public void onclickplus (View view){
LayoutInflater inflate = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View view1 = inflate.inflate(R.layout.row_checkitem, null);
mainLayout.addView(view1);
count = count +1;
}
이
내 질문은, 우리가 어떻게 액세스합니까된다
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
</LinearLayout>
이것은 자바 코드는 다음과 같습니다
이
은 활동에 추가되는 뷰의 XML 파일입니다 이 체크 박스와 EditTexts가 실제 자바 코드에 추가되어 데이터를 데이터베이스에 저장할 수 있습니다.내가 예를 들어 할 것 미리 정해진 이러한 개체 경우 등
EditText text1;
text1 = (EditText) findViewById(R.id.editText1);
text1.getText().toString();
하고, EDITTEXT의 값에 액세스 할 수 있습니다.
그러나이 경우 활동이 시작될 때 이러한 개체가 없습니다.
나를 도와 줄 수 있습니까? 감사합니다. .
안녕하십니까. 답변 해 주셔서 감사합니다. 링크 된 솔루션을 살펴본 결과, 다음 코드를 사용하여 많은 양의 EditText를 만들고 해당 값에 액세스 할 수 있습니다. EditText [] ed; ed = 새 EditText [count]; \t \t \t \t 찾는 INT (I = 0; I ++가 나는 카운트 <) { \t \t \t ED [I] = 새로운 글고 (이); \t \t \t ed [i].setId (i); \t \t \t \t \t \t mainLayout.addView (ed [i]); \t \t} 그러나 이해할 수 있듯이 사용자가 XML보기를 부풀리고 추가하거나 제거하는 것과 달리 사용자가 선택한 양만 추가 할 수 있습니다. 여전히 이러한 체크 박스에 액세스하는 방법을 찾고 있으며 XML보기를 부 풀려서 추가 한 editTexts가 있습니다. –
왜 그걸 원하니? 이 예제를 보면 레이아웃에 'tableLayout.addView (createOneFullRow (rowId));'를 추가하기 만하면됩니다. 'ed [i] .getText(). toString(); '을 사용하여 EditText 필드에 액세스 (예 : 텍스트 가져 오기) 할 수 있습니다. 필드를 동적으로 추가하고 액세스합니다. –
다시 연락 드리겠습니다. 오늘 밤에 작업하고 어떻게 작동하는지보십시오. 감사합니다. . –