2014-01-21 3 views
-1

내가 "activity_main.xml"이라고 가정하면 "@+id/clickAndAdd"버튼이 있습니다. 내가 "second.xml"라는 또 다른 XML 파일을 가지고 그것은 내가 "@+id/clickAndAdd는" 버튼을 클릭 할 때마다 EditText를 어떻게 추가 할 수 있습니까?

가 감사를 클릭 내 " activity_main.xml"모든 시간에 " @+id/myEditText"

는 어떻게 추가 할 수 있습니다 "@+id/myEditText"라는 글고 있습니다.

+0

먼저 몇 가지 기본적인 안드로이드 자습서를 읽어 보시기 바랍니다. –

+0

나는 많은 것을 알고 읽었습니다. 그러나이 주제는 그것에 대해 혼란 스럽습니다. 나는 addView에 대해 알고있다. – Prince

+0

대신 "_assume you have ..._"를 작성하는 대신 여기에 관련 코드를 게시하십시오. – csmckelvey

답변

1

당신은 프로그램에 다음과 같은 코드를 작성하여 (이 경우 글고 치기를)보기를 만들 수 있습니다에서 당신이 얻을 수있는 자세한 내용은

Intent i=new Intent(MainActivity.this,NexActivity.class); 
startActivity(i); 

를 사용하여 작업을 수행 할 수 있습니다 귀하의 자바 파일.

//Main layout ID in your activity_main.xl 
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.linearLayoutHorizontal); 

//Creating the edittext 
EditText editTextOne = new EditText(this); 

//You can also add properities here 
editTextOne.setHint("Hello World"); 
editTextOne.setHintTextColor(Color.CYAN); 

//Adding the edittext to the xml file 
mainLayout.addView(editTextOne); 

여기 좋은 튜토리얼입니다 : http://android-er.blogspot.ca/2013/05/add-and-remove-view-dynamically.html

관련 문제