在android中获取listview中的项目

在android中获取listview中的项目,android,Android,我正在开发一个应用程序,其中列表视图中的每一行都有五个文本视图(t1..t5)和其中的值。我有二十行,每行在文本视图中有不同的值。现在,当我点击一个项目(在一行上)时,另一个页面打开,有五个文本视图。我的问题是,如何将每行文本视图的值获取到我导航到的页面,并将这些值放入文本视图中。根据我单击的位置,值也应该相应地变化 你能帮我理解一下这个概念吗。试试这个 listView.setOnItemClickListener(new OnItemClickListener() { @Overri

我正在开发一个应用程序,其中列表视图中的每一行都有五个文本视图(t1..t5)和其中的值。我有二十行,每行在文本视图中有不同的值。现在,当我点击一个项目(在一行上)时,另一个页面打开,有五个文本视图。我的问题是,如何将每行文本视图的值获取到我导航到的页面,并将这些值放入文本视图中。根据我单击的位置,值也应该相应地变化

你能帮我理解一下这个概念吗。

试试这个

listView.setOnItemClickListener(new OnItemClickListener() {
    @Override
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {


       String str = ((TextView) view.findViewById(R.id.someid)).getText().toString();

       //Now pass this to intent
       Intent intent = new Intent(getApplicationContext(),
                SomeActivity.class);
        intent.putExtra("string", str);
        startActivity(intent);

    }
  });
listView.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
String str=((TextView)view.findViewById(R.id.someid)).getText().toString();
//现在将此传递给intent
意向意向=新意向(getApplicationContext(),
(活动、班级);
intent.putExtra(“字符串”,str);
星触觉(意向);
}
});

尝试使用McClickListener

contests_listView.setOnItemClickListener(new android.widget.AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,int position, long id) {
//Here you can write code
            }
        });
竞争\u listView.setOnItemClickListener(新的android.widget.AdapterView.OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父对象、视图、整型位置、长id){
//您可以在这里编写代码
}
});

列表视图中获取项目
并将其发送到
意图中

listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                TextView txt1 = (TextView) view.findViewById(R.id.txt1);
                TextView txt2 = (TextView) view.findViewById(R.id.txt2);
                TextView txt3 = (TextView) view.findViewById(R.id.txt3);
                TextView txt4 = (TextView) view.findViewById(R.id.txt4);
                TextView txt5 = (TextView) view.findViewById(R.id.txt5);

                String strTxt1 = txt1.getText().toString();
                String strTxt2 = txt2.getText().toString();
                String strTxt3 = txt3.getText().toString();
                String strTxt4 = txt4.getText().toString();
                String strTxt5 = txt5.getText().toString();

            }
        });
listView.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
TextView txt1=(TextView)view.findViewById(R.id.txt1);
TextView txt2=(TextView)view.findViewById(R.id.txt2);
TextView txt3=(TextView)view.findViewById(R.id.txt3);
TextView txt4=(TextView)view.findViewById(R.id.txt4);
TextView txt5=(TextView)view.findViewById(R.id.txt5);
字符串strTxt1=txt1.getText().toString();
字符串strTxt2=txt2.getText().toString();
字符串strTxt3=txt3.getText().toString();
字符串strTxt4=txt4.getText().toString();
字符串strTxt5=txt5.getText().toString();
}
});
将strTxt1、strTxt2、strTxt3、strTxt4和strTxt5添加到MainActivity的onCreate()方法中

listView.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {
                TextView txt1 = (TextView) view.findViewById(R.id.txt1);
                TextView txt2 = (TextView) view.findViewById(R.id.txt2);
                TextView txt3 = (TextView) view.findViewById(R.id.txt3);
                TextView txt4 = (TextView) view.findViewById(R.id.txt4);
                TextView txt5 = (TextView) view.findViewById(R.id.txt5);

                String strTxt1 = txt1.getText().toString();
                String strTxt2 = txt2.getText().toString();
                String strTxt3 = txt3.getText().toString();
                String strTxt4 = txt4.getText().toString();
                String strTxt5 = txt5.getText().toString();

            }
        });
ListView listView = (ListView)findViewById(R.id.listView);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
    int position, long id) {


   String str1 = ((TextView) view.findViewById(R.id.txt1)).getText().toString();
String str2 = ((TextView) view.findViewById(R.id.txt2)).getText().toString();
String str3 = ((TextView) view.findViewById(R.id.txt3)).getText().toString();
String str4 = ((TextView) view.findViewById(R.id.txt4)).getText().toString();
String str5 = ((TextView) view.findViewById(R.id.txt5)).getText().toString();

   //Start a new intent and pass all these string values to your new Activity
   Intent intent = new Intent(getApplicationContext(),
            NewActivity.class);
    intent.putExtra("t1", str1);
    intent.putExtra("t2", str2);
    intent.putExtra("t3", str3);
    intent.putExtra("t4", str4);
    intent.putExtra("t5", str5);
    startActivity(intent);

}
});

再次非常感谢……)