我试图去另一个页面使用button,但它总是失败.
这是我的第一类XML及其XML:
public class FindPeopleFragment extends Fragment {
public FindPeopleFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_home, container, false);
return rootView;
}
public void goToAttract(View v)
{
Intent intent = new Intent(getActivity().getApplication(), MainActivityList.class);
startActivity(intent);
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_marginBottom="48dp"
android:onClick="goToAttract"
android:text="Button" /></RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这是我的stacktrace ..这是我使用onclicklistener时的结果
12-30 16:54:28.006: E/AndroidRuntime(992): FATAL EXCEPTION: main
12-30 16:54:28.006: E/AndroidRuntime(992): java.lang.RuntimeException: Unable to start activity ComponentInfo{info.androidhive.slidingmenu/info.androidhive.slidingmenu.MainActivityList}: android.view.InflateException: Binary …Run Code Online (Sandbox Code Playgroud) 我正在使用Fragment,它是Fragment的一个实例,而不是DialogFragment的实例.
我做谷歌的大部分搜索结果显示了如何使用DialogFragment来拥有DatePicker.
由于Fragment和DialogFragment的类型不匹配,这在我的情况下不起作用
任何例子或想法都会有所帮助
这是片段Java代码
public class CreateReportFragment extends Fragment {
public CreateReportFragment(){}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
rootView = inflater.inflate(R.layout.activity_create_report, container, false);
initViews();
return rootView;
}
private void initViews()
{
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
editTextDate.setText(new StringBuilder()
// Month is 0 based, just add 1
.append(year)
.append("-")
.append(month + 1)
.append("-").append(day));
buttonDate = (Button)rootView.findViewById(R.id.buttonDate);
}
Run Code Online (Sandbox Code Playgroud)
如何在Fragment中实现DatePicker?
这是我的Java代码
但它不起作用我不会得到我的错误.

package info.androidhive.slidingmenu;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Fragment;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
public class CommunityFragment extends Fragment {
public CommunityFragment(){}
// Declare Variables
JSONObject jsonobject;
JSONArray jsonarray;
ListView listview;
ListViewAdapter adapter;
ProgressDialog mProgressDialog;
ArrayList<HashMap<String, String>> arraylist;
static String RANK = "rank";
static String COUNTRY = "country";
static String POPULATION = "population";
static String FLAG = "flag";
@Override
public View onCreateView(LayoutInflater …Run Code Online (Sandbox Code Playgroud) 这是侧面菜单的当前UI.

这是带有DRILL-DOWN或Expandable ListView菜单的应用程序的图像

如何为第一张图片创建相同的菜单UI?
是否有可能ListView在Fragment课堂上定制?
这是我的片段类,其中fragment_find_people只是一个空的XML:
public class FindPeopleFragment extends Fragment {
public FindPeopleFragment(){}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_find_people, container, false);
return rootView;
}
Run Code Online (Sandbox Code Playgroud)
}
现在,我已经有了一个,customListView但它只适用于Activity班级.我该怎么把它转移到Fragment?
我的listview_main xml
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/listmain" >
<ListView
android:id="@+id/listview"
android:layout_marginTop="10dp"
android:background="@drawable/bg"
android:divider="#9c9c9c"
android:dividerHeight="5dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /></RelativeLayout>
Run Code Online (Sandbox Code Playgroud)