-2

I am using a custom Listview containing Images and Buttons.

my 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>

I am dealing with 3 LinearLayouts here.

my 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>

adapter code

tweetArray containing my list.

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);

Issue : My problem is that how can i get id of ImageView.

Tried : I have tried to get in simple way as

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

But this is showing error : Target must not be null.

Do you have any Idea...?

Atula
  • 2,177
  • 2
  • 12
  • 28
  • If that code is in your `Adapter`, you need to call `findViewById()` on the `View` you're inflating for the list item. – Mike M. Jun 10 '16 at 08:21
  • how to do that @MikeM. – Atula Jun 10 '16 at 08:22
  • You need to post the code for your `Adapter`. – Mike M. Jun 10 '16 at 08:24
  • downvoters can you share the reason too please. that might be helpfull. – Atula Jun 10 '16 at 08:30
  • That's not how you create a `ListView` with a custom item layout. You need to implement a custom `Adapter` class. Have a look at [this post](http://stackoverflow.com/questions/8166497/custom-adapter-for-list-view). – Mike M. Jun 10 '16 at 08:33
  • please read the documentation @Atula [ListView](https://developer.android.com/guide/topics/ui/layout/listview.html) [Adapter](https://developer.android.com/reference/android/widget/Adapter.html) Tutorials: [Tutorial 1](http://www.tutorialspoint.com/android/android_list_view.htm) [tutorial 2](http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/) – SaravInfern Jun 10 '16 at 08:35
  • thanks @SaravInfern for the links. but they not helpful for now. – Atula Jun 10 '16 at 08:39
  • @Mike M can you share any alternative to deal with this issue. – Atula Jun 10 '16 at 08:39
  • Any alternative would be even more complicated and involved. That's the basics for a custom `ListView`. – Mike M. Jun 10 '16 at 08:43

1 Answers1

-1

try to customize your adapter please check the link for adapter

http://www.vogella.com/tutorials/AndroidListView/article.html

SaravInfern
  • 3,338
  • 1
  • 20
  • 44
  • 1
    Link only answers are [not considered good practise](http://meta.stackexchange.com/questions/7515/why-is-linking-bad) on Stack Overflow. The question "answer" should actually contain an answer or at very least a summary of the content and how it pertains to the question. – Ed Holloway-George Jun 10 '16 at 08:38
  • getting null as result – Atula Jun 10 '16 at 08:38