过滤后的ListView定位

时间:2013-11-18 16:02:58

标签: java android listview

我已经搜索但我不理解答案,我有一个ListView,过滤器可以工作但是当它过滤结果时,初始位置是它带来的,打开一个不需要的活动。这是我的代码

public class IndexPageActivity extends Activity implements OnItemClickListener {
ListView listView;
EditText editTextB;
ArrayAdapter<String> adapter1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.indexpage);
    listView = (ListView) findViewById(R.id.pageList);
    editTextB = (EditText) findViewById(R.id.searchB);
    String[] pages = getResources().getStringArray(R.array.page_data);
    // Row layout defined by Android: android.R.layout.simple_list_item_1
    adapter1 = (new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_1, pages));
    listView.setAdapter(adapter1);
    adapter1.notifyDataSetChanged();
    listView.setOnItemClickListener(this);

    editTextB.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2,
                int arg3) {
            // When user changed the Text
            IndexPageActivity.this.adapter1.getFilter().filter(cs);
            adapter1.notifyDataSetChanged();
        }

        @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
        }
    });
}

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
    // TODO Auto-generated method stub
    if (index == 0) {
        Intent i = new Intent(this, WebViewActivity.class);
        i.putExtra("keyHTML", "file:///android_asset/page1.html");
        startActivity(i);
    } else if (index == 1) {
        Intent i = new Intent(this, WebViewActivity.class);
        i.putExtra("keyHTML", "file:///android_asset/page2.html");
        startActivity(i);

当过滤器工作时,如何使过正确的字符串/项目使用过滤器?

由于

0 个答案:

没有答案