我正在使用示例來顯示具有圖像和文本的列表視圖。列表顯示時間過長。所以我想要的是使用這個列表作爲懶惰的圖像列表,以便所有的圖像不會立即加載,但會在用戶向下滾動時加載。如何在懶列表視圖中顯示可繪製的文件夾圖像
public class SetImageText {
public int icon;
public String title;
public SetImageText()
{
super();
}
public SetImageText(int icon,String title)
{
super();
this.icon=icon;
this.title=title;
}
}
//Main Class
package com.example.customizearrayadapter;
import android.R.layout;
public class MainActivity extends Activity {
private ListView listView1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SetImageText data[]=new SetImageText[]
{
new SetImageText(R.drawable.limage,"Cloudy"),
new SetImageText(R.drawable.limage,"Showers"),
new SetImageText(R.drawable.limage,"snow"),
new SetImageText(R.drawable.limage,"Storm"),
new SetImageText(R.drawable.limage,"Sunny"),
new SetImageText(R.drawable.cow, "kriss"),
new SetImageText(R.drawable.dog,"wazid"),
new SetImageText(R.drawable.hen, "anuj"),
new SetImageText(R.drawable.horse, "abhay"),
new SetImageText(R.drawable.kbc, "abid"),
new SetImageText(R.drawable.mj ,"aman"),
new SetImageText(R.drawable.penguine ,"ali"),
new SetImageText(R.drawable.rat, "hemant"),
new SetImageText(R.drawable.pizza, "jai"),
new SetImageText(R.drawable.tortoise ,"kapil")
};
SetImageTextArrayAdapter adapter=new SetImageTextArrayAdapter(this,R.layout.listview_row_item,data);
listView1=(ListView)findViewById(R.id.listView1);
View header=(View)getLayoutInflater().inflate(R.layout.listview_header,null);
listView1.addHeaderView(header);
listView1.setAdapter(adapter);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
package com.example.customizearrayadapter;
import java.util.Set;
import android.app.Activity;
import android.content.Context;
public class SetImageTextArrayAdapter extends ArrayAdapter<SetImageText>{
Context context;
int layoutResourceId;
SetImageText data[]=null;
public SetImageTextArrayAdapter(Context context, int layoutResourceId,
SetImageText[] data) {
super(context, layoutResourceId, data);
this.layoutResourceId=layoutResourceId;
this.context=context;
this.data=data;
// TODO Auto-generated constructor stub
}
public View getView(int position,View convertView,ViewGroup parent)
{
View row = convertView;
SetImageTextHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new SetImageTextHolder();
holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
row.setTag(holder);
}
else
{
holder = (SetImageTextHolder)row.getTag();
}
SetImageText setimagetext = data[position];
holder.txtTitle.setText(setimagetext.title);
holder.imgIcon.setImageResource(setimagetext.icon);
return row;
}
static class SetImageTextHolder
{
ImageView imgIcon;
TextView txtTitle;
}
}
ü可以給我例子。我是begineer。 – kriss