Skip to content

Commit

Permalink
修复bug
Browse files Browse the repository at this point in the history
修复显示参与活动用户的Listview不能展开显示的问题
  • Loading branch information
YongdongHe committed Feb 3, 2016
1 parent 51025da commit cc2cb08
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ public void onResponse(String response) {
tv_content.setText(activityInfo.getContent());
liv_partner.setAdapter(new UserListAdapter(getBaseContext(),
R.layout.listview_activity_info_item, activityInfo.getPartnerArrayList()));

//根据listview的item数目和高度设置本身的高度,以保证listview能全部展开展示
UserListAdapter.setListViewHeightBasedOnChildren(liv_partner);
} else if (json_res.getInt("code") == 404) {
Toast.makeText(getBaseContext(),"该活动不存在或者已被删除",Toast.LENGTH_SHORT).show();
onBackPressed();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -50,4 +52,26 @@ public void onClick(View v) {
});
return view;
}

public static void setListViewHeightBasedOnChildren(ListView listView) {
//根据listview的item数目设置宽度
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}

ViewGroup.LayoutParams params = listView.getLayoutParams();

params.height = totalHeight
+ (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ public ActivityInfo (JSONObject response)throws JSONException{
this.activity_id = response.getString("activity_id");
this.title = response.getString("title");
this.content = response.getString("content");
partnerArrayList = new ArrayList<>();
this.partnerArrayList = new ArrayList<>();
JSONArray partners = response.getJSONArray("partners");
for(int i = 0;i<partners.length();i++){
JSONObject partner = partners.optJSONObject(i);
partnerArrayList.add(new Partner(
this.partnerArrayList.add(new Partner(
partner.getString("name"),
partner.getString("id"),
partner.getString("phone")
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/listview_activity_info_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
Expand Down

0 comments on commit cc2cb08

Please sign in to comment.