简单地将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;

}

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐