【发布时间】:2016-10-03 22:28:57
【问题描述】:
我自己也在学习 DialogFragments。除了从按钮传递意图之外,我从未尝试过任何其他方法,所以我没有找到正确的方向。
我想学习所有可能的方法。
与使用 ListFragment 创建列表有什么不同吗?
主 Activity 上有 2 个按钮。单击第二个按钮时,它应该会打开一个包含项目列表的 DialogFragment,单击列表项应该会在浏览器中打开一个 URL。
主要活动
btnDepartment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Intent intent = new Intent(MainActivity.this, DepartmentActivity.class);
//startActivity(intent);
}
});
这里是Department Class,是一个纯Java类
public class Department {
private String deptName, deptUrl;
public static final Department[] myDepartment = {
new Department("CS", "http://cs.com"),
new Department("Biology", "http://bio.com"),
new Department("Chemistry", "http://www.chemistry.com"),
new Department("Nursing", "http://nursing.com")
};
private Department(String deptName, String deptUrl){
this.deptName = deptName;
this.deptUrl = deptUrl;
}
public String getDeptName() {
return deptName;
}
public String getDeptUrl() {
return deptUrl;
}
@Override
public String toString() {
return deptName;
}
}
部门片段
public class DepartmentFragment extends DialogFragment {
public DepartmentFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_department, container, false);
}
}
【问题讨论】:
标签: android listview android-fragments android-dialogfragment