2014-10-07 2 views
0

나는 그것을 설명하기보다는 보여주기 쉽기 때문에 스크린 샷을 추가 한 작은 출퇴근 시간 기록 용지 응용 프로그램을 가지고 있습니다! 바라건대 당신이 거기 근로자가 될 것입니다 다른 사이트에 대한 작업 번호 있어야하고 그에 소요되는 시간에 대한 각 작업의 수를 기준으로 자신의 시간을 입력 할 수 있습니다 볼 수있는 사진과android 응용 프로그램에 사용자 정의 레이아웃을 추가하는 버튼

enter image description here

일자리를 추가 할 수있는 "일자리 추가"버튼을 사용할 수 있습니까? 그렇습니다. 그것이 눌려 질 때마다 아래의보기? 아래 그림과 같이 아래

이 섹션의 XML 코드는 I 당신은 버튼의 onClick에서보기를 부풀려 수

<LinearLayout 
    android:id="@+id/MainLayoutThree" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > //start of 1st job layout 

<LinearLayout 
    android:id="@+id/LayoutTwoA" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/beige" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/jobNo" > 
    </TextView> 

    <EditText 
     android:id="@+id/editText3" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:maxLines="1"> 
    </EditText> 

    <TextView 
     android:id="@+id/textView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/ordHours" > 
    </TextView> 

    <EditText 
     android:id="@+id/editText4" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:maxLines="1"> 
    </EditText> 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/LayoutThree" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/beige" 
    android:orientation="horizontal" > 

    <TextView 
      android:id="@+id/textView5" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="@string/overTimeHours" /> 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/LayoutFour" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@color/beige" 
    android:orientation="horizontal" > 

    <TextView 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="x1.25" /> 

    <EditText 

     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:maxLines="1"> 
    </EditText> 


    <TextView 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="x1.50" /> 

    <EditText 

     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:maxLines="1"> 
    </EditText> 


    <TextView 

      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="x2" /> 

    <EditText 

     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:maxLines="1"> 
    </EditText> 

    </LinearLayout> 

+0

[동적으로 선형 레이아웃에 컨텐츠 추가?] (http://stackoverflow.com/questions/6661261/adding-content-to-a-lineary-layout-dynamically) –

답변

4

버튼을 누를 때마다 추가 할 수 있습니다 :

addButton.setOnClickListener(new OnClickListener() { 

    @Override 
    public void onClick(View v) { 
     LayoutInflater inflater = LayoutInflater 
         .from(getApplicationContext()); 
     View view = inflater.inflate(R.layout.job_row_layout, null); 
     containerLayout.addView(view); 

    } 
}); 

희망이 도움이됩니다.

+0

감사합니다. 내 작업 레이아웃 XML 위의 레이아웃 폴더에있는 새 XML 파일에 ?? –

+1

예. @bIG_aL 및 그 inflat 그 XML을. –

+0

어쨌든 동적으로 각 뷰에 사용자 정의 ID를 추가 할 수 있습니까? 예를 들어 ID가 생성 될 때 코드를 구조화 할 수 있습니까? 3 번째 또는 4 번째 작업에서 시간을 가져 오려면 어떻게해야합니까? ? 나는이 질문을 새로운 질문으로 올리면 안 될까? 아니면 미안하다고 생각해서이 질문을해야합니까? –

관련 문제