我想在每一行中创建一个带有图像和文本的 ListView,动态改变他的大小(例如,在开始时,listView 什么都不显示,然后我可以向 listView 添加条目),我也希望 listView 可以加载位图图像列表,而不是可绘制的图像。
我创建了此代码,但是该代码仅从可绘制对象加载图像并创建一次(意味着我无法动态更改列表-添加或删除 listView 条目)
String[] text = { "One", "Two", "Three", "Four", "Five", "Six", "Seven",
"Eight", "Nine", "Ten" };
int[] image = { R.drawable.logo, R.drawable.logo, R.drawable.logo,
R.drawable.logo, R.drawable.logo, R.drawable.logo, R.drawable.logo,
R.drawable.logo, R.drawable.logo, R.drawable.logo };
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
lv.setAdapter(new MyCustomAdapter(text, listImages));
edittext= (EditText) findViewById(R.id.EditText01);
edittext.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable s)
{
}
public void beforeTextChanged(CharSequence s, int start,
int count, int after)
{
}
public void onTextChanged(CharSequence s, int start,
int before, int count)
{
textlength = edittext.getText().length();
text_sort.clear();
image_sort.clear();
for (int i = 0; i < text.length; i++)
{
if (textlength <= text[i].length())
{
if (edittext.getText().toString().
equalsIgnoreCase((String) text[i].subSequence(0, textlength)))
{
text_sort.add(text[i]);
// image_sort.add(image[i]);
}
}
}
lv.setAdapter(new MyCustomAdapter
(text_sort, image_sort));
}
});
}