0

我想将视图放在缓冲区之类的东西中,然后再显示它们。就像是:

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);
}
4

1 回答 1

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));
}
于 2013-07-26T08:43:11.457 回答