如何从ListView控件跳转到下一个活动 [英] How to jump from ListView to next Activity

查看:116
本文介绍了如何从ListView控件跳转到下一个活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这些codeS从列表视图跳转到选定的类别

I am using these codes to jump from listview to selected class

public class mainmenu extends Activity{

私人的ListView LV1;
   私人ArrayAdapter listAdapter;
 @覆盖
   公共无效的onCreate(捆绑savedInstanceState){
     super.onCreate(savedInstanceState);
     的setContentView(R.layout.mainmenu);

private ListView lv1 ; private ArrayAdapter listAdapter ; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView (R.layout.mainmenu);

  lv1 = (ListView) findViewById(R.id.options); 

的String [] lv_arr =新的String [] {尚书一个分类广告,预约分类显示广告,图书的显示广告,页面位置可用性,管理信息系统,市场份额, 批准,上传材料,退出};
   ArrayList的选项=新的ArrayList();结果
    Options.addAll(Arrays.asList(lv_arr));
    listAdapter =新ArrayAdapter(这一点,R.layout.simplerow,选项);结果
      lv1.setAdapter(listAdapter);结果
      lv1.setTextFilterEnabled(真);
      lv1.setClickable(真);

String[] lv_arr= new String [] { "Book a Classified Ad" , "Book a Classified display Ad" , "Book a display Ad" , "Page Position Availability" , "MIS" , "Market Share" , "Approval" , "Upload Material", "Exit" }; ArrayList Options = new ArrayList();
Options.addAll(Arrays.asList(lv_arr)); listAdapter = new ArrayAdapter(this, R.layout.simplerow, Options);
lv1.setAdapter( listAdapter );
lv1.setTextFilterEnabled(true); lv1.setClickable(true);

  lv1.setOnItemClickListener(new  ListView.OnItemClickListener() {
   public void onItemClick( AdapterView<?> a, View v, int position, long id) {

    position = a.getSelectedItemPosition();
    a.setSelection(position);
    int pos1 = position;



    if (pos1 == 0) {

      Intent intent = getIntent();
     intent =  new Intent(mainmenu.this,classifiedAd.class);
     startActivity(intent);   

    }


    else  if (pos1 == 1 || pos1 == 2) {
              Intent intent1 = new Intent(mainmenu.this, displayAd.class);
              startActivity(intent1);
          } 


    else  if (pos1 == 3) {
              Intent intent3 = new Intent(mainmenu.this, spaceAvail.class);
              startActivity(intent3);
          }
    else   if (pos1 == 4) {
              Intent intent4 = new Intent(mainmenu.this, mis.class);
              startActivity(intent4);
          }
   else  if (pos1 == 5) {
              Intent intent5 = new Intent(mainmenu.this, mark.class);
              startActivity(intent5);
          }
   else   if (pos1 == 6) {
              Intent intent6 = new Intent(mainmenu.this, approval.class);
              startActivity(intent6);
          }
   else   if (pos1 == 7) {
              Intent intent7 = new Intent(mainmenu.this, uploadMat.class);
              startActivity(intent7);
          }
   else if (pos1 == 8) {
             finish();
         }
  }

   });


  }

}

问题出在哪里?

推荐答案

而不是位置我得标签

Object GetLabel = lv1.getItemAtPosition(position);
if (GetLabel.toString().equals("Book a Classified Ad")) {

                     Intent intent = new Intent(mainmenu.this, classifiedAd.class);
                     startActivity(intent);                  
                    }

这篇关于如何从ListView控件跳转到下一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆