gpt4 book ai didi

android - Switch语句Android

转载 作者:太空宇宙 更新时间:2023-11-03 11:57:48 26 4
gpt4 key购买 nike

我的 switch 语句有问题。当我尝试从列表中选择一个项目时,它会自动执行 switch 语句的最后一个案例。这是我的代码:

CustomAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Holder holder=new Holder();
View rowView;
rowView = inflater.inflate(R.layout.list_field, null);
holder.tv2=(TextView) rowView.findViewById(R.id.textView2);
holder.tv=(TextView) rowView.findViewById(R.id.titleView);
holder.img=(ImageView) rowView.findViewById(R.id.imageView1);

holder.tv2.setText(description[position]);
holder.tv.setText(result[position]);
holder.img.setImageResource(imageId[position]);

rowView.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

Intent intent = new Intent(context, Lesson.class);

switch(position){
case 0: intent.putExtra("Title", l1);
case 1: intent.putExtra("Title", l2);
case 2: intent.putExtra("Title", l3);
case 3: intent.putExtra("Title", l4);
case 4: intent.putExtra("Title", l5);
case 5: intent.putExtra("Title", l6);
case 6: intent.putExtra("Title", l7);
case 7: intent.putExtra("Title", l8);
case 8: intent.putExtra("Title", l9);
case 9: intent.putExtra("Title", l10);

context.startActivity(intent);
}
}
});

最佳答案

你应该休息

     switch(position){                                                     
case 0: intent.putExtra("Title", l1); break;
case 1: intent.putExtra("Title", l2); break;
case 2: intent.putExtra("Title", l3); break;
case 3: intent.putExtra("Title", l4); break;
case 4: intent.putExtra("Title", l5); break;
case 5: intent.putExtra("Title", l6); break;
case 6: intent.putExtra("Title", l7); break;
case 7: intent.putExtra("Title", l8); break;
case 8: intent.putExtra("Title", l9); break;
case 9: intent.putExtra("Title", l10); break;
default:
Log.e("", "no case");
return;
}
context.startActivity(intent);

关于android - Switch语句Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22372639/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com