引言
在這半周的工作中,我們小組仍然主要進行後臺客戶端的代碼編寫工作以及界面的優化,在這裏,我對自己主要從事的工作,即查看評論功能,做一個重點的介紹。
一、界面編寫
在之前的界面設計中,已經完成了關於我們界面的設計。該界面比較簡單,在最外層使用一個縱向的LinearLayout,內層嵌套一個ListView顯示列表即可,具體代碼如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/white"
android:padding="0dp">
<ImageButton
android:layout_width="?attr/actionBarSize"
android:layout_height="?attr/actionBarSize"
android:layout_alignParentLeft="true"
android:background="@drawable/toolbar_back_bg"
android:onClick="CommentBack"
android:src="?attr/homeAsUpIndicator" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="評論"
android:textColor="@color/black"
android:textSize="19sp" />
</RelativeLayout>
<ListView
android:id="@+id/comment_lv"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
根據該代碼生成的預覽效果如下所示,可以看到是符合預期的。
二、內部邏輯實現
功能十分簡單,只需要從後臺獲取評論,然後加載到ListView中顯示即可。
代碼如下:
/**
* 評論界面
*/
public class CommentActivity extends BaseActivity {
private ListView comment_lv;
private ArrayList<SuperViseBriefBean> SuperViseBriefList;
private CommentListAdapter adapter;
@Override
public int getLayoutId() {
return R.layout.activity_comment;
}
@Override
public void afterCreate(Bundle savedInstanceState) {
comment_lv = (ListView) findViewById(R.id.comment_lv);
Intent intent = getIntent();
SuperViseBriefList = (ArrayList<SuperViseBriefBean>) intent.getExtras().get("briefBean");
adapter = new CommentListAdapter(this, SuperViseBriefList);
comment_lv.setAdapter(adapter);
}
public void CommentBack(View view) {
CommentActivity.this.finish();
}
}
功能完成之後,我進行了白盒測試。因爲代碼比較簡單的緣故,測試沒有發現問題,順利通過。