Android 将EditText值从ListView传递给另一个活动
我有三项活动。在一个Android 将EditText值从ListView传递给另一个活动,android,csv,Android,Csv,我有三项活动。在一个活动中,我从CSV文件中读取数据,并使用列表视图,在编辑文本中显示数据。现在,我想将EditText的值传递给另一个活动。如何解决这个问题 代码: String dir=Environment.getExternalStorageDirectory()+“/gery/data/”+spinner.toString(); final File csvfile=新文件(dir.toString()); ListView ListView=(ListView)findViewByI
活动中
,我从CSV
文件中读取数据,并使用列表视图
,在编辑文本
中显示数据。现在,我想将EditText
的值传递给另一个活动。如何解决这个问题
代码:
String dir=Environment.getExternalStorageDirectory()+“/gery/data/”+spinner.toString();
final File csvfile=新文件(dir.toString());
ListView ListView=(ListView)findViewById(R.id.ListView);
MyList adapter=新建MyList(getApplicationContext(),R.layout.activity\u editfield);
setAdapter(适配器);
studentid=(EditText)findViewById(R.id.et_studentid);
Schoolname=(EditText)findViewById(R.id.et_Schoolname);
SchoolAddress=(EditText)findViewById(R.id.et_schooladd);
studentname=(EditText)findViewById(R.id.et_studentname);
父名=(EditText)findViewById(R.id.et_父名);
mothername=(EditText)findViewById(R.id.et_mothername);
studentaddress=(EditText)findViewById(R.id.et_studentaddress);
//Toast.makeText(Editinfo.this,studentid.getText().toString(),Toast.LENGTH_SHORT).show();
FileInputStream inputStream=null;
试一试{
inputStream=新文件inputStream(csvfile);
}catch(filenotfounde异常){
e、 printStackTrace();
}
CSVReader reader=新的CSVReader(inputStream);
最终列表myList=reader.read();
for(字符串[]数据:myList){
adapter.add(数据);
}
next.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
Intent Intent=新的Intent(getApplicationContext(),Editinfo1.class);
intent.putExtra(“微调器”,chosenOption);
intent.putExtra(“studentid”,studentid.getText().toString());
intent.putExtra(“schoolname”,schoolname.getText().toString());
intent.putExtra(“学校地址”,schooladdress.getText().toString());
intent.putExtra(“studentname”,studentname.getText().toString());
intent.putExtra(“父名”,父名.getText().toString());
intent.putExtra(“mothername”,mothername.getText().toString());
intent.putExtra(“studentaddress”,studentaddress.getText().toString());
intent.putExtra(“myList”,(可序列化的)myList);
//intent.putExtra(“mylist”,mylist);
星触觉(意向);
}
});
}
按照以下代码修改适配器:
定义新的ArrayList
:
私有列表ListItemSelected=new ArrayList()代码>
创建返回列表的方法:
private List<String> getSelectedString(){
return listItemChosen;
}
上面的代码只是处于添加状态。每次单击textview
,它都会将所选项目保存在列表中
如果您需要删除已添加的项目,则应再次添加参数,如int
parameter,首先单击它将添加项目,第二次单击同一文本视图将删除项目
我有一个参考看起来像你需要的,但使用复选框。但总的来说,逻辑还是一样的
如果遗漏了某些内容,请告诉我。按照以下代码修改适配器:
定义新的ArrayList
:
私有列表ListItemSelected=new ArrayList()代码>
创建返回列表的方法:
private List<String> getSelectedString(){
return listItemChosen;
}
上面的代码只是处于添加状态。每次单击textview
,它都会将所选项目保存在列表中
如果您需要删除已添加的项目,则应再次添加参数,如int
parameter,首先单击它将添加项目,第二次单击同一文本视图将删除项目
我有一个参考看起来像你需要的,但使用复选框。但总的来说,逻辑还是一样的
如果遗漏了什么,请告诉我您使用intent传递列表项位置和您的arraylist,在下一个活动中,您将使用received position获得该arraylist和位置,并从arraylist中获得价值。谢谢…您能否简单介绍一下如何传递项目位置请检查此链接,我将查看它。谢谢分享链接..对我有帮助..你可以使用intent传递列表项位置和你的arraylist,在下一个活动中,你可以使用received position获得该arraylist和位置,并从arraylist中获得值。谢谢…你能简单介绍一下如何传递项目位置吗?请检查此链接,我将浏览它..谢谢分享链接..其帮帮我。。
SharedPreferences sharedPreferences = context.getSharedPreferences(Constants.MODE_SHARED, Context.MODE_PRIVATE);
final SharedPreferences.Editor edit = sharedPreferences.edit();
final Gson gson = new Gson();
holder.tvItemName.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
listItemChosen.add(itemName);
String jsonString = gson.toJson(getSelectedString());
edit.putString(Constants.KEY_SHARED,jsonString);
edit.commit();
}
});