2
我正在使用SimpleCursorAdapter
將SQLite
數據庫中的數據提取到ListView
。現在我試圖打開一個Activity
,其中將包含ListView
的文本。我已經編寫了代碼,但無論我點擊什麼,它都只顯示第一個項目的文本。下面的代碼給出:如何將文本從ListView項目傳遞到新活動
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
textView = (TextView) findViewById(R.id.tvListItem);
String text = textView.getText().toString();
Intent intent = new Intent(getApplicationContext(), SingleActivity.class);
intent.putExtra("com.example.practise.write", text);
startActivity(intent);
}
});
守則SingleACtivity
類:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_single);
textTextView = (TextView) findViewById(R.id.tvWrite);
Intent intent = getIntent();
String write = intent.getStringExtra("com.example.practise.write");
textTextView.setText(write);
}
listview中有多少個文本框,你能顯示你的listview的屏幕截圖以及你想傳遞給nextactivity的內容嗎? –
如何更改爲'textView =(TextView)view.findViewById(R.id.tvListItem);'? – Abbas
textView是動態的,我的意思是從數據庫添加項目@Daryl –