1

I have two android application projects in my workspace, Testobject and MyAndroidApplication.

I would like to use one of them, Testobject, as a base for the new one. For that purpose, I have setting up Testobject as a library (Properties - Android - checked Checkbox Is Library). In MyAndroidApplication I have add the lib Testobject (Properties - Android - Add...).

Now I can use all classes and ressources from Testobject:

reference library

I have used an XML from Testobject and changed for example the ImageView.

/** called when the activity is first created */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    ImageView stImageView = (ImageView) findViewById(R.id.imageview_ov_remote);
    stImageView.setImageResource(R.drawable.car_launcher);
}

While clicking the ImageView, a new activity get started.

   Intent intent = new Intent(this, TestKlasse1.class);
   startActivity(intent);

The started activity is in the project Testobject.

How can I change a TextView from TestKlasse1 in the project MyAndroidApplication?

    //cutout from Testklasse1 in Testobject

    TextView testString;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_testklasse_eins);

    testString = (TextView) findViewById(R.id.testKlasse1TextView);

    }

I won't change the content in TestKlasse1, because I want to use this class for different apps. For example for a supermarket app or an automobile manufacturer app. I don't want only to change the ic_launcher. Multiple Applications with different names

How can I change for example the TextView, though the class is in another project?

Community
  • 1
  • 1
maryBlaa
  • 115
  • 10

1 Answers1

0

Via the Intent you can send parameters to the activity.

 Intent intent = new Intent(this, TestKlasse1.class);
 intent.putExtra("MY_STRING", "New Content");
 startActivity(intent);

And in your activity you get the contents (in onStart) by:

 String myString = getIntent().getStringExtra("MY_STRING");

Or you can add the string to a strings.xml resource file in the project, then you can override the value in the application project by using the same name.

GvS
  • 52,015
  • 16
  • 101
  • 139
  • I've tried this: `...intent.putExtra("test", "hello cookie!");...` But the text in the TextView didn't changed. `String test = "hallo"; ...testString = (TextView) findViewById(R.id.testKlasse1TextView); testString.setText(test);` – maryBlaa Sep 24 '14 at 13:25
  • Call the setText with a hardcoded string, to see what's happening. – GvS Sep 25 '14 at 14:18