总之,我的目标是当我点击" akim表演"没有和有搜索界面,它应该给我吐司(这真的很好)!谢谢。帮帮我们
public class MainActivity extends AppCompatActivity{
private EditText editText;
private ArrayAdapter<String> listAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.event6icon);
editText = (EditText)findViewById(R.id.editCourseText);
ListView itemList = (ListView)findViewById(R.id.CoursesListView);
String [] listViewAdapterContent = {
"rita performance",
"ashely performance",
"jenifer performance",
"akim performance",
"john performance",
};
listAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_2, android.R.id.text1, listViewAdapterContent);
itemList.setAdapter(listAdapter);
itemList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String sMessage = "";
switch(position) {
case 0: sMessage = "This is exactly what should be done "; break;
case 1: sMessage = "You are completely wrong! "; break;
case 2: sMessage = "This is good "; break;
case 3: sMessage = "This is really good "; break;
case 4: sMessage = "This is perfect "; break;
}
Toast.makeText(getApplicationContext(), sMessage+position, Toast.LENGTH_LONG).show();
}
});
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence c, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence c, int start, int before, int count) {
MainActivity.this.listAdapter.getFilter().filter(c);
}
@Override
public void afterTextChanged(Editable c) {
}
});
}
}
答案 0 :(得分:0)
您可以在代码中使用简单的随机选择器逻辑;
itemList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (Math.random() > 0.5) {
Toast.makeText(getApplicationContext(), "This is exactly what should be done "+position, Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getApplicationContext(), "You are completely wrong! "+position, Toast.LENGTH_LONG).show();
}
}
});