我有一个问题,我使用webservices,我想,当我没有任何东西从这个json Web服务删除我在我的代码中做的relativelayout,这是我的布局谁有3相对布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F2F2F2" >
<TextView
android:id="@+txtview/prog_match"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/include1"
android:layout_marginTop="58dp"
android:background="#FF0000"
android:gravity="center"
android:text="@string/program"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+txtview/Last_Match"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+txtview/prog_match"
android:background="#000000"
android:gravity="center"
android:text="@string/txt_last_match"
android:textColor="#FFFFFF"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+txtview/Next_Match"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+txtview/Last_Match"
android:layout_marginTop="104dp"
android:background="#000000"
android:gravity="center"
android:text="@string/txt_next_match"
android:textColor="#FFFFFF"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+txtviews/match"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+txtview/Last_Match"
android:layout_marginLeft="14dp"
android:layout_marginTop="21dp"
android:textColor="#000000"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+txtviews/score"
android:layout_width="wrap_content"
android:textColor="#000000"
android:layout_height="wrap_content"
android:layout_above="@+txtviews/txt_date"
android:layout_alignParentRight="true"
android:layout_marginRight="48dp"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+txtviews/next_date"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+txtviews/txt_vs_match"
android:layout_below="@+txtviews/txt_vs_next_match"
android:layout_marginTop="22dp" />
<TextView
android:id="@+txtviews/next_match"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_alignLeft="@+txtviews/txt_date"
android:layout_below="@+txtview/Next_Match"
android:layout_marginTop="22dp"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="@+txtviews/next_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:layout_alignBottom="@+txtviews/txt_next_date"
android:layout_alignLeft="@+txtviews/txt_time" />
<TextView
android:id="@+txtviews/txt_next_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+txtviews/txt_next_date"
android:layout_alignLeft="@+txtviews/txt_score"
android:textColor="#000000"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:textColor="#000000"
android:id="@+txtviews/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+txtviews/txt_vs_match"
android:layout_below="@+txtviews/txt_vs_match"
android:layout_marginTop="25dp" />
<TextView
android:id="@+txtviews/txt_time"
android:textColor="#000000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+txtviews/txt_date"
android:layout_alignBottom="@+txtviews/txt_date"
android:layout_centerHorizontal="true" />
</RelativeLayout>
这是我的代码有时当我得到(0)或得到(1)应用程序崩溃所以当我没有任何东西要删除其中一个relativeLayout时我想要的那样:
private void prog() {
programs = JSONParser.parseProgram(savedData);
txt1.setText(programs.get(1).getTitle());
txt2.setText(programs.get(0).getTitle());
txt3.setText(programs.get(1).getScore());
txt4.setText(programs.get(0).getScore());
txt5.setText(programs.get(1).getMatchdate());
txt6.setText(programs.get(0).getMatchdate());
txt7.setText(programs.get(1).getTime());
txt8.setText(programs.get(0).getTime());
这是我的json解析器:
public static MonProg ProgramParser(JSONObject jsonProgram) {
Program program = new Program();
try {
program.setTitle(Html.fromHtml(jsonProgram.getString("title")).toString());
program.setReport(jsonProgram.getString("report").toString());
program.setScore(jsonProgram.getString("score").toString());
program.setTime(jsonProgram.getString("start_time").toString());
program.setMatchdate(jsonProgram.getString("date").toString());
return program;
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
答案 0 :(得分:0)
您可以使用以下内容删除带有视图的元素:
ViewGroup myViewGroup = (ViewGroup) viewToRemove.getParent();
myViewGroup.removeView(viewToRemove);
但我认为你不能以这种方式删除root视图。所以要么删除里面的所有内容,请在1个容器中包装RelativeLayout,给它id,然后使用上面的函数。 viewToRemove应该指向RelativeLayout的id。
或者简单地说:
view.setVisiblility(View.GONE)