在android中重新填充ListView
如何在android中重新填充ListView在android中重新填充ListView,android,listview,android-listview,Android,Listview,Android Listview,如何在android中重新填充ListView listview = (ListView) findViewById(R.id.listView1); listview.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Names)); final String[] TempArray = new String[Names.le
listview = (ListView) findViewById(R.id.listView1);
listview.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, Names));
final String[] TempArray = new String[Names.length];
editText = (EditText) findViewById(R.id.editText1);
editText.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
// TODO Auto-generated method
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s)
{
// TODO Auto-generated method stub
}
});
listview=(listview)findViewById(R.id.listView1);
setAdapter(新的ArrayAdapter(此,
android.R.layout.simple_list_item_1,Names));
final String[]TempArray=新字符串[Names.length];
editText=(editText)findViewById(R.id.editText1);
editText.addTextChangedListener(新的TextWatcher()
{
public void onTextChanged(字符序列,int start,int before,
整数计数)
{
//TODO自动生成方法
}
更改前的公共无效(字符序列、整数开始、整数计数、,
整数后)
{
//TODO自动生成的方法存根
}
公共无效后文本已更改(可编辑)
{
//TODO自动生成的方法存根
}
});
这是我的示例代码。我想在public voidonTextChanged(CharSequence s,int start,int count)函数上重新填充listview。在onTextChanged函数上,我想用新的字符串数组填充listview。我如何才能做到这一点?似乎您正在用“名称”值填充适配器,您可以做的是ContextChanged从“名称”中清除旧数据并添加新数据并设置适配器。首先,您需要将适配器放入一个变量中:
ArrayAdapter mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Names);
listview.setAdapter(mAdapter);
您所需要的只是放入
notifyDataSetChanged()onTextChanged
方法中的code>方法
如:
editText.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before, int count)
{
// TODO Auto-generated method
notifyDataSetChanged();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s)
{
// TODO Auto-generated method stub
}
});
希望这有帮助。。享受..您不能在任何将引发
我所做的是通过实现OnFocusChangeListener接口在RecyclerView列表中自动添加新行,该接口将在editText获得用户关注后自动添加,并且能够避免上述错误
editText.setOnFocusChangeListener(new View.OnFocusChangeListener {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus)
// ADD NEW ITEM INTO LIST
notifyDataSetChanged();
}
})
您可以使用下面的代码重新创建列表适配器:
editText.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
// TODO Auto-generated method
Names = new ArrayList<~>();
Names.add('your object');
listview.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, Names));
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s)
{
// TODO Auto-generated method stub
}
});
你说的续杯是什么意思?是过滤列表项吗?在ContextChanged函数中,我想用一个新的字符串数组填充listview。这并不复杂,您遇到了问题,您一定已经尝试了一些东西,尽管您尽了最大的努力,但还是无法使它工作。那么,您尝试了什么呢?在onTextChanged函数中,我想用一个新的字符串数组填充listview
editText.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
// TODO Auto-generated method
Names = new ArrayList<~>();
Names.add('your object');
listview.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, Names));
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s)
{
// TODO Auto-generated method stub
}
});
editText.addTextChangedListener(new TextWatcher()
{
public void onTextChanged(CharSequence s, int start, int before,
int count)
{
// TODO Auto-generated method
Names.add('your object');
listview.getAdapter().notifyDataSetChanged();
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after)
{
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s)
{
// TODO Auto-generated method stub
}
});