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

test: Reply
 
LinkBack Thread Tools
Old January 11th, 2011, 12:21 PM   #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 Desperate for help - Link TextView to another page

This is driving me up the wall, i keep getting different answers from everyone so was hoping I can get a definite answer on here. Looking for the simplest way for me to have the text in my app to link to the another page within my app.

What's the easiest way this can be done?

I'm using lots of nested LinearLayouts with a TextView and ImageView in each. I only need my text to be linkable so just TextView.

Is it easier to have just the image linking? I.e. I can have the ImageView linking instead of my TextView? Whatevers easier really as this is getting tiring now.

i've been told to use an OnTouchListener, OnClickListener, Android:Clickable etc and nothing has worked.


Any help would really be appreciated.

Advertisements
RED_ is offline  
Reply With Quote
sponsored links
Old January 11th, 2011, 03:28 PM   #2 (permalink)
New Member
 
Join Date: Jan 2011
Posts: 7
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 1 Time in 1 Post
Default

I'm sure you should be able to achieve this with an OnClickListener. Can you paste the code where you register your listener and call a new activity in the onClick() method?
vasanthj is offline  
Reply With Quote
Old January 11th, 2011, 03:56 PM   #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

This is what i was told to add but it didn't work as i got a force close when running it and i had nowhere to put the url for the new page.

Code:
LinearLayout layout = (LinearLayout)findViewById(R.id.layoutId);

layout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
RED_ is offline  
Reply With Quote
Old January 11th, 2011, 05:16 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

Big fat breakthrough with this:

Code:
LinearLayout layout = (LinearLayout)findViewById(R.id.layout1);

   layout.setOnClickListener(new View.OnClickListener() {

           @Override
           public void onClick(View v) {
               // TODO Auto-generated method stub
        	   startActivity(new Intent(SellScreen.this, Linktext.class));
           }
       });
However, i get a force close when clicking the area . The code above makes a view clickable, since im using nested LinearLayouts in this case i'm clicking on one of the LinearLayouts

Maybe i need to add something to the xml files or something into the new class it goes to? Been working 8hours+ on this now and getting nowhere. Manifest maybe..? No idea.
RED_ is offline  
Last edited by RED_; January 11th, 2011 at 05:25 PM.
Reply With Quote
Old January 11th, 2011, 05:28 PM   #5 (permalink)
Member
 
Join Date: Jun 2010
Posts: 363
 
Device(s): Samsung Galaxy S (international)
Carrier: Not Provided

Thanks: 72
Thanked 58 Times in 55 Posts
Default

don't link to the layout in the code
have a textview , and link it inside the code then put View.OnClickListener [the same way you did up there]

I haven't tried it , but it should work

you can also use this
ImageButton | Android Developers
JiMMaR is offline  
Reply With Quote
The Following User Says Thank You to JiMMaR For This Useful Post:
RED_ (January 12th, 2011)
Old January 11th, 2011, 06:24 PM   #6 (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

What do you mean?

As in don't have this bit: "LinearLayout layout = (LinearLayout)findViewById(R.id.layout1);"?

I have a textview in my main.xml so should i change the above bit to Textview?

Thing is though that the code that i wrote allows a whole view to be a clickable area, so just like the android market see here: http://img269.imageshack.us/img269/691/09droid3295x440.jpg

Any chance of that being done? No problem if not, just an option if possible.
RED_ is offline  
Reply With Quote
Old January 11th, 2011, 06:40 PM   #7 (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

Sorry to keep bumping and posting but this is a bit long. I'm trying the textview option as mentioned above, this is what i changed the code too still getting force closes:
Code:
TextView text = (TextView)findViewById(R.id.text1);

   text.setOnClickListener(new View.OnClickListener() {

           @Override
           public void onClick(View v) {
               // TODO Auto-generated method stub
        	   startActivity(new Intent(SellScreen.this, Linktext.class));
           }
       });

This is the code on the page that the onClick links too:
Code:
package com.android.sellscreen;

import android.app.Activity;
import android.os.Bundle;

public class Linktext extends Activity {

	public void onCreate(Bundle savedInstanceState) {
		   super.onCreate(savedInstanceState);
		   setContentView(R.layout.main);
	}
}
RED_ is offline  
Last edited by RED_; January 11th, 2011 at 06:42 PM.
Reply With Quote
Old January 11th, 2011, 07:07 PM   #8 (permalink)
Member
 
Join Date: Dec 2010
Location: Aarhus, Denmark
Posts: 136
 
Device(s): SE Xperia X10
Carrier: Not Provided

Thanks: 2
Thanked 22 Times in 22 Posts
Default

Are you running this from Eclipse and with the emulator? = What error messages do you get with the force close? They are almost always the fastest way to the answer...
JamTheMan is offline  
Reply With Quote
The Following User Says Thank You to JamTheMan For This Useful Post:
RED_ (January 12th, 2011)
Old January 11th, 2011, 07:19 PM   #9 (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

The console doesn't show any errors when a force close takes place. Just the usual dialog in the emulator:

"The application SellScreen(process com.android.sellscreen) has stopped unexpectedly. Try again later"

All i know is when i remove the this line: startActivity(new Intent(SellScreen.this, Linktext.class)); i get no force close or errors, however nothing happens when clicking that area/text. So therefore it must be something in that line.
RED_ is offline  
Reply With Quote
Old January 12th, 2011, 04:16 AM   #10 (permalink)
Member
 
Join Date: Dec 2010
Location: Aarhus, Denmark
Posts: 136
 
Device(s): SE Xperia X10
Carrier: Not Provided

Thanks: 2
Thanked 22 Times in 22 Posts
Default

Did you try looking at the LogCat instead of the Console?

The most common error when a startActivity results in a ForceClose is that you forgot to add the activity you want to start to the Manifest.
JamTheMan is offline  
Reply With Quote
The Following User Says Thank You to JamTheMan For This Useful Post:
RED_ (January 12th, 2011)
sponsored links
Old January 12th, 2011, 04:27 AM   #11 (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 did have a problem with that to be fair. This is my manifest:

Code:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.android.sellscreen"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".SellScreen"
                  android:label="@string/app_name">   
        <activity android:name=".Linktext"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        </activity>
    </application>


</manifest>
How is the new activity added properly? Its called Linktext but when i add it under SellScreen (like i have above) and run it, it comes up with a ''no launcher found'' error.
RED_ is offline  
Reply With Quote
Old January 12th, 2011, 05:00 AM   #12 (permalink)
Member
 
Join Date: Dec 2010
Location: Aarhus, Denmark
Posts: 136
 
Device(s): SE Xperia X10
Carrier: Not Provided

Thanks: 2
Thanked 22 Times in 22 Posts
Default

Well... Your main (the first one you want to see when you start the app) activity should have the intent filter you have there. Like this:

Code:
<activity 
  android:name=".MainActivity"
  android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

And any new activity, which should only be used by your app can be added simply like this:

Code:
<activity
  android:name=".SecondActivity"
  android:label="@string/second_activity_name"
>
</activity>
New activities should be added after ending the main activity, and are not to be nested!
JamTheMan is offline  
Last edited by JamTheMan; January 12th, 2011 at 05:02 AM.
Reply With Quote
The Following User Says Thank You to JamTheMan For This Useful Post:
RED_ (January 12th, 2011)
Old January 12th, 2011, 05:58 AM   #13 (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

Works like a charm! Really appreciate your help mate, spent all of last night and the day before trying to get it to work and you pop along and fix it in one go Top stuff, just glad its done.
RED_ is offline  
Reply With Quote
Old January 12th, 2011, 08:21 AM   #14 (permalink)
Member
 
Join Date: Dec 2010
Location: Aarhus, Denmark
Posts: 136
 
Device(s): SE Xperia X10
Carrier: Not Provided

Thanks: 2
Thanked 22 Times in 22 Posts
Default

;-)

Always glad to help
JamTheMan is offline  
Reply With Quote
Old January 12th, 2011, 02:11 PM   #15 (permalink)
New Member
 
Join Date: Jan 2011
Posts: 7
 
Device(s):
Carrier: Not Provided

Thanks: 1
Thanked 1 Time in 1 Post
Default

Excellent work JamTheMan!
vasanthj is offline  
Reply With Quote
Reply
Tags
android, textview


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 01:01 AM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.