android list集合替换,java – ListActivity TwoLineListItem替代
简单地将TwoLineListItem源代码剪切并粘贴到您自己的布局中:android:layout_width="match_parent"android:layout_height="wrap_content"android:orientation="vertical">android:textSize="16sp"android:textStyle="bold"android:layo
简单地将TwoLineListItem源代码剪切并粘贴到您自己的布局中:
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:textSize="16sp"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
android:textSize="16sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
(注意我改变了id的一致性.)
现在使用一个ViewHolder来保持对TextViews的引用:
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder holder;
if(convertView == null){
// You should fetch the LayoutInflater once in your constructor
LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.list_item_2, null);
// Initialize ViewHolder here
}else{
holder = (ViewHolder) convertView.getTag();
}
File file = filesArrayList.get(position);
holder.text1.setText(file.getTitle());
holder.text2.setText2(file.getDescription());
return convertView;
}
更多推荐
所有评论(0)