2012-08-17 3 views
-3

저는 android.I에 새롭습니다. 선택한 이미지와 함께 변경되는 버튼이있는 textview를 추가하는 방법을 모르겠습니다. 누구든지 적절한 코드를 통해 나를 도울 수 있습니다. 어떻게해야합니까? 도움을 주시면 감사하겠습니다.갤러리의 버튼이있는 텍스트 뷰

+1

버튼이있는 textview를 추가 하시겠습니까? 그게 무슨 뜻 이죠? 문제를 해결할 수 있도록 좀 더 분명하게 찾으십시오. – RyanInBinary

답변

0

응답을 지우려면 개체를 보관할 컬렉션 또는 arraylist를 설정 한 다음 클릭 한 내용을 기준으로 참조하십시오.

이미지가 액티비티의 유일한 객체 인 경우 단일 이미지에서이를 수행하는 방법은 다음과 같습니다.

XML :

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    > 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/image" 
     android:src="@drawable/YOUR_IMAGE_RESOURCE" 
     /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Text for the picture" 
     android:visibility="invisible" 
     android:id="@+id/text" 
     /> 

    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Hello" 
     android:id="@+id/button" 
     android:visibility="invisible" 
     /> 
</LinearLayout> 

자바

ImageView photoImage = (ImageView)findViewById(R.id.image); 
TextView text = (TextView)findViewById(R.id.text); 
Button button = (Button)findViewById(R.id.button); 

photoImage.setOnClickListener(new OnClickListener{ 
    void onClick(View v){ 
     text.setVisibility(View.VISIBLE); 
     button.setVisibility(View.VISIBLE); 
    } 
}); 

// Set the OnClickListener for "button" here, to start a new intent or whatever 

여러 버튼을 사용하는 경우, 설치 ArrayList에 또는 수집 제가 위에서 언급있다.

그런 다음 당신이에 따라 원하는대로 할 수

List<TextView> tvs = new ArrayList<TextView>(); 
// Setup the views 
for (int i = 0; i < numberOfTextViews; i++){ 
    TextView thisTextView = new TextView(context); 
    // Setup whatever layout info you want here 
    tvs.add(thisTextView); 
} 
// Use a view inflater here to add each of the textviews however you want (table layout, linearlayout, etc.) 

[편집]

배열 목록에 뭔가를 넣어 귀하의 코드는 다음과 같습니다 ... 그냥 ... tvs.get(NUMBER)을 사용하여 원하는 내용을 찾으십시오. 버튼이나 다른 것을 사용하여 동일한 작업을 수행 할 수 있으며 동일한 NUMBER를 사용하여 문자열, 텍스트 뷰 및 버튼을 동시에 참조 할 수 있습니다. 예 : 버튼 번호 1을 클릭하십시오. tvs.get(1), buttons.get(1), stringResources.get(1)

더 적합한가요?

+0

내 코드를 업데이트했습니다. – RyanInBinary