80,351
社区成员
发帖
与我相关
我的任务
分享
public class ScrollTypeLayout extends HorizontalScrollView implements View.OnClickListener {
//前面省略,initView()是往里面加TextView
private void initView(){
this.mLayout.removeAllViews();
String[] typenameStrings ={"首页","新品","特价品","aaaa","bbbb","cccc","dddd"};
for(int i=0;i<typenameStrings.length;i++){
TextView localTextView = (TextView)LayoutInflater.from(this.mContext).inflate(R.layout.scroll_type_item, null);
String str = typenameStrings[i];
localTextView.setText(str);
localTextView.setId(i);
localTextView.setOnClickListener(this);
this.mLayout.addView(localTextView);
}
}
public void onClick(View paramView){
this.mViewId = paramView.getId();
this.invalidate();
}
}
public class MainActivity extends Activity {
public void onCreate(Bundle paramBundle)
super.onCreate(paramBundle);
setContentView(R.layout.main);
ScrollTypeLayout mScrollTypeLayout = (ScrollTypeLayout)findViewById(R.id.type_layout);
}
}
mScrollTypeLayout = (ScrollTypeLayout)findViewById(R.id.article_type_layout);
LinearLayout mLinearLayout = (LinearLayout)mScrollTypeLayout.getChildAt(0);
for(int i = 0; i < mLinearLayout.getChildCount(); i++)
{
View child = mLinearLayout.getChildAt(i);
child.setOnClickListener(this);
}
但还是不行,LinearLayout下面已经是我想要的TextView,但是mLinearLayout.getChildCount为0