安卓应用程序中活动的java搜索栏
我宣布
HeaderListView list;
我尝试实现搜索栏。一切正常,但此行显示错误。我没有使用列表视图我使用了列表 这是电话线
list.setTextFilterEnabled(true);
我在这里要做什么
提前谢谢
list = new HeaderListView(this);
list.setAdapter(new SectionAdapter() {
@Override
public int numberOfSections() {
return aStatesDetails.size();
}
@Override
public int numberOfRows(int section) {
return aStatesDetails.get(section).getCoursesDetails().size();
}
@Override
public Object getRowItem(int section, int row) {
return null;
}
@Override
public boolean hasSectionHeaderView(int section) {
return true;
}
@Override
public View getRowView(int section, int row, View convertView, ViewGroup parent) {
ViewHolder holder = null;
if (convertView == null ) {
//Log.i("section Details","value : "+ section + " data : " + si + " view created");
convertView = SearchGolfCourseActivity.this.getLayoutInflater().inflate(R.layout.searchcourse_adapter, null);
holder = new ViewHolder();
holder.mTextView_CourseName = (TextView) convertView.findViewById(R.id.mTextView_CourseName);
holder.mTextView_Update = (TextView) convertView.findViewById(R.id.mTextView_Update);
holder.mTextView_CourseName.setPadding(dScreenSizeWidth/50, dScreenSizeHeight/50, dScreenSizeWidth/50, dScreenSizeHeight/50);
holder.mTextView_Update.setPadding(0, dScreenSizeHeight/50, dScreenSizeWidth/50, dScreenSizeHeight/50);
/*holder.mTextView_Update.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
int getSection = (Integer) view.getTag(R.id.mTextView_CourseName);
int getPosition = (Integer) view.getTag(R.id.mTextView_Update);
Log.v("Item Clicked", getSection + " " + getPosition);
}
});*/
convertView.setTag(holder);
convertView.setTag(R.id.mTextView_CourseName, holder.mTextView_CourseName);
convertView.setTag(R.id.mTextView_Update, holder.mTextView_Update);
} else {
holder = (ViewHolder) convertView.getTag();
}
if(holder.mTextView_CourseName != null)
{
holder.mTextView_CourseName.setText(aStatesDetails.get(section).getCoursesDetails().get(row).getCourseName());
holder.mTextView_CourseName.setTag(aStatesDetails.get(section).getCoursesDetails().get(row).getCourseId());
}
if(holder.mTextView_Update != null)
if(aStatesDetails.get(section).getCoursesDetails().get(row).getDownloadStatus())
{
holder.mTextView_CourseName.setTextColor(Color.parseColor("#FF0000"));
holder.mTextView_Update.setVisibility(View.VISIBLE);
holder.mTextView_Update.setText("Update");
holder.mTextView_Update.setTag(R.id.mTextView_CourseName, section);
holder.mTextView_Update.setTag(R.id.mTextView_Update, row);
}
else
{
holder.mTextView_CourseName.setTextColor(Color.parseColor("#000000"));
holder.mTextView_Update.setVisibility(View.GONE);
}
return convertView;
}
@Override
public int getSectionHeaderViewTypeCount() {
return 2;
}
@Override
public int getSectionHeaderItemViewType(int section) {
return section % 2;
}
@Override
public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = (TextView) getLayoutInflater().inflate(getResources().getLayout(安卓.R.layout.simple_list_item_1), null);
}
((TextView) convertView).setText(aStatesDetails.get(section).getStateName());
convertView.setBackgroundColor(getResources().getColor(R.color.holo_brown_light));
return convertView;
}
@Override
public void onRowItemClick(AdapterView<?> parent, View view, final int section, final int row, long id) {
super.onRowItemClick(parent, view, section, row, id);
boolean isDownloaded = aStatesDetails.get(section).getCoursesDetails().get(row).getDownloadStatus();
AlertDialog.Builder alertDialog = new AlertDialog.Builder(SearchGolfCourseActivity.this);
// Setting Dialog Title
alertDialog.setTitle("Info");
// Setting Dialog Message
if(isDownloaded)
alertDialog.setMessage("This course has been already downloaded. Do you want to update this course?");
else
alertDialog.setMessage("Do you want to download this course?");
// Setting alert dialog icon
alertDialog.setIcon(R.drawable.tab_info_light);
// On pressing Yes button
alertDialog.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//StandardRouteFinderActivity.mapObject.redrawMap();
dialog.cancel();
String courseId = aStatesDetails.get(section).getCoursesDetails().get(row).getCourseId();
String courseName = aStatesDetails.get(section).getCoursesDetails().get(row).getCourseName();
new MyAsyncTaskDownloadCourse().execute(courseId, courseName);
}
});
// on pressing No button
alertDialog.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
// Showing Alert Message
alertDialog.show();
Toast.makeText(SearchGolfCourseActivity.this, "Section " + section + " Row " + row, Toast.LENGTH_SHORT).show();
}
});
list.setTextFilterEnabled(true);
mCourseListRelativeLayout.addView(list);
# 1 楼答案
正如在official documentation中指出的,您的适配器应该实现可过滤的接口,而不是您可以使用列表。setTextFilterEnabled(真)。你的分区适配器实现了吗?如果没有,试着去做
# 2 楼答案
使用Edittext从Listview筛选数据。 下面是我在Adapter类和过滤数据的活动中所做的:
适配器类
在我的活动中:
你需要以这个为例,根据这个来编辑你的适配器
# 3 楼答案
我正在使用通过编辑文本,希望这将帮助你