我在一项活动中创建了这个:
hiveconf
要发送到此活动:
protected void onClickSunSea(View v) {
persons = (EditText) findViewById(R.id.txtPerson);
days = (EditText) findViewById(R.id.txtDays);
String p = persons.getText().toString();
String d = days.getText().toString();
String [] array = getResources().getStringArray(R.array.sunsea);
Intent myintent = new Intent(MainActivity.this, MainActivity.class);
myintent.putExtra("PERSONS", p);
myintent.putExtra("DAYS", d);
myintent.putExtra("PLACES",array);
startActivity(myintent);
}
我在strings.xml中创建了这些数组:
String person = getIntent().getStringExtra("PERSONS");
String day = getIntent().getStringExtra("DAYS");
TextView txtPerson = (TextView) findViewById(R.id.txtViewPersons);
txtPerson.setText("Persons travelling: " + person);
TextView txtDay = (TextView) findViewById(R.id.txtViewDays);
txtDay.setText("Days of traveling: " + day);
String[] arrayCityBreak = getIntent().getStringArrayExtra("PLACES");
ArrayAdapter<String> adapterCityBreak = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayCityBreak);
ListView myview = (ListView) findViewById(R.id.lstView);
myview.setAdapter(adapterCityBreak);
我想在其中插入一个带有价格的子项目,例如: 西班牙巴塞罗那 200 然后在变量中获取“200”值并更改它,然后将其放回到数组中以使用新值+之前的一些文本将其写出来。像这样: 西班牙巴塞罗那 2人的费用是400 任何人都可以帮助我吗? 希望你理解我的问题。
答案 0 :(得分:0)
首先,您应该使用某种Map来获取此数据,这样您就可以拥有一对城市名称将成为关键,价格将是一个值。坏消息是你无法在资源中保存Map。但你可以“模仿”它,例如使用“|”作为分隔符:
<array name="citybreak">
<item>Barcelona, Spain|200</item>
<item>Berlin, Germany|300</item>
<item>Copenhagen, Denmark|250</item>
<item>Gothenburg, Sweden|500</item>
<item>Milan, Italy|700</item>
</array>
然后你可以解析这些字符串并从中创建一个Map。以this答案为例。当你有一张地图时,你可以将它传递给你的第二个活动,在那里修改价格,然后以新价格发回。