我有三項活動。在一個Activity
中,我從CSV
文件讀取數據並使用ListView
,我在EditText
中顯示它。現在,我想將EditText
的值傳遞給另一個Activity
。可以做些什麼來解決這個問題?將EditText值從ListView傳遞給另一個活動
代碼:
String dir = Environment.getExternalStorageDirectory() + "/grocery/data/" + spinner.toString();
final File csvfile = new File(dir.toString());
ListView listView = (ListView) findViewById(R.id.listview);
MyList adapter = new MyList(getApplicationContext(), R.layout.activity_editfeild);
listView.setAdapter(adapter);
studentid= (EditText) findViewById(R.id.et_studentid);
Schoolname= (EditText) findViewById(R.id.et_schoolname);
schoolAdress= (EditText) findViewById(R.id.et_schooladd);
studentname=(EditText) findViewById(R.id.et_studentname);
fathername= (EditText) findViewById(R.id.et_fathername);
mothername= (EditText) findViewById(R.id.et_mothername);
studentaddress= (EditText) findViewById(R.id.et_studentadd);
//Toast.makeText(Editinfo.this, studentid.getText().toString(), Toast.LENGTH_SHORT).show();
FileInputStream inputStream = null;
try {
inputStream = new FileInputStream(csvfile);
} catch (FileNotFoundException e){
e.printStackTrace();
}
CSVReader reader = new CSVReader(inputStream);
final List<String[]> myList=reader.read();
for (String[] data : myList) {
adapter.add(data);
}
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(getApplicationContext(), Editinfo1.class);
intent.putExtra("spinner", chosenOption);
intent.putExtra("studentid", studentid.getText().toString());
intent.putExtra("schoolname", Schoolname.getText().toString());
intent.putExtra("schooladdress", schoolAdress.getText().toString());
intent.putExtra("studentname", studentname.getText().toString());
intent.putExtra("fathername", fathername.getText().toString());
intent.putExtra("mothername", mothername.getText().toString());
intent.putExtra("studentaddress", studentaddress.getText().toString());
intent.putExtra("myList", (Serializable) myList);
//intent.putExtra("mylist", myList);
startActivity(intent);
}
});
}
你傳遞一個列表項的位置和你的ArrayList的使用意圖,並在接下來的活動中,你得到的是ArrayList和位置,並使用接收的位置從ArrayList中獲得價值。 – Shailesh
謝謝...可以給你簡要的想法如何通過項目的位置 –
請檢查此http://stackoverflow.com/questions/5374546/passing-arraylist-through-intent – Shailesh