[英]Building either a Swing and Android app from the same code base using Ant
[英]Using the same android app as a base for a new one
我的工作區中有兩個android應用程序項目:Testobject和MyAndroidApplication。
我想使用其中之一TestObject作為新對象的基礎。 為此,我已將Testobject設置為庫(“屬性-Android”-選中“復選框為庫”)。 在MyAndroidApplication中,我添加了lib Testobject(屬性-Android-添加...)。
現在,我可以使用Testobject的所有類和資源:
我使用了來自Testobject的XML,並更改了例如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);
}
單擊ImageView時,開始一個新的活動。
Intent intent = new Intent(this, TestKlasse1.class);
startActivity(intent);
啟動的活動在項目Testobject中。
如何在MyAndroidApplication項目中從TestKlasse1更改TextView?
//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);
}
我不會更改TestKlasse1中的內容,因為我想將此類用於不同的應用程序。 例如,對於超級市場應用程序或汽車制造商應用程序。 我不想只更改ic_launcher。 具有不同名稱的多個應用程序
盡管該類在另一個項目中,但如何更改例如TextView?
通過Intent,您可以將參數發送到活動。
Intent intent = new Intent(this, TestKlasse1.class);
intent.putExtra("MY_STRING", "New Content");
startActivity(intent);
在您的活動中,您可以通過以下方式獲得內容(在onStart
):
String myString = getIntent().getStringExtra("MY_STRING");
或者,可以將字符串添加到項目中的strings.xml資源文件中,然后可以使用相同的名稱覆蓋應用程序項目中的值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.