Search code examples
androidimagezoomingscalesubsampling

Error on findViewById - Subsampling Scale Image View - Android


I'm trying to test the code in this tutorial "Subsampling Scale Image View" to make a zoom image pinch, but it gives one error on .findViewById(id.imageView); - cannot resolve symbol..

My XML layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</LinearLayout>

And on my MainActivity fragment code have this code (inside onCreate method):

public class MainActivity extends AppCompatActivity {



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SubsamplingScaleImageView imageView = (SubsamplingScaleImageView)findViewById(id.imageView);
        imageView.setImage(ImageSource.resource(R.drawable.abc));

    }
}

Can any one please help me, please?

thanks in advance CAFC


Solution

  • Quick solution: Replace id.imageView with R.id.imageView.

    What happens is, when you want to reference an ID, you go to the R (Resources) directory provided by android. You have to go to the resources directory (R), and then in there there's the id directory. Then there's your id. So, the final result is R.id.imageView.