我从 xml 文件中获取 listview 的值。这些是我的 java 和 xml 代码:
package com.gazi.tezproje;
import android.app.ActionBar;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.Toast;
public class verbs extends Activity {
public boolean onCreateOptionsMenu(Menu menu) {
ActionBar bar=getActionBar();
bar.setDisplayHomeAsUpEnabled(true);
MenuInflater menu1 = getMenuInflater();
menu1.inflate(R.menu.info, menu);
return super.onCreateOptionsMenu(menu);
}
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menuinfo:
Toast.makeText(getApplicationContext(),getString(R.string.verbs), Toast.LENGTH_LONG).show();
break;
case android.R.id.home:
finish();
break; }
return false;
}
private ListView vlist;
EditText ara;
private String [] fiilliste;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.verbs);
fiilliste=getResources().getStringArray(R.array.fiiller);
vlist=(ListView)findViewById(R.id.listView1);
adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, fiilliste);
vlist.setAdapter(adapter);
ara = (EditText) findViewById(R.id.editText1);
vlist.setTextFilterEnabled(true);
vlist.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> a,View v,int position,long id){
}
});
ara.addTextChangedListener(new TextWatcher(){
public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
// When user changed the Text
verbs.this.adapter.getFilter().filter(cs);
}
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
}}
XML 文件
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="fiiller">
<item>A</item>
<item>Affetmek</item>
<item>Almak</item>
<item>Anlamak</item>
<item>Anlaşmak</item>
<item>Anlatmak</item>
<item>Ayrılmak</item>
<item>B</item>
<item>Bakmak</item>
<item>Başlamak</item>
</string-array>
</resources>
例如; 当我单击“Bakmak”的列表视图时,我想显示带有吐司的文本,即使列表视图被过滤。而对于列表视图的其他项目,另一个祝酒词。我做不到,因为如您所知,在过滤后,项目的位置会发生变化。
我真的需要你的想法和帮助!谢谢!