试图让值超出文本视图列表视图单击事件中的android [英] Trying to get value out of text view in list view click event in android

查看:224
本文介绍了试图让值超出文本视图列表视图单击事件中的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个click事件迷上了我的列表视图,如图所示。

I have a click event hooked up to my listview as shown.

int[] GenusListIDs = { R.id.txt_ID, R.id.txt_Genus, R.id.txt_Count };
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.genusitem, cursor_genuslist, service.GenusListColumns, GenusListIDs);

        ListView list_Genus = (ListView)findViewById(R.id.list_Genus);
        list_Genus.setAdapter(adapter);
        list_Genus.setOnItemClickListener(new OnItemClickListener(){
            @Override
            public void onItemClick(AdapterView parent, View view, int position, long id)
            {
                try
                {
                    Log.println(1, "ItemClick", view.toString());
                    TextView tv = (TextView)view;
                    String genus = (String) tv.getText();
                    Intent i = new Intent(getBaseContext(), Cat_Species.class);//new Intent(this, Total.class);
                    /*view
                    i.putExtra("id", id);*/
                    startActivity(i);
                }
                catch(Exception ex)
                {
                    Log.println(1, "item-click-event", ex.getMessage());
                }
            }
        });

我需要在此基础上的ListItem他们点击来传递一个字符串参数,以新的意图。我想传递的价值是在一个名为txt_Genus的列表项。我如何获得该值出列表项的传递给意图是什么?不要注意我的实验,请哈哈。

I need to pass a string param to the new intent based on which listitem they clicked on. The value I want to pass is in the listitem called txt_Genus. How do I get that value out of the listitem to pass to the intent? Don't pay attention to my experiments please haha.

推荐答案

这应该这样做。

TextView tv = (TextView)view.findViewById(R.id.txt_Genius);
String genus = tv.getText().toString();

然后把它放到意图演员,我想你已经知道这一点。

Then put it into the intent extras, I think you already know this bit.

i.putExtra("genius", genius);

Edit(编辑)

Edit;

在新的活动中,您将访问的意图,并获得额外的包。然后,您可以您放置在意向上的previous活动中包含访问什么;

In your new activity you would access the intent and get the extras bundle. You can then access anything you placed in the intent on your previous activity like below;

Bundle extras = getIntent().getExtras();
String genius = extras.getString("genius");
// pop some toast to show the value of genius - not required but shows it works :) 
Toast.makeText(this, "Genius value: " + genius, Toast.LENGTH_SHORT).show();

这篇关于试图让值超出文本视图列表视图单击事件中的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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