2016-06-10 2 views
-2

이미지 및 단추가 포함 된 사용자 지정 Listview를 사용하고 있습니다.여러 LinearLayout 내 ImageView ID 가져 오기

listview.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:id="@+id/layout"> 

    <ListView android:id="@android:id/list" 
     android:layout_width="match_parent" 
     android:layout_height="0dp" 
/> 
</LinearLayout> 

여기 3은 LinearLayouts을 취급하고 있습니다.

button_view.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" 
android:id="@+id/parent" 
> 

    <LinearLayout 
    android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/child1" 
    <ImageView 
     android:id="@+id/image" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:src="@drawable/image" 
     /> 
    <TextView 
     android:id="@+id/listarray" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 

<LinearLayout 
    android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" android:id="@+id/child2"> 
    <ImageButton 
     android:id="@+id/one" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/one" 
     /> 
    <ImageButton 
     android:id="@+id/two" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/two" 
     /> 
    <ImageButton 
     android:id="@+id/three" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 

어댑터 코드 내 목록을 포함

tweetArray.

ArrayAdapter<String> arrayAdapter =new ArrayAdapter<String>(this,R.layout.button_view, R.id.listarray, tweetArray); 
      ListView listView = (ListView) findViewById(android.R.id.list); 
      listView.setAdapter(arrayAdapter); 

문제 : 내 문제는 내가 어떻게 ImageView의 ID를 얻을 수 있다는 것입니다. 시도

: 나는

ImageView user_picture = (ImageView) findViewById(R.id.image); 
Picasso.with(getApplicationContext()).load("http://www.w3schools.com/css/trolltunga.jpg).into(user_picture); 

으로 간단한 방법으로 얻을 시도하지만이 오류을 보여주고있다 : 대상이 널 (null)이 아니어야합니다.

아이디어가 있습니까? 그 코드가`Adapter`에있는 경우

+0

에 대한 링크를 확인하십시오 어댑터 을 사용자 정의, 당신은에'findViewById를을()'를 호출하는 데 필요한'View' 당신 ' 목록 항목을 다시 팽창시킵니다. –

+0

@MikeM하는 방법. – Atula

+0

'Adapter'에 대한 코드를 게시해야합니다. –

답변

-1
+0

어떤 오류가 발생합니까? logcat 게시 – SaravInfern

+1

링크 만 응답은 스택 오버플로에서 [우수 사례로 간주되지 않습니다] (http://meta.stackexchange.com/questions/7515/why-is-linking-bad)입니다. "대답"이라는 질문은 실제로 대답을 포함하거나 최소한 내용의 요약과 그것이 내용과 관련된 내용을 포함해야합니다. –

+0

결과로 null이 됨 – Atula