当不确定会有多少个listview的数据的时候,可以将listview作为另一个listview的item来进行coding。
如下
PushContentAdapter pushContentAdapter = new PushContentAdapter(getActivity(), data);
lv_main.setAdapter(pushContentAdapter);
public class PushContentAdapter extends BaseAdapter implements HeaderAdapter {
private ArrayList<Columnm1Data> newstdatas;
private LayoutInflater inflater;
private Context context;
public PushContentAdapter(Context context, ArrayList<Columnm1Data> newstdatas) {
this.newstdatas = newstdatas;
this.context = context;
inflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return newstdatas.size();
}
@Override
public Columnm1Data getItem(int position) {
return newstdatas.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
viewHolder holder;
if (view == null) {
holder = new viewHolder();
view = inflater.inflate(R.layout.list_item_main_recommend_outer_content_listview, null);
holder.tvTitle = (TextView) view.findViewById(R.id.tv_column_title);
holder.tv_more = (TextView) view.findViewById(R.id.txt_recommend_mainRecommend);
holder.lv_column = (HeadListView) view.findViewById(R.id.list_recommend_mainRecommend);
holder.lv_column.setFocusable(false);
view.setTag(holder);
} else {
holder = (viewHolder) view.getTag();
}
final Columnm1Data data = newstdatas.get(position);
holder.tvTitle.setText(data.title);
holder.tv_more.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getActivity(), GuessLikeActivity .class);
intent.putExtra("title", data.title);
intent.putExtra("classify", data.sid);
startActivity(intent);
}
});
if (data.detail.size() >= 0) {
GoodRecommendAdapter adapter = new GoodRecommendAdapter(context, data.detail);
holder.lv_column.setAdapter(adapter);
holder.lv_column.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(getActivity(), AlbumActivity.class);
intent.putExtra("sid", data.detail.get(position).sid);
intent.putExtra("id", data.detail.get(position).album_id);
startActivity(intent);
}
});
}
return view;
}
class viewHolder {
TextView tvTitle, tv_more;
HeadListView lv_column;
}
@Override
public int getHeaderState(int position) {
return 0;
}
@Override
public void configureHeader(View header, int position, int alpha) {
}
}
布局
<?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="wrap_content"
android:padding="@dimen/pad_height_14" >
<TextView
android:id="@+id/tv_column_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:drawableLeft="@drawable/activity_play_checked"
android:drawablePadding="@dimen/pad_height_10"
android:text="精彩推荐"
android:textColor="@color/main_color_black"
android:textSize="@dimen/pad_text_size_16" />
<TextView
android:id="@+id/txt_recommend_mainRecommend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:drawablePadding="@dimen/pad_height_8"
android:drawableRight="@drawable/homepage_right_hui"
android:text="更多"
android:textColor="@color/main_color_black_center"
android:textSize="@dimen/pad_text_size_14" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:background="@color/view_bg" />
<com.hipad.voice.view.HeadListView
android:id="@+id/list_recommend_mainRecommend"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</com.hipad.voice.view.HeadListView>
</LinearLayout>