如何使用textview显示从列表视图中选择的项目的值 [英] How to display the value of an item selected from a list view using textview

查看:74
本文介绍了如何使用textview显示从列表视图中选择的项目的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用simplesursoradapter我已经提出了一个listview。我从listview中选择一个项目,并将其保存在变量'titlename'中,并能够在Toast中显示。现在,我希望将'titlename'中的这个值传递给文本视图id'textView3',以便它可以显示在同一活动的屏幕顶部。当我尝试使用以下代码时,我在行 textView.setText(query.toString())中得到一个NULL指针异常;





a)TextView ID'textView'和'textView2'在custom_row.xml中



b)TextView ID'textView3'在Activity_Out.xml中





 静态  String  v_titlename; 

public void onItemClick(AdapterView TextView selectedTitle =(TextView)view.findViewById (R.id.textView);
TextView titlename =(TextView)view.findViewById(R.id.textView2);
TextView textView =(TextView)findViewById(R.id.textView3);
v_titlename = titlename.getText()。toString();
String query = titlename.getText()。toString();
textView .setText(query.toString());
Toast.makeText( this ,titlename.getText(),Toast.LENGTH_LONG)。show();
inputID = selectedTitle.getText()。toString(); // 此标题的_id存储在inputID中
}

解决方案

你的代码没有意义。检查出来:

1. Android ListView示例 [ ^ ]

2. 使用两个布局xml一个活动的文件 [ ^

Using simplesursoradapter I have raised a listview. I select an item from listview and keep it in a variable 'titlename' and able to show in Toast. Now, I want this value in 'titlename' to be passed to a text view id 'textView3' so that it could be displayed on top of the screen in the same activity. When I tried with the following code I get a NULL pointer exception at line textView.setText(query.toString());


a)TextView ID 'textView' and 'textView2' are in custom_row.xml

b)TextView ID 'textView3' is in Activity_Out.xml


static String v_titlename;

public void onItemClick(AdapterView        TextView selectedTitle = (TextView)view.findViewById(R.id.textView);
        TextView titlename= (TextView)view.findViewById(R.id.textView2);
        TextView textView = (TextView) findViewById(R.id.textView3);
        v_titlename=titlename.getText().toString();
        String query = titlename.getText().toString();
        textView.setText(query.toString());
        Toast.makeText(this, titlename.getText() , Toast.LENGTH_LONG).show();
        inputID=selectedTitle.getText().toString(); // the _id of this title is stored in inputID
    }

解决方案

You code does not make sense. Check these out:
1. Android ListView Example[^]
2. Using two layout xml file for one Activity[^]


这篇关于如何使用textview显示从列表视图中选择的项目的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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