public class SetHelpRows {
String name;
String id;
public String getName () {
return name;
}
public void setName (String name) {
this.name = name;
}
public String getID () {
return id;
}
public void setID (String id) {
this.id = id;
}
public SetHelpRows(String name, String id) {
super();
this.name = name;
this.id = id;
}
}
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.TextView;
public class SetRowsCustomAdapter extends ArrayAdapter<SetRows> {
Context context;
int layoutResourceId;
ArrayList<SetRows> data=new ArrayList<SetRows>();
private ArrayList<SetRows> original;
private ArrayList<SetRows> fitems;
private Filter filter;
public SetRowsCustomAdapter(Context context, int layoutResourceId, ArrayList<SetRows> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
this.original = data;//new ArrayList<Pkmn>();
this.fitems = data;//new ArrayList<Pkmn>();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ImageHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ImageHolder();
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtID = (TextView)row.findViewById(R.id.txtModDate);
row.setTag(holder);
}
else
{
holder = (ImageHolder)row.getTag();
}
SetRows myImage = data.get(position);
holder.txtTitle.setText(myImage.name);
holder.txtID.setText(myImage.id);
int outImage=myImage.image;
holder.imgIcon.setImageResource(outImage);
return row;
}
static class ImageHolder
{
ImageView imgIcon;
TextView txtTitle;
TextView txtID;
}
@Override
public Filter getFilter()
{
if (filter == null) {
Log.i("Before Filter", "Before Filter");
filter = new PkmnNameFilter();
}
return filter;
}
private class PkmnNameFilter extends Filter
{
@Override
protected FilterResults performFiltering(CharSequence constraint)
{
FilterResults results = new FilterResults();
String prefix = constraint.toString().toLowerCase();
if (prefix == null || prefix.length() == 0)
{
Log.i("prefix is null or 0", "prefix is null or 0");
ArrayList<SetRows> list = new ArrayList<SetRows>(original);
results.values = list;
results.count = list.size();
}
else
{
Log.i("prefix is !null or !0", "prefix is !null or !0");
final ArrayList<SetRows> list = new ArrayList<SetRows>(original);
final ArrayList<SetRows> nlist = new ArrayList<SetRows>();
int count = list.size();
for (int i=0; i<count; i++)
{
final SetRows pkmn = list.get(i);
final String value = pkmn.getName().toLowerCase();
if (value.startsWith(prefix))
{
nlist.add(pkmn);
}
}
results.values = nlist;
results.count = nlist.size();
}
return results;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint, FilterResults results) {
Log.i("publish result", "publish result");
fitems = (ArrayList<SetRows>)results.values;
clear();
int count = fitems.size();
for (int i=0; i<count; i++)
{
SetRows pkmn = (SetRows)fitems.get(i);
add(pkmn);
}
}
}
}
我的部分mainactivity
文件:
inputSearch = (EditText) findViewById(R.id.etSearch);
dataList = (ListView) findViewById(R.id.lvFiles);
for (int y=0; y<strNames.length;y++) {
name = strNamesOfAllah[y];
meaning = strMeaning[y];
rowsArray.add(new SetRows(R.drawable.icon, name, meaning));
}
adapter = new SetRowsCustomAdapter(MainActivity.this, R.layout.customlist, rowsArray);
dataList.setAdapter(adapter);
dataList.setClickable(true);
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
//MainActivity.this.adapter.getFilter().filter(cs);
//String text = inputSearch.getText().toString().toLowerCase();
adapter.getFilter().filter(cs.toString().toLowerCase(Locale.US));
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
//TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable arg0) {
//TODO Auto-generated method stub
}
});
在logcat
中,我确实看到了以下内容:
12-12 12:15:57.077: I/Before Filter(720): Before Filter
12-12 12:15:57.106: I/prefix is !null or !0(720): prefix is !null or !0
12-12 12:15:57.216: I/publish result(720): publish result
我修改了我的代码,并且能够使它工作。如果有人想用,请便:)
SetRows Java文件:
public class SetRows {
int image;
String name;
String id;
public int getImage () {
return image;
}
public void setImage (int image) {
this.image = image;
}
public String getName () {
return name;
}
public void setName (String name) {
this.name = name;
}
public String getID () {
return id;
}
public void setID (String id) {
this.id = id;
}
public SetRows(int image, String name, String id) {
super();
this.image = image;
this.name = name;
this.id = id;
}
@Override
public String toString() {
return image + " " + name + " " + id;
}
}
SetRowsCustomAdapter Java文件:
import java.util.ArrayList;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Filter;
import android.widget.ImageView;
import android.widget.TextView;
public class SetRowsCustomAdapter extends ArrayAdapter<SetRows> {
Context context;
int layoutResourceId;
ArrayList<SetRows> data=new ArrayList<SetRows>(); //data = countryList
private ArrayList<SetRows> originalList;
private NameFilter filter;
public SetRowsCustomAdapter(Context context, int layoutResourceId, ArrayList<SetRows> data) {
super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.data = data;
//this.data.addAll(data);
this.originalList = new ArrayList<SetRows>();
this.originalList.addAll(data);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
ImageHolder holder = null;
if(row == null)
{
LayoutInflater inflater = ((Activity)context).getLayoutInflater();
row = inflater.inflate(layoutResourceId, parent, false);
holder = new ImageHolder();
holder.txtTitle = (TextView)row.findViewById(R.id.txtTitle);
holder.imgIcon = (ImageView)row.findViewById(R.id.imgIcon);
holder.txtID = (TextView)row.findViewById(R.id.txtModDate);
row.setTag(holder);
}
else
{
holder = (ImageHolder)row.getTag();
}
SetRows myImage = data.get(position);
holder.txtTitle.setText(myImage.name);
holder.txtID.setText(myImage.id);
int outImage=myImage.image;
holder.imgIcon.setImageResource(outImage);
return row;
}
static class ImageHolder
{
ImageView imgIcon;
TextView txtTitle;
TextView txtID;
}
@Override
public Filter getFilter() {
if (filter == null){
filter = new NameFilter();
}
return filter;
}
private class NameFilter extends Filter
{
@Override
protected FilterResults performFiltering(CharSequence constraint) {
constraint = constraint.toString().toLowerCase();
FilterResults result = new FilterResults();
if(constraint != null && constraint.toString().length() > 0)
{
ArrayList<SetRows> filteredItems = new ArrayList<SetRows>();
for(int i = 0, l = originalList.size(); i < l; i++)
{
SetRows nameList = originalList.get(i);
if(nameList.toString().toLowerCase().contains(constraint))
filteredItems.add(nameList);
}
result.count = filteredItems.size();
result.values = filteredItems;
}
else
{
synchronized(this)
{
result.values = originalList;
result.count = originalList.size();
}
}
return result;
}
@SuppressWarnings("unchecked")
@Override
protected void publishResults(CharSequence constraint,
FilterResults results) {
data = (ArrayList<SetRows>)results.values;
notifyDataSetChanged();
clear();
for(int i = 0, l = data.size(); i < l; i++)
add(data.get(i));
notifyDataSetInvalidated();
}
}
}
问题内容: 我想实现我的功能,但每次我输入的东西我就会消失。 我的档案: 我的档案: 我的部分MainActivity文件: 在中,LogCat我确实看到以下内容: 问题答案: 我修改了我的代码,并使其能够正常工作。如果有人想使用它,请成为我的客人 SetRows Java文件: SetRowsCustomAdapter Java文件: 其他一切都保持不变:) 我希望人们发现它对自己的应用有用。
在我的代码中,我使用了一个带有“查询文本更改”的函数,但它只受android 11的支持,这是一个简单的搜索栏。如何验证当前版本的android,并显示不同的活动?谢谢
问题内容: 我是Android的新手,我想尝试做一些非常基础的事情:Array中有5个字符串(例如’One’,’Two’…)。我想将这5个字符串添加到listactivity的列表视图中。 我的清单: 我的清单行: 基本上,我想将Array项绑定到TextView homeItemName。稍后我可能会在行中添加其他项,因此不能将listview绑定到条目。 谢谢! 问题答案: 对于代码,请快速浏
显然,过去有一种方法可以为Azure函数创建自定义计时器,方法是创建一个继承的类,并在其方法中定义自定义逻辑。 System.NotimPlementedException:Azure函数不支持属性“TimerTriggerAttribute”上的属性“ScheduleType”。 显然,这曾经是有效的,但它不是现在,我有一个很大的时间找到任何相关的信息,正确的方式是这样做的现在。有人知道设置自定
问题内容: 编辑: 是否使用不在此问题的范围内。考虑使用PDO。 需要采取什么步骤将脚本从使用不赞成使用的功能转换为? 使用代替时,是否需要采取其他不同的措施? 这是使用函数的基本脚本: 问题答案: 注意: 从转换到可能不是最佳的。如果您准备将所有代码转换为OOP,请考虑使用 PDO 。 这是很有诱惑力的尝试更换的所有实例与祈祷它的工作原理。您会很亲密,但不是很准。 连接到数据库: 幸运的是,该方
问题内容: 嗨,我想知道何时才是使用htmlspecialchars()的适当位置。是在将数据插入数据库之前还是从数据库中检索数据时? 问题答案: 仅在将数据回显为HTML时才应调用此方法。 不要将转义的HTML存储在数据库中;它只会使查询更烦人。 数据库应存储您的实际数据,而不是其HTML表示形式。