2017-03-07 51 views
1

我是初学者。我正在开发一个包含更多活动的应用程序。我有我的MainActivity中的listView和toolBar中的searchView。现在我需要通过搜索listView并单击listView中的项目来打开其他活动。 帮助我..在可搜索列表中添加项目意图

ArrayList<String> arrayCountry = new ArrayList<>(); 
     arrayCountry.addAll(Arrays.asList(getResources().getStringArray(R.array.array_country))); 

     adapter = new ArrayAdapter<>(
       MainActivity.this, 
       android.R.layout.simple_list_item_1, 
       arrayCountry); 
     lv.setAdapter(adapter); 


     lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
       String arrayCountry = lv.getAdapter().toString(); 

      } 
     }); 

回答

0

我想这就是你一直在寻找的,

Object GetLabel = lv.getItemAtPosition(position); 
         if (GetLabel.toString().equals("label1")) { 
          Intent intent = new Intent(MainActivity.this, label1.class); 
          startActivity(intent); 
         } 
+1

谢谢..像宝石一样的作品... – Spidey

1

只要把意图在itemClickListener。

onItemClick() { 
    Intent intent = new Intent(MainActivity.this, <ACTIVITY_NAME>.class); 
    startActivity(intent); 
} 

我不知道这是你在寻找什么,因为你的描述是一种模糊的,但这将开始一个新的活动,没有任何问题。

+0

您发送将推出代码 .class文件,......但我想对于启动其他活动,在项目listView ...抱歉,我的模糊问题...你能帮我修改我的问题吗? – Spidey