我很难找到正确的代码..我在列表视图上使用了一个过滤器,它工作正常,但是当我点击一个过滤的项目时,然后显示错误的活动..我已经卡了很长时间了,任何帮助会很棒..这是我的代码
public class Colour extends Activity {
// List view
private ListView lv;
// Listview Adapter
ArrayAdapter<String> adapter;
// Search EditText
EditText inputSearch;
// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list);
// Listview Data
final String products[] = {"Blue","Green","Red"};
lv = (ListView) findViewById(R.id.list);
inputSearch = (EditText) findViewById(R.id.inputSearch);
// Adding items to listview
adapter = new ArrayAdapter<String>(this,
R.layout.colour, R.id.product_name, products);
lv.setAdapter(adapter);
/**
* Enabling Search Filter
* */
inputSearch.addTextChangedListener(new TextWatcher() {
public void onTextChanged(CharSequence cs, int arg1, int arg2,
int arg3) {
// When user changed the Text
Colour.this.adapter.getFilter().filter(cs);
}
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
public void afterTextChange(Editable arg0) {
// TODO Auto-generated method stub
}
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String openClass = products[position];
if (openClass.equals("Blue")) {
Intent myIntent = new Intent(view.getContext(), Blue.class);
startActivityForResult(myIntent, 0);
}
else if (openClass.equals("Green")) {
Intent myIntent1 = new Intent(view.getContext(), Green.class);
startActivityForResult(myIntent1, 0);
}
else if (openClass.equals("Red")) {
Intent myIntent2 = new Intent(view.getContext(), Red.class);
startActivityForResult(myIntent2, 0);
}
}
});
;
} }