我目前有一个包含几个字符串的列表视图。这些是从 strings.xml 中的字符串数组调用的
<string name="app_name">Taxi Me</string>
<string-array name="taxi_array">
<item>Barrys Taxi</item>
<item>Boom Taxi</item>
</string-array>
我试图做的是为这些创建子项,以便我可以显示地址和联系方式等字段。我不久前做了一个customlistview,但无法弄清楚如何使用strings.xml文件来做到这一点?我需要使用任何特定标签以便它们显示在列表视图中吗?
主要活动代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String[] taxi = getResources().getStringArray(R.array.taxi_array);
final String[] address = getResources().getStringArray(R.array.taxi_add);
setListAdapter(new ArrayAdapter<String>(this, R.layout.listtaxi, taxi));
final ListView lv = getListView();
lv.setTextFilterEnabled(true);
for (int i = 0; i < taxi.length; i++) {
lv.add(new ListTaxi (taxi[i], address[i]));
}
/*lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_LONG).show();
}
});
*/
lv.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, final int position, long id)
{
final int selectedPosition = position;
AlertDialog.Builder adb=new AlertDialog.Builder(ListTaxi.this);
adb.setTitle("Taxi Booking");
adb.setMessage("You Have Selected: "+lv.getItemAtPosition(position));
adb.setPositiveButton("Book", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent(getApplicationContext(), Booking.class);
intent.putExtra("booking", taxi[selectedPosition]);
startActivity(intent);
}
});
adb.setNegativeButton("Cancel", null);
adb.show();
}
});