[英]How To Limit The Number of Characters displayed In Android Custom ListView which is used in Multiple activities?
[英]Android - Reducing the number of activities used
我正在嘗試一種方法,通過使用同一活動切換布局來減少應用程序中使用的活動總數。 我正在做的是-
/* Class A is the actual activity */
public class A extends Activity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button but=(Button)findViewById(R.id.button1);
but.setOnClickListener(new View.OnClickListener(){
/*When the button is pressed, create an object of class B to switch layout*/
public void onClick(View arg0) {
B b=new B(A.this);
}
});
}
}
/*Classs B handles some operation*/
public class B{
Activity a;
/*Set the new layout inside the constructor or call some other function to do that*/
B(Activity act){
a=act;
a.setContentView(R.layout.newlayout);
}
因此,B類將切換布局,進行一些操作。 我想知道這種方法是否是好的做法,以及是否還有其他方法可以做到這一點。 謝謝
老實說,我不認為這是一個很好的做法,因為通過這種方式來永葆幾類中的籌碼,因為它們是由始終運行,所以它可能是一種資源的浪費主要activiy類引用。
我認為管理兩個處理特定任務的活動要好得多,這有兩個原因:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.