我可以使用适配器在我的主要活动中打印学校名称,如下面的代码。
我的问题是,如果我点击学校名称并想在其他学生活动中列出学生姓名,我如何列出import re
abc = re.sub(r"['\[\]]", '', abc)
的学生姓名,以及如何指定学生姓名?在学生适配器中的位置?
RealmList<Student> Students
答案 0 :(得分:1)
1 - 你应该为你的学校列表视图实现一个OnItemClick监听器:
listViewSchool.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long l)
{
// Get the School Name from School Adapter
String schoolName = ((School) adapterView.getItemAtPosition(position)).[GetSchoolName()];
// Create intent to pass data and call another Activity.
Intent intent = new Intent(activity, [YourStudentActivity].class);
// Add data to intent
intent.putExtra("schoolName", schoolName);
// Call the Student Activity
startActivity(intent);
}
});
2 - 您应该在创建学生活动时在OnCreate()中按学校名称过滤学生,并在学生列表视图中显示。要获得来自意图的价值:
// OnCreate on Student Activity
@Override
protected void onCreate(Bundle savedInstanceState)
{
...
Bundle extras = getIntent().getExtras();
if (extras != null)
{
String schoolName = extras.getString("schoolName");
}
// Then filter the students by [schoolName] and then add the result to the student array used by the student adapter and then notify the student listview.
...
}
也许它有所帮助:Getting wrong result in Android application from PHP Server
问:为什么需要在学生适配器中指定学生位置?
答案 1 :(得分:1)
you have to implement the onclick for school row and o click of that have to call another activity with putting school id as extra.
then on student you have to fetch students list on the basis of school id you send from first list. and the generate the list here.