列表视图,打开新的活动的onClick [英] Listview , open new activity onClick

查看:131
本文介绍了列表视图,打开新的活动的onClick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿大家我已经看了好几个小时试图找到一个解决的办法,我的目标是有当它打开以及打开另一个活动的一个列表视图。嗯,事实上我得到了它能够打开另一个活动时,它的点击,但我怎么得到它使每一个列表项将开放其自己的活动?很抱歉,如果这个问题已经回答了,但我发现这个链接并不能真正说明什么code做[是的,我是一个新手:)]

这是使用code IM

  @覆盖
    公共无效的onCreate(包savedInstanceState){
      super.onCreate(savedInstanceState);

      的String []国家= getResources()getStringArray(R.array.countries_array)。
      setListAdapter(新ArrayAdapter<字符串>(这一点,R.layout.newfile,国家));

      ListView的LV = getListView();
      lv.setTextFilterEnabled(真正的);

      lv.setOnItemClickListener(新OnItemClickListener(){
        公共无效onItemClick(适配器视图<>母公司视图中查看,
            INT位置,长的id){
          //单击时,显示出与TextView的文字敬酒
             意图myIntent =新的意图(view.getContext(),Html_file.class);
             startActivityForResult(myIntent,0);

        }
      });
    }
}
 

解决方案

  lv.setOnItemClickListener(新OnItemClickListener(){
    公共无效onItemClick(适配器视图<>母公司视图中查看,
        INT位置,长的id){
        //单击时,显示出与TextView的文字敬酒
        如果(位置== 1){
            //具体到一个列表项code
            意图myIntent =新的意图(view.getContext(),Html_file1.class);
            startActivityForResult(myIntent,0);
        }

        如果(位置== 2){
            // $ C $具体到第二个清单项目C
            意图myIntent =新的意图(view.getContext(),Html_file2.class);
            startActivityForResult(myIntent,0);
        }
    }
});
 

Hey everyone I've looked for hours trying to find a solution to this, my goal is to have a Listview when it opens well open another activity. Well actually I got it to be able to open another activity when its click but how do I get it so that each list item will open its own activity? I am terribly sorry if this question is already answered but the links I found doesn't really describe what the code is doing [Yes i am a newbie :)]

this is the code im using

@Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      String[] countries = getResources().getStringArray(R.array.countries_array);
      setListAdapter(new ArrayAdapter<String>(this, R.layout.newfile, countries));

      ListView lv = getListView();
      lv.setTextFilterEnabled(true);

      lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view,
            int position, long id) {
          // When clicked, show a toast with the TextView text
             Intent myIntent = new Intent(view.getContext(), Html_file.class);
             startActivityForResult(myIntent, 0);

        }
      });
    }
}

解决方案

lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
        // When clicked, show a toast with the TextView text
        if(position == 1) {
            //code specific to first list item    
            Intent myIntent = new Intent(view.getContext(), Html_file1.class);
            startActivityForResult(myIntent, 0);
        }

        if(position == 2) {
            //code specific to 2nd list item    
            Intent myIntent = new Intent(view.getContext(), Html_file2.class);
            startActivityForResult(myIntent, 0);
        }
    }
});

这篇关于列表视图,打开新的活动的onClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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