正しいコードを見つけるのに問題があります..リストビューでフィルターを使用していますが、正常に動作しますが、フィルターされたアイテムをクリックすると、間違ったアクティビティが表示されます..長い間立ち往生しています。素晴らしいでしょう..ここに私のコードがあります
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);
}
}
});
;
} }