• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Desperate for help - Link TextView to another page

RED_

Well-Known Member
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.
 
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?
 
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

        }
    });
 
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.
 
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.
 
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);
	}
}
 
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...
 
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.
 
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.
 
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.
 
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!
 
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 :D Top stuff, just glad its done.
 
Back
Top Bottom