Go Back   Android Forums > Android Development > Application Development
Application Development Dev lounge for our application developers.

test: Reply
 
LinkBack Thread Tools
Old November 2nd, 2012, 07:29 AM   #1 (permalink)
Member
Thread Author (OP)
 
Join Date: Nov 2010
Location: London
Posts: 210
 
Device(s): HTC Desire HD, Samsung Galaxy SII, Samsung Galaxy Nexus, ASUS Nexus 7
Carrier: Not Provided

Thanks: 16
Thanked 8 Times in 7 Posts
Default Implementing a slideview from tutorial. What am I doing wrong?

Hey guys,

First off, here is the tutorial I followed: Android User Interface Design: Horizontal View Paging

The actual slideview works fine, moving left and right works just like swiping between homescreens of a launcher. However there are some issues. Mainly that the onClicks of my TextViews are unresponsive and that my ImageView buttons on everypage other than my first one (the one you see when the app launches) gives me a force close error.

Each one of my buttons has one TextView and one ImageView. On my first screen the ImageViews work but when clicking on a TextView nothing happens. On every other page the ImageView's give me a force close and again, the TextViews don't do anything.

This is my Java file (I removed the onClicks because I have a lot of them:

Code:
package com.android.history;

import android.os.Bundle;
import android.os.Parcelable;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.blank_main);
        
        MyPagerAdapter adapter = new MyPagerAdapter();
        ViewPager myPager = (ViewPager) findViewById(R.id.mysixpanelpager);
        myPager.setAdapter(adapter);
        myPager.setCurrentItem(1);
        
        new EULA(this).show();
    }

        public void AboutUs (View v) {
    	
    	Intent gotoabout = new Intent(getApplicationContext(), AboutUsMain.class);
    	startActivity(gotoabout);   	
    }
    
//--- SLIDE VIEW HERE ---
    private class MyPagerAdapter extends PagerAdapter {
        public int getCount() {
            return 6;
        }
        public Object instantiateItem(View collection, int position) {
            LayoutInflater inflater = (LayoutInflater) collection.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            int resId = 0;
            switch (position) {
            case 0:
            	resId = R.layout.about;
            	break;
            case 1:
            	resId = R.layout.main;
            	break;
            case 2:
                resId = R.layout.main_two;
                break;
            case 3:
                resId = R.layout.main_three;
                break;
            case 4:
                resId = R.layout.main_four;
                break;
            case 5:
                resId = R.layout.main_five;
                break;
            }
            View view = inflater.inflate(resId, null);
            ((ViewPager) collection).addView(view, 0);
            return view;
        }
        @Override
        public void destroyItem(View arg0, int arg1, Object arg2) {
            ((ViewPager) arg0).removeView((View) arg2);
        }
        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == ((View) arg1);
        }
        @Override
        public Parcelable saveState() {
            return null;
        }
}

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}
"blank_main" consists of a linear layout with the following inside it:
Code:
<android.support.v4.view.ViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/mysixpanelpager"/>


Is there a better way to do this if my problem can't be resolved?

Really appreciate any help.

Advertisements
__________________
Twitter.

My Android apps: Link to play store.
RED_ is offline  
Last edited by RED_; November 2nd, 2012 at 08:36 AM.
Reply With Quote
sponsored links
Old November 2nd, 2012, 08:18 AM   #2 (permalink)
Senior Member
 
jonbonazza's Avatar
 
Join Date: Jul 2010
Gender: Male
Posts: 1,935
 
Device(s): Nexus 4, Samsung Galaxy S II, HTC Evo 4G, Amazon Kindle Fire
Carrier: ATT

Thanks: 235
Thanked 482 Times in 294 Posts
Default

Where are you setting your onClick listeners? Also, where is the functionality for your buttons?
__________________
My blog, Inverted Keystrokes, is looking for aspiring developers (not necessarily with Android) to post articles. If you have any development experience and are interested in participating, please PM me. =)
jonbonazza is offline  
Reply With Quote
Old November 2nd, 2012, 08:34 AM   #3 (permalink)
Member
Thread Author (OP)
 
Join Date: Nov 2010
Location: London
Posts: 210
 
Device(s): HTC Desire HD, Samsung Galaxy SII, Samsung Galaxy Nexus, ASUS Nexus 7
Carrier: Not Provided

Thanks: 16
Thanked 8 Times in 7 Posts
Default

Quote:
Originally Posted by jonbonazza View Post
Where are you setting your onClick listeners? Also, where is the functionality for your buttons?
I'm setting my onClicks in the XML. android : onClick and all that. I've added one of my onClicks back to my java code, there are quite a few of those all leading to different pages. I'll put it in bold. It's under my onCreate method. It's in the same place in my code and as I said, there are quite a few of them.
RED_ is offline  
Last edited by RED_; November 2nd, 2012 at 08:37 AM.
Reply With Quote
Old November 3rd, 2012, 12:42 PM   #4 (permalink)
Member
Thread Author (OP)
 
Join Date: Nov 2010
Location: London
Posts: 210
 
Device(s): HTC Desire HD, Samsung Galaxy SII, Samsung Galaxy Nexus, ASUS Nexus 7
Carrier: Not Provided

Thanks: 16
Thanked 8 Times in 7 Posts
Default

I think I found the issue here so if anyone has the same problem..

I'm supposed to use a FragmentPagerAdapter not just a View pager adapter. Using fragments means that when I swipe between layouts the Activity will change too. This is what I need.

The reason I'm having problems is because the viewpager is all in one activity so even though I slide to a new layout it doesn't change to that layouts Activity, it stays on MainActivity, therefore it can't find any onClicks or anything related to said activity.
RED_ is offline  
Reply With Quote
Reply
Tags
android, force close, homescreen, imageview, pageradaptor, slideview, textview, viewpager indicator compatibility library


Go Back   Android Forums > Android Development > Application Development
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 05:34 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.