我已经创建了一个列表视图,现在想要从listview项目中打开第二个活动,并打开从assest文件夹到第二个活动的文本文件,我该怎么做?请帮我正确的代码.. < / p>
1)这是我列表视图的java代码
package com.example.dell.cap;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import java.io.IOException;
import java.io.InputStream;
public class basicc extends AppCompatActivity {
ListView listView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_basicc);
listView=(ListView) findViewById(R.id.list1);
ArrayAdapter<String> mAdapter =new ArrayAdapter<String>(basicc.this,android.R.layout.simple_list_item_1,getResources().getStringArray(R.array.basics));
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(basicc.this,Displaytext.class);
startActivity(intent);
}
});
listView.setAdapter(mAdapter);
}
}
2)这是列表视图项
<resources>
<string name="app_name">CAP</string>
<string name="sets_string"><![CDATA[Sets & String]]></string>
<string-array name="basics">
<item>Accessing an array using pointers.c</item>
<item>C program for Binary to decimal conversion.c</item>
<item>C program for decimal to octal converter.c</item>
<item>C program for hexadecimal to binary conversion.c</item>
<item>C program to accept an array of 10 elements and swap 3rd element
with 4th element using pointers and display the results..c</item>
<item>C program to accept N numbers sorted in ascending order and to
search for a given number using binary search..c</item>
<item>C Program to Accept the Height of a Person & Categorize as
Taller, Dwarf & Average.c</item>
<item>C Program to Accept two Integers and Check if they are
Equal.c</item>
<item>C Program to Add two Complex Numbers.c</item>v
<item>C Program to Calculate the Sum of Odd & Even Numbers.c</item>
<item>C Program to calculate the total execution time of a
program.c</item>
<item>C Program to Check if a given Integer is Odd or Even.c</item>
</string-array>
</resources>
this is the 2nd activity on which i want to display the text from assets
答案 0 :(得分:0)
使用onItemClickListener。 像这样
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(basicc.this,Displaytext.class);
startActivity(intent);
}
});