自定义Tab2

class MyAdapter extends BaseAdapter
{
private List<Bean> list = new ArrayList<Bean>();

private LayoutInflater inflater;

public MyAdapter(Context context)
{
list = new ArrayList<Bean>();

inflater = LayoutInflater.from(context);
}

public int getCount()
{
return list.size();
}

public List<Bean> getTaskList()
{
return list;
}

public Object getItem(int position)
{
return list.get(position);
}

public long getItemId(int position)
{
return position;
}

public View getView(int position, View convertView, ViewGroup parent)
{
Bean task = list.get(position);

if (task == null)
{
return convertView;
}
if (convertView == null)
{
convertView = inflater.inflate(R.layout.task_history_row, null);
}

TextView top = (TextView)convertView.findViewById(R.id.task_row_top);
TextView bottom = (TextView)convertView.findViewById(R.id.task_row_bottom);
top.setText(task.getA());
bottom.setText(task.getB());
convertView.setId(position);
return convertView;
}

public void setCTaskData(List<Bean> tList)
{
this.list = tList;
}

}


abstract class MyActivity extends BaseActivity
{
protected View prePressed;

protected List<View> tabList;

private ListView mListView;

private HorizontalScrollView mScroll;

private ImageView line;

protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

setContentView(R.layout.task_history_main);
initView();
}

protected void onResume()
{
super.onResume();
}

protected void setListAdapter(BaseAdapter adapter)
{
mListView.setAdapter(adapter);

mListView.setOnLongClickListener(this);
}

protected Adapter getListAdapter()
{
return mListView.getAdapter();
}

private void initView()
{
mListView = (ListView)findViewById(R.id.task_list_view);
line = (ImageView)findViewById(R.id.line);
mScroll = (HorizontalScrollView)findViewById(R.id.tabHost);
}

private void initTab(String[] tabArray, OnClickListener listener)
{
LinearLayout.LayoutParams lp =
new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

TabHost host = new TabHost(this, lp, tabArray, listener);
host.setOrientation(LinearLayout.HORIZONTAL);
tabList = host.getTabList();
mScroll.addView(host);
}

public void builder(String[] tabArray, OnClickListener listener)
{
initTab(tabArray, listener);
changeTabView(tabList);
if (tabArray == null || tabArray.length == 0)
{
line.setVisibility(ImageView.GONE);
}
else
{
line.setVisibility(ImageView.VISIBLE);
}
}

private void changeTabView(List<View> mTabList)
{
if (mTabList != null)
{
for (View tabView : mTabList)
{
tabView.setBackgroundResource(R.drawable.tab_unpressed);
}
}
}

public void setPressedTab(View v, int pressed, int unpressed)
{
if (tabList == null)
{
return;
}
if (prePressed != null)
{
prePressed.setBackgroundResource(unpressed);
}
v.setBackgroundResource(pressed);
prePressed = v;
}

public ListView getListView()
{
return mListView;
}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值