我想打开对象的列表视图并单击列表行,它将打开另一个显示该行的新闻详细信息的活动。到目前为止,我可以打开一个新活动,当单击列表中的行时显示行名。但我不知道如何为每一行进行活动以显示一些不同的信息,例如地址、每行的联系信息开放时间。
这是我第一个显示列表视图的活动
// storing string resources into Array
String []Buildings_halls = getResources().getStringArray(R.array.halls);
// Binding resources Array to ListAdapter
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.hallstudent, R.id.listhall, Buildings_halls));
}
protected void onListItemClick(ListView lv, View v, int position, long id){
super.onListItemClick(lv, v, position, id);
Intent intent = new Intent();
intent.setClass(StudentHall.this, StudentHallSelect.class);
intent.putExtra("position", position);
// Or / And
intent.putExtra("id", String.valueOf(id));
intent.putExtra("description", getResources().getStringArray(R.array.hallsdescription));
startActivity(intent);
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
this is my second code package
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.selecthall);
// TODO Auto-generated method stub
Intent intent = getIntent();
int position = intent.getIntExtra("position", 0);
String halldetails=intent.getStringExtra("description");
TextView TextView1 = (TextView) findViewById(R.id.select_details);
TextView1.setText(String.valueOf(halldetails));
// Here we turn your string.xml in an array
String[] myKeys = getResources().getStringArray(R.array.halls);
TextView myTextView = (TextView) findViewById(R.id.selecthalllist);
myTextView.setText(myKeys[position]);
}
}
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/select_details"
android:padding="10dp"
android:text="@string/news_description"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
我在我的新活动中获得了列表和 Null 的名称,但没有获得我存储在 array.xml 文件中的详细信息。谢谢