20161205

安卓横向列表HorizontalListView

 

首先是布局

<com.devsmart.android.ui.HorizontalListView
android:id="@+id/listview_search_titlebar"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_centerVertical="true"

>

</com.devsmart.android.ui.HorizontalListView>



在activity里
private HorizontalListView listview_search_titlebar;

listview_search_titlebar = (HorizontalListView) findViewById(R.id.listview_search_titlebar);

listview_search_titlebar.setAdapter(new HorizontalListViewAdapter(shopanalysisInfo.getDatas()));//这里没有弄假数据的集合直接从接口获取的


下面是adapter

class HorizontalListViewAdapter extends BaseAdapter {
        private ShopanalysisInfo.DatasBean datas;

public
HorizontalListViewAdapter (ShopanalysisInfo.DatasBean datas) {
            this.datas = datas;
}

@Override
public int getCount() {
return datas.getKeywordList().size();
}

@Override
public Object getItem(int position) {
return datas.getKeywordList().get(position);
}

@Override
public long getItemId(int position) {
return 0;
}
// LayoutInflater inflater=LayoutInflater.from(FirstListView.this);

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = View.inflate(this, R.layout.itemtext, null);
holder.textView = (TextView) convertView.findViewById(R.id.textView);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textView.setText(datas.getKeywordList().get(position));
return convertView;
}

}
public static class ViewHolder {
private TextView textView;
}

整体来说就是listview的步骤。













 

posted @ 2016-12-05 19:14  别着急慢慢来  阅读(114)  评论(0编辑  收藏  举报