我是新的android developer.three java文件和xml文件。在我的项目中,当列表视图上显示所有收件箱消息时,但是当我选择此消息时,不显示在另一个活动的编辑框上。 下面的代码当我选择页面导航到messagebox.java到mainactivity.java但msg不显示在编辑框上
three java files--
**Mainactivity.java**
Intent intent = getIntent();
String msg = intent.getStringExtra("Msg_Detail");
TextView7 = (TextView) findViewById(R.id.TextView7);
TextView7.setText(msg);
**MessageBox.java**
lvMsg = (ListView) findViewById(R.id.lvMsg);
Uri inboxURI = Uri.parse("content://sms/inbox");
// List required columns
String[] reqCols = new String[] { "_id", "address", "body" };
// Get Content Resolver object, which will deal with Content
// Provider
ContentResolver cr = getContentResolver();
// Fetch Inbox SMS Message from Built-in Content Provider
Cursor c = cr.query(inboxURI, reqCols, null, null, null);
// Attached Cursor with adapter and display in listview
adapter = new SimpleCursorAdapter(this, R.layout.row, c,
new String[] { "body", "address" }, new int[] {
R.id.lblMsg, R.id.lblNumber });
lvMsg.setAdapter(adapter);
lvMsg.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String msg=(String) lvMsg.getSelectedItem();
Intent in = new Intent(getApplicationContext(),MainActivity.class);
in.putExtra("Msg_Detail", msg);
startActivity(in);
}
});
}
**list.java**
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.row);
txt = (TextView) findViewById(R.id.lblMsg);
txt2= (TextView) findViewById(R.id.lblNumber);
}
activity_xml messagebox.xml -all listview(listview上的消息显示)
</ListView>
**list.xml**--all message display in textview(lblmsg and lblno)
<TextView android:textAppearance="?android:attr/textAppearanceLarge"
android:text="TextView" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/lblMsg"></TextView>
<TextView android:textAppearance="?android:attr/textAppearanceMedium"
android:text="TextView" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textColor="#00f"
android:id="@+id/lblNumber"></TextView>
activity_xml-包含textview和messagebox.xml-listview以及list.xml-contains textview 在listactivity.java
的editbox上的listview显示中选择textview msg答案 0 :(得分:0)
试试这个:
String msg = intent.getExtras().getString("Msg_Detail");