Ok I got it. Make your SecondActivity as abstract class in yr library and create a clientSecondActivity class and extend SecondActivity
OverRide onCreate() method and add required views. thanks Chenna On Oct 26, 7:47 pm, Francesco <nolano...@gmail.com> wrote: > Ok, thanks Chenna, for your help .. > > maybe i didn't make my self very clear, I'm very sorry... > > Setting the text resource from my client app to library was just an > example.. I was actually trying to modify the Activity library > behavior, overwriting it on the client app that is using the library > (if possible). > As it is very simple to redefine resources in a project using a > library, I was wondering whether there is a way to redefine classes > (in particular, activities) in a project, overwriting or extending the > library ones... > > So, in my example, I was trying to overwrite SecondActivity defined in > library, in order to modify its behavior ... in the example above, > I've just changed text in TextView, but I could do more, for example I > would implement a different functionality in activity project , or > adding programmatically a new view ... > > thanks > francesco > > On 26 Ott, 15:42, Chenna <chenn...@gmail.com> wrote: > > > > > > > > > As per my understanding you have two activities in your library. So > > you want to provide your library for another apps to use it. You want > > to set text resource from your client app to your library activity. If > > you want only resource. Create a class Configurator and declare a > > static variable testdata and assign R.string.Textdata this R is > > belongs to your library. And use this variable to set in yr text view. > > > When you create a Client app Activity get the string resource from > > client app resource and assign Configurator.testData = > > R.string.testdata this R is from client app. > > > thanks > > Chenna > > > On Oct 26, 6:26 pm, Francesco <nolano...@gmail.com> wrote: > > > > Thanks, Chenna, for your reply; > > > > but I have some doubts more... Could you better explain me , with > > > sample code? > > > > You say: "Declare your activity as abstract class in library" => ok, > > > in this way (right?) > > > > ************************************************************************** > > > public abstract class SecondLibraryActivity extends Activity{ > > > > @Override > > > public void onCreate(Bundle savedInstanceState) { > > > super.onCreate(savedInstanceState); > > > setContentView(R.layout.second_activity); > > > > TextView t = (TextView) findViewById(R.id.textView); > > > > t.setText("Hello, i'm second activity on library!!!"); > > > }} > > > > ************************************************************************** > > > > then, "create a new activity in client apps using that library.": => > > > like this (right?) > > > > ************************************************************************* > > > public class SecondLibraryActivity extends Activity{ > > > > @Override > > > public void onCreate(Bundle savedInstanceState) { > > > super.onCreate(savedInstanceState); > > > setContentView(R.layout.second_activity); > > > > TextView t = (TextView) findViewById(R.id.textView); > > > > t.setText("Hello, i'm second activity on project!!!"); > > > } > > > > } > > > > ************************************************************************* > > > > now, in Manifest Project, which activity must I declare ??? > > > > * if a refer to project activity : > > > <application android:icon="@drawable/icon" android:label="@string/ > > > app_name"> > > > <activity > > > android:name="com.nolanofra.app.androidLibraryExample.AndroidLibraryExample > > > Activity"> > > > <intent-filter> > > > <action android:name="android.intent.action.MAIN" /> > > > <category > > > android:name="android.intent.category.LAUNCHER" /> > > > </intent-filter> > > > </activity> > > > > <activity android:name=".SecondLibraryActivity"> > > > </activity> > > > > </application> > > > > then I have an arror in AndroidLibraryExampleActivity at line: > > > Intent intent = new Intent(AndroidLibraryExampleActivity.this, > > > SecondLibraryActivity.class); > > > > with ActivityNotFoundException; > > > > * if I refer to library activity: > > > > <activity > > > android:name="com.nolanofra.app.androidLibraryExample.AndroidLibraryExample > > > Activity"> > > > <intent-filter> > > > <action android:name="android.intent.action.MAIN" /> > > > <category > > > android:name="android.intent.category.LAUNCHER" /> > > > </intent-filter> > > > </activity> > > > > <activity > > > android:name="com.nolanofra.app.androidLibraryExample.SecondLibraryActivity > > > "> > > > </activity> > > > > then it will be run always code of library activity. > > > > I don' t understand when you say: "Declare a configuration class with > > > static variables for your library. Assign resource ids with your local > > > R.ids ..." > > > Could you explain me with an example? > > > > Thanks for you patience, > > > francesco > > > > On 26 Ott, 14:29, Chenna <chenn...@gmail.com> wrote: > > > > > Declare your activity as abstract class in library and create a new > > > > activity in client apps using that library. > > > > > Declare a configuration class with static variables for your library. > > > > Assign resource ids with your local R.ids. If required you can allow > > > > yr client apps can configure required resources for the same. > > > > > hope this helps. > > > > > thanks > > > > Chenna > > > > > On Oct 26, 2:18 pm, Francesco <nolano...@gmail.com> wrote: > > > > > > hi all, > > > > > > this is my situation: i have a library project, and a project > > > > > referencing it. I know that is very simple to redefine any resource in > > > > > my project, because in cases where a resource ID is defined in both > > > > > the application and the library, the tools ensure that the resource > > > > > declared in the application gets priority and that the resource in the > > > > > library project is not compiled into the application .apk ( from > > > > > android developers web site ). > > > > > > But: how can i do to redefine source (for example, override an > > > > > activity) in my project? > > > > > > I have implemented some code samples, to better explain my problem: > > > > > > In my library project, i have two activities: > > > > > > *AndroidLibraryExampleActivity: > > > > > ******************************************************************** > > > > > > package com.nolanofra.app.androidLibraryExample; > > > > > > import android.app.Activity; > > > > > import android.content.Intent; > > > > > import android.os.Bundle; > > > > > import android.view.View; > > > > > > public class AndroidLibraryExampleActivity extends Activity { > > > > > /** Called when the activity is first created. */ > > > > > @Override > > > > > public void onCreate(Bundle savedInstanceState) { > > > > > super.onCreate(savedInstanceState); > > > > > setContentView(R.layout.main); > > > > > > } > > > > > > public void onSecondActivityGo (View v) > > > > > { > > > > > Intent intent = new Intent(AndroidLibraryExampleActivity.this, > > > > > SecondLibraryActivity.class); > > > > > > startActivity(intent);} > > > > > > *************************************************************************** > > > > > ******************* > > > > > > and SecondLibraryActivity: > > > > > ************************************************************** > > > > > > package com.nolanofra.app.androidLibraryExample; > > > > > > import android.app.Activity; > > > > > import android.os.Bundle; > > > > > import android.widget.TextView; > > > > > > public class SecondLibraryActivity extends Activity{ > > > > > > @Override > > > > > public void onCreate(Bundle savedInstanceState) { > > > > > super.onCreate(savedInstanceState); > > > > > setContentView(R.layout.second_activity); > > > > > > TextView t = (TextView) findViewById(R.id.textView); > > > > > > t.setText("Hello, i'm second activity on library!!!"); > > > > > }} > > > > > > *************************************************************************** > > > > > ******************* > > > > > > Manifest of library project is: > > > > > ************************************************************ > > > > > <?xml version="1.0" encoding="utf-8"?> > > > > > <manifest xmlns:android="http://schemas.android.com/apk/res/android" > > > > > package="com.nolanofra.app.androidLibraryExample" > > > > > android:versionCode="1" > > > > > android:versionName="1.0"> > > > > > <uses-sdk android:minSdkVersion="8" /> > > > > > > <application android:icon="@drawable/icon" android:label="@string/ > > > > > app_name"> > > > > > <activity android:name=".AndroidLibraryExampleActivity" > > > > > android:label="@string/app_name"> > > > > > </activity> > > > > > > <activity android:name=".SecondLibraryActivity" > > > > > android:label="@string/app_name"> > > > > > </activity> > > > > > > </application> > > > > > </manifest> > > > > > *************************************************************************** > > > > > ********************** > > > > > > In my project referencing library, I want to redefine > > > > > SecondLibraryActivity in order to change text displayed in text view, > > > > > for example I would like to do some of this: > > > > > > package com.nolanofra.app.sampleProjectUsingLibrary; > > > > > > import android.app.Activity; > > > > > import android.os.Bundle; > > > > > import android.widget.TextView; > > > > > > import com.nolanofra.app.androidLibraryExample.R; > > > > > > public class SecondLibraryActivity extends Activity{ > > > > > > @Override > > ... > > read more » -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en