我有两个活动,即朋友和详细信息,朋友活动是一个列表视图,列表数据从我已经创建的数据库中填充,当单击列表项时,应启动详细信息活动并将列表项数据传送到详细信息活动并放入详细信息类中的编辑文本框中
package com.rich.myfinal;
public class FriendsActivity extends Activity {
private CustomCursorAdapter customAdapter;
private PersonDataHelper databaseHelper;
private ListView listView;
private static final String TAG = FriendsActivity.class.getSimpleName();
/**
* Called when the activity is first created.
*/
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_friends);
databaseHelper = new PersonDataHelper(this);
listView = (ListView) findViewById(R.id.list_data);
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.d(TAG, "clicked on item: " + position);
Intent i = new Intent(getApplicationContext(), DetailsActivity.class);
startActivity(i);
}
});
// Database query can be a time consuming task ..
// so its safe to call database query in another thread
// Handler, will handle this stuff for you <img src="http://s0.wp.com/wp-includes/images/smilies/icon_smile.gif?m=1129645325g" alt=":)" class="wp-smiley">
new Handler().post(new Runnable() {
@Override
public void run() {
customAdapter = new CustomCursorAdapter(FriendsActivity.this, databaseHelper.getAllData());
listView.setAdapter(customAdapter);
}
});
}
}
活动详情如下
package com.rich.myfinal;
public class DetailsActivity extends Activity {
EditText details;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_details);
details = (EditText) findViewById (R.id.details);
}
}