Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7401755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:33:32+00:00 2026-05-29T04:33:32+00:00

Please don’t judge me, i’m extremely new on android developing… I wanna make an

  • 0

Please don’t judge me, i’m extremely new on android developing… I wanna make an app with viewPager… I’ve got three pages with three different layouts… But i just couldn’t figure out how to deal with a button on second page on viewPager. I found this question ” How to write button onClick method in viewpager? ” and set my codes like this:

ViewPagerAdapter:

@Override
public Object instantiateItem( View pager, int position )
{
    View v = new View(pager.getContext());
    LayoutInflater inflater =
            (LayoutInflater) pager.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int resId = 0;
    switch (position) {
    case 0:         
        resId = R.layout.deneme;            
        break;
    case 1:
        resId = R.layout.deneme2;          
        break;
    case 2:
        resId = R.layout.deneme3;
        break;   
    }

    v = inflater.inflate(resId, null);
    ((ViewPager) pager).addView(v, 0);

    return v;
  }

Here I’m getting errors:
“The method findViewById(int) is undefined for the type new View.OnClickListener(){}” on line

 LinearLayout l = (LinearLayout) findViewById(R.id.layout2); 

and “The method getResources() is undefined for the type new View.OnClickListener(){}” on line

 l.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));

Main:

 public class ViewPagerProjectActivity extends Activity {

 Button btn;
 View deneme2lout;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    ViewPagerAdapter adapter = new ViewPagerAdapter( this );
    ViewPager pager = (ViewPager)findViewById( R.id.viewpager );
    pager.setAdapter( adapter );
    pager.setCurrentItem(0);


    LayoutInflater getView = getLayoutInflater();
    deneme2lout = (View) getView.inflate(R.layout.deneme2,null);      
    btn = (Button) deneme2lout.findViewById(R.id.button1);

}

public void buttonClick(View v) {
    if(v.equals(btn)) {
    deneme2lout.setBackgroundDrawable(getResources().getDrawable(R.drawable.background));
    }
}

 }

So as i get, i cannot use those two codes… So how should i do it? I need to change background of the second page when clicked the button on second layout.

And here’s my deneme2.xml codes:

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

    <Button
        android:id="@+id/button1"
        android:layout_width="175dp"
        android:layout_height="95dp"
        android:layout_x="69dp"
        android:layout_y="174dp"
        android:textSize="25dp"
        android:text="Change" />

</AbsoluteLayout>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T04:33:34+00:00Added an answer on May 29, 2026 at 4:33 am

    That’s because, as it explains, OnClickListener doesn’t have these two methods which you’re using inside an OnClickListener. Replace:

    LinearLayout l = (LinearLayout) findViewById(R.id.layout2);
    

    with

    LinearLayout l = (LinearLayout) v.findViewById(R.id.layout2);
    

    if it then says v should be final, that should be okay. And replace:

    getResources().getDrawable(R.drawable.background)
    

    with

    ViewPagerAdapter.this.context.getResources().getDrawable(R.drawable.background)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm extremely new to using jQuery/JavaScript, so please don't judge me if this is
I'm new to Rails and Android, so please don't blame me if the question
I am new to Python so please don't flame me if the question is
I am new to Python so please don't flame me if I ask something
I am fairly new to MVC so please don't hesitate to suggest a better/cleaner/simpler
I am new to Visual C++ so please don't bite my head off. I
I'm new to working with MVC so please don't assume I know anything. I
I have to make a short Windows shell script. Please don't run away. It
I am new to xml , so please don't mind if it is too
Please don't judge me for what I'm doing because I realise it's a bizzare

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.