public class EastContent extends AppCompatActivity implements AdapterView.OnItemClickListener{
public static ArrayList j;
ListView listView;
String s="sonu";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.east_content);
Intent iin= getIntent();
Bundle b = iin.getExtras();
String[] array={"sonu","monu","ronu","sone"};
ArrayList<String> list=new ArrayList();
list.addAll(Arrays.asList(array));
j=b.getStringArrayList("name");
listView= (ListView) findViewById(R.id.listview);
ArrayAdapter adapter=new ArrayAdapter(this,R.layout.customtextview,R.id.textViewcustom,array);
listView.setAdapter(adapter);
listView.setOnItemClickListener(this);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
switch (position){
case 0:
Toast.makeText(getApplication(),"good hai",Toast.LENGTH_SHORT).show();
case 1:
Toast.makeText(getApplication(),"achha nahi hai",Toast.LENGTH_SHORT).show();
case 2:
Toast.makeText(getApplication(),"achha cool hai",Toast.LENGTH_SHORT).show();
case 3:
Toast.makeText(getApplication(),"sdvvgsgvrsg",Toast.LENGTH_SHORT).show();
}
}}
答案 0 :(得分:0)
您只是忘记在break
后生成case
:
switch (position){
case 0:
Toast.makeText(getApplication(),"good hai",Toast.LENGTH_SHORT).show();
break;
case 1:
Toast.makeText(getApplication(),"achha nahi hai",Toast.LENGTH_SHORT).show();
break;
case 2:
Toast.makeText(getApplication(),"achha cool hai",Toast.LENGTH_SHORT).show();
break;
case 3:
Toast.makeText(getApplication(),"sdvvgsgvrsg",Toast.LENGTH_SHORT).show();
break;
}
}}
没有break
,switch
正在浏览所有cases
。
答案 1 :(得分:0)
你需要使用&#34; break&#34;对于每个案例,通过switch语句停止掉落。
switch(position){
case 0:
Toast.makeText(getApplication(),"good hai",Toast.LENGTH_SHORT).show();
break;
......等等。