Java 原始文件夹中有多个txt文件|如何在listview中单击项目获取txt

Java 原始文件夹中有多个txt文件|如何在listview中单击项目获取txt,java,android,textview,android-resources,Java,Android,Textview,Android Resources,我在res/raw文件夹中有多个文本文件。我想从listview中获取有关项目单击的特定文本文件 b.java(保存列表数组和rawid的活动) 当我单击列表位置0或位置1,位于位置rawid[0]的R.raw.addamtopm打开时,我想根据在列表视图中单击项的位置获取txt文件 b.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android

我在res/raw文件夹中有多个文本文件。我想从listview中获取有关项目单击的特定文本文件

b.java(保存列表数组和rawid的活动)

当我单击列表位置
0
或位置
1
,位于位置
rawid[0]
R.raw.addamtopm
打开时,我想根据在列表视图中单击项的位置获取txt文件

b.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
 >

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listView1"
    />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ScrollView android:layout_height="match_parent" android:layout_width="match_parent">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:id="@+id/textView2"
    android:textIsSelectable="true"
    />
</ScrollView>
</RelativeLayout>

b1.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
 >

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listView1"
    />
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ScrollView android:layout_height="match_parent" android:layout_width="match_parent">
<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:id="@+id/textView2"
    android:textIsSelectable="true"
    />
</ScrollView>
</RelativeLayout>


我在这里被绊倒了,请帮帮我。

您必须将位置值从第一类(b.java)传递到第二类(b1.java)

`

`

然后为每个位置写入if条件

if(position==0){
     textView.setText(readTextFile(b1.this,R.raw.addamtopm);
  }

为什么你有3个原始文件,而你的列表有4个项目。Rahul我实际上已经丢失了原始文件,包括列表项目…为了简单起见,我只是在这里发布了一点。感谢shekhar兄弟…感谢你的帮助,它起了作用。我已经尝试过了,但最后弹出了一些thanx供你反馈
And just get value in b.java oncreate


Bundle extras = getIntent().getExtras(); 
        int position;
      if (extras != null) {
        position= extras.getint("pos");
        // and get whatever type user account id is
       }
if(position==0){
     textView.setText(readTextFile(b1.this,R.raw.addamtopm);
  }