请帮助我,如何按开关盒点击数组或如何使这个开关盒变成如果?因为我有一个搜索栏,并且在搜索时,出来的项目不符合数组。例如,当我单击es cendol的项目/数组时,显示的类是EsBerasKencur_ResepMinum.class,而不是EsCendol_ResepMinum.class。但是吐司展示了es cendol项目。请帮帮我。
public class Dingin_Tab extends Activity implements
OnItemClickListener {
public static final String[] titles = new String[] { "Es Beras Kencur", "Dawet Ayu",
"Es Cendol", "Es Doger", "Es Oyen", "Es Teler", "Es Temulawak",
"Es Selendang Mayang", "Es Cincau", "Es Merah Delima"};
public static final Integer[] images = {R.drawable.minumberaskencur,
R.drawable.minumdawetayu, R.drawable.minumescendol,
R.drawable.minumesdoger, R.drawable.minumesoyen, R.drawable.minumesteler, R.drawable.minumestemulawak,
R.drawable.minumesselendangmayang, R.drawable.minumescincau, R.drawable.minumesmerahdelima};
ListView listView;
List<RowItem> rowItems;
EditText editsearch;
ListView list;
CustomListViewAdapter madapter;
ArrayList<RowItem> arraylist = new ArrayList<RowItem>();
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listviewresma);
rowItems = new ArrayList<RowItem>();
for (int i = 0; i < titles.length; i++) {
RowItem item = new RowItem(images[i], titles[i], null);
rowItems.add(item);
}
listView = (ListView) findViewById(R.id.list);
CustomListViewAdapter adapter = new CustomListViewAdapter(this,
R.layout.list_item, rowItems);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
madapter = new CustomListViewAdapter(this, 0, rowItems);
// Binds the Adapter to the ListView
listView.setAdapter(madapter);
// Locate the EditText in listview_main.xml
editsearch = (EditText) findViewById(R.id.search);
// Capture Text in EditText
editsearch.addTextChangedListener(new TextWatcher() {
@Override
public void afterTextChanged(Editable arg0) {
// TODO Auto-generated method stub
String text = editsearch.getText().toString().toLowerCase(Locale.getDefault());
madapter.filter(text);
}
@Override
public void beforeTextChanged(CharSequence arg0, int arg1,
int arg2, int arg3) {
// TODO Auto-generated method stub
}
@Override
public void onTextChanged(CharSequence arg0, int arg1, int arg2,
int arg3) {
// TODO Auto-generated method stub
}
});
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
switch (position)
{
case 0: Intent newActivity0 = new Intent(this, EsBerasKencur_ResepMinum.class);
startActivity(newActivity0);
break;
case 1: Intent newActivity1 = new Intent(this, DawetAyu_ResepMinum.class);
startActivity(newActivity1);
break;
case 2: Intent newActivity2 = new Intent(this, EsCendol_ResepMinum.class);
startActivity(newActivity2);
break;
case 3: Intent newActivity3 = new Intent(this, EsDoger_ResepMinum.class);
startActivity(newActivity3);
break;
case 4: Intent newActivity4 = new Intent(this, EsOyen_ResepMinum.class);
startActivity(newActivity4);
break;
case 5: Intent newActivity5 = new Intent(this, EsTeler_ResepMinum.class);
startActivity(newActivity5);
break;
case 6: Intent newActivity6 = new Intent(this, Temulawak_ResepMinum.class);
startActivity(newActivity6);
break;
case 7: Intent newActivity7 = new Intent(this, EsSelendangmayang_ResepMinum.class);
startActivity(newActivity7);
break;
case 8: Intent newActivity8 = new Intent(this, EsCincau_ResepMinum.class);
startActivity(newActivity8);
break;
case 9: Intent newActivity9 = new Intent(this, EsMerahDelima_ResepMinum.class);
startActivity(newActivity9);
break;
}
Toast toast = Toast.makeText(getApplicationContext(),
"Resep Minuman Dingin " + (position + 1) + ": " + rowItems.get(position),
Toast.LENGTH_SHORT);
toast.setGravity(Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
答案 0 :(得分:0)
您的已过滤列表与rowItems
不同,因此请检查您点击的项目以及您在吐司中显示的项目。请参阅此example
答案 1 :(得分:0)
您不需要使用这样的开关盒。有多种方法可以达到您所需的结果。 一个是您可以将自定义适配器中的筛选列表设置为公共,并可以通过onItemClick()的ists位置获取它。(filteredList.get(position)) 否则,您可以将类objectc作为标记添加到列表适配器中,并将其作为(view.getTag())传入onItemClick()。
希望这有帮助。