Android 相对论中内容明确的问题
我在更新Android 相对论中内容明确的问题,android,android-layout,android-intent,textview,Android,Android Layout,Android Intent,Textview,我在更新RelativeLayout中的TextView内容时面临一个问题。当我在第二次更新时,我需要清除RelativeLayout中以前的文本 我的应用程序activity\u calendar.xml <RelativeLayout android:id="@+id/rel_container" android:layout_width="fill_parent" android:layout_height="f
RelativeLayout
中的TextView
内容时面临一个问题。当我在第二次更新时,我需要清除RelativeLayout
中以前的文本
我的应用程序activity\u calendar.xml
<RelativeLayout
android:id="@+id/rel_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignTop="@+id/linearLayout1"
android:layout_toRightOf="@+id/linearLayout1">
</RelativeLayout>
这是主要代码:
public void listall () {
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.rel_container);
int prevTextViewId = 0;
for (int i = 0; i < titleCalendar.length; i++) {
final TextView textView = new TextView(this);
textView.setText(titleCalendar[i]);
cnvrttime = hourCalendar[i] - 3;
addcnvrtTime = 60*cnvrttime;
curTextViewId = prevTextViewId + 1;
textView.setId(curTextViewId);
final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.BELOW, addcnvrtTime);
params.setMargins(0, convertDPtoInt((float)addcnvrtTime), 0, 0);
textView.setLayoutParams(params);
prevTextViewId = curTextViewId;
relativeLayout.addView(textView, params);
}
public void listall(){
RelativeLayout RelativeLayout=(RelativeLayout)findViewById(R.id.rel_容器);
int-prevTextViewId=0;
对于(int i=0;i
您需要为TextView提供一个id,以便以后可以找到它:
textView.setId(1234);
随后:
TextView textView = findViewById(1234);
textView.setText("New Text");
如果相对布局中没有任何要保留的子视图,请在循环的
之前调用relativeLayout.removeallview()
。否则,请使用removeView(View)
或removeViewAt(int)
删除不需要的文本。不使用linearLayout或ListView的原因是什么?因此,我可以在使用linearLayout时删除文本吗?不需要“清除”文本,如果调用settText(),它会将该文本放在视图中,覆盖之前的文本。