只需执行以下操作...
FirstActivity(MainActivity.java)
package com.example.getlistitemvalueinnewactivity;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity implements OnItemClickListener {
String[] str={"Hello","Android","Apple","Rakesh","BlackBerry"};
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ListView lv=(ListView)findViewById(R.id.listView1);
ArrayAdapter arr =new ArrayAdapter(this,android.R.layout.simple_expandable_list_item_1,str);
lv.setAdapter(arr);
lv.setOnItemClickListener(this);
}
public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
String s= (String) ((TextView) arg1).getText();
//Toast.makeText(this, s, 100).show();
Intent intent = new Intent();
intent.setClass(this, Next.class);
Bundle bundle = new Bundle();
bundle.putString("Value", s);
intent.putExtras(bundle);
startActivity(intent);
}
}
SecondActivity(Next.java)
package com.example.getlistitemvalueinnewactivity;
import android.os.Bundle;
import android.widget.TextView;
import android.app.Activity;
public class Next extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.nextpage);
TextView tv1=(TextView)findViewById(R.id.textView1);
Bundle bundle = this.getIntent().getExtras();
String textName_value = bundle.getString("Value");
tv1.setText(textName_value);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
</ListView>
</RelativeLayout>
下一页.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="192dp"
android:text="TextView" />
</RelativeLayout>
AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.getlistitemvalueinnewactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Next"></activity>
</application>
</manifest>