我希望将视图放在缓冲区之类的内容中,然后再显示它们。 类似的东西:
public void addTextView(int belowId, int id,String text){
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.BELOW, belowId);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
TextView tv = new TextView(this);
tv.setId(id);
tv.setText(text+"\n");
///i mean something like this:
buffer = addview(tv,lp)
}
以后再显示
public void showview(bufferview b){
RelativeLayout rSub= (RelativeLayout) findViewById(R.id.rSub);
rsub.addview(b);
}
答案 0 :(得分:1)
如何使用Map
?
http://docs.oracle.com/javase/6/docs/api/java/util/Map.html
Map<Integer,TextView> textViewMap = new HashMap<Integer,TextView>();
public void addTextView(int belowId, int id,String text){
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.BELOW, belowId);
lp.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
TextView tv = new TextView(this);
tv.setLayoutParams(lp);
tv.setId(id);
tv.setText(text+"\n");
textViewMap.put(tv.getId(), tv);
}
public void showview(int id){
RelativeLayout rSub= (RelativeLayout) findViewById(R.id.rSub);
rsub.addview(textViewMap.get(id));
}