列表视图中点击到的setText Android开的事情 [英] Android get thing clicked in listview to setText

查看:152
本文介绍了列表视图中点击到的setText Android开的事情的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个班,一个ListView类许多字符串和文本视图类..
我想,当我点击的列表视图的字符串第二课堂开始,并在其TextView是被向的setText单击该项目。

I have two classes, a listview class with many strings and a class with a text view .. I want when I click on a string on the listview the second class starts and the textView in it is setText to the item clicked ..

我试过:

      @Override
      protected void onListItemClick(android.widget.ListView l, View v, int position, long id) 
      {
          super.onListItemClick(l, v, position, id);
          String item = (String) getListAdapter().getItem(position);
          Intent select = new Intent(LV.this, Main.class);
          startActivity(select);
      }

和第二类的

S.setText(LV.item); 

S是TextView的

S is the textview

现在看来空。

推荐答案

您没有得到某项活动的一种方法的数据与另一个活动,除非你通过activites之间的数据。他们只是当地现有的一个活动。

You dont get data in one method of an activity in another activity, unless you pass the data between activites. They are only locally available to one activities

使用 putExtra 来从一个活动发送数据到另一个。现在,在第二个活动收到该值并将其设置为文本TextView的

Use putExtra to send data from one activity to another. Now in the second activity recieve that value and set it as text to the TextView

这里例如

在第一个活动

Intent select = new Intent(LV.this, Main.class);
select.putExtra("item", item)
startActivity(select);

在接下来的活动中,收到此

In the next activity, receive this

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("item");
}

S.setText(value); 

这篇关于列表视图中点击到的setText Android开的事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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