Android Parse.com:如何在片段内部为Parse ListView添加搜索过滤器
我正在尝试为选项卡片段中的ListView添加搜索过滤器。使用和适配器从解析服务器调用数据 下面是我的片段java文件 SportsCar.javaAndroid Parse.com:如何在片段内部为Parse ListView添加搜索过滤器,android,android-fragments,parse-platform,android-search,android-filter,Android,Android Fragments,Parse Platform,Android Search,Android Filter,我正在尝试为选项卡片段中的ListView添加搜索过滤器。使用和适配器从解析服务器调用数据 下面是我的片段java文件 SportsCar.java import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.LayoutInflater; import android.view.View;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import com.parse.FindCallback;
import com.parse.ParseException;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import java.util.ArrayList;
import java.util.List;
public class SportsCar extends android.support.v4.app.ListFragment
implements FindCallback<ParseObject> {
private List<ParseObject> mCar = new ArrayList<ParseObject>();
ArrayAdapter<String> adapter;
EditText inputSearch;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.activity_main, container, false);
}
@Override
public void onViewCreated(View view, Bundle b) {
super.onViewCreated(view, b);
CarAdapter adaptor = new CarAdapter(getActivity(), mCar);
setListAdapter(adaptor);
ParseQuery.getQuery("oldcar").findInBackground(this);
}
@Override
public void done (List < ParseObject > scoreList, ParseException e){
if (e == null) {
Log.d("score", "Retrieved " + scoreList.size() + " oldcar");
mCar.clear();
mCar.addAll(scoreList);
((CarAdapter) getListAdapter()).notifyDataSetChanged();
} else {
Log.d("score", "Error: " + e.getMessage());
}
inputSearch.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
SportsCar.this.adapter.getFilter().filter(cs);
}
@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
}
});
}
}
导入android.os.Bundle;
导入android.text.Editable;
导入android.text.TextWatcher;
导入android.util.Log;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.ArrayAdapter;
导入android.widget.EditText;
导入com.parse.FindCallback;
导入com.parse.ParseException;
导入com.parse.ParseObject;
导入com.parse.ParseQuery;
导入java.util.ArrayList;
导入java.util.List;
公共级跑车扩展了android.support.v4.app.ListFragment
实现FindCallback{
private List mCar=new ArrayList();
阵列适配器;
编辑文本输入搜索;
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
返回充气机。充气(R.layout.activity_main,容器,假);
}
@凌驾
已创建公用void onview(视图,捆绑包b){
super.onViewCreated(视图,b);
CarAdapter适配器=新的CarAdapter(getActivity(),mCar);
setListAdapter(适配器);
getQuery(“oldcar”).findInBackground(this);
}
@凌驾
公共作废完成(列表scoreList,parsee异常){
如果(e==null){
Log.d(“score”,“Retrieved”+scoreList.size()+oldcar”);
mCar.clear();
mCar.addAll(记分表);
((CarAdapter)getListAdapter()).notifyDataSetChanged();
}否则{
Log.d(“分数”,“错误:+e.getMessage());
}
inputSearch.addTextChangedListener(新的TextWatcher(){
@凌驾
public void onTextChanged(字符序列cs、int arg1、int arg2、int arg3){
//当用户更改文本时
SportsCar.this.adapter.getFilter().filter(cs);
}
@凌驾
更改前的公共void(字符序列arg0、int arg1、int arg2、,
int arg3){
//TODO自动生成的方法存根
}
@凌驾
public void PostTextChanged(可编辑arg0){
//TODO自动生成的方法存根
}
});
}
}
这是xml文件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp">
<TextView android:id="@id/android:empty"
android:layout_width="match_parent"
android:layout_height="335dp"
android:text="No data"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="56dp"
android:layout_toLeftOf="@+id/android:list"
android:layout_toStartOf="@+id/android:list" />
<ListView android:id="@id/android:list"
android:layout_width="263dp"
android:layout_height="241dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="@+id/searchUserTextField" />
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/android:empty"
android:id="@+id/searchUserTextField"
android:background="@android:color/holo_red_dark"
android:textColor="@android:color/white"
android:layout_toRightOf="@+id/android:empty"
android:layout_marginTop="105dp"
android:textAllCaps="true"
android:textAlignment="center"
android:paddingTop="5dp"
android:textSize="14sp"
tools:text="Search by Name or Company" />
</RelativeLayout>
如何调用主要活动的片段?