这是我的解决方案,使用点击事件并转到详细显示
public class GinActivityList extends Activity {
private ListView lv;
private EditText et;
private ArrayList<Object> array_sort = new ArrayList<Object>();
int textlength = 0;
private Object[] ginsArray;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ginsArray = (Object[]) General.GINS.values().toArray();
setContentView(R.layout.list_search);
lv = (ListView) findViewById(R.id.ListView01);
et = (EditText) findViewById(R.id.EditText01);
lv.setAdapter(new ArrayAdapter<Object>(this,
android.R.layout.simple_list_item_1, ginsArray));
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Gin ginSelected = (Gin) lv.getAdapter().getItem(position);
Intent intent = new Intent(getParent(), GinActivityDetail.class);
GinActivityGroup parentActivity = (GinActivityGroup) getParent();
Bundle bundle = new Bundle();
bundle.putSerializable("ID_GIN", ginSelected.getId());
intent.putExtras(bundle);
parentActivity.startChildActivity("GinActivityDetail", intent);
}
});
et.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
textlength = et.getText().length();
array_sort.clear();
for (int i = 0; i < ginsArray.length; i++) {
if (textlength <= ((Gin) ginsArray[i]).getName().length()) {
if (et.getText()
.toString()
.equalsIgnoreCase(
(String) ((Gin) ginsArray[i]).getName()
.subSequence(0, textlength))) {
array_sort.add((Gin) ginsArray[i]);
}
}
}
lv.setAdapter(new ArrayAdapter<Object>(GinActivityList.this,
android.R.layout.simple_list_item_1, array_sort));
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
}
}
list_search.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/EditText01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="Buscar" >
</EditText>
<ListView
android:id="@+id/ListView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:textSize="12sp" >
</ListView>