以一个listview作为一个item

当不确定会有多少个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>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值