我有一个活动,它从列表中输出json数据.但现在我想在一个片段中实现它.在这个片段中,我想将其视为gridview.这两个文件都运行正常.但是当我尝试实现AsyncTask时,我得到几个redflags作为无法访问的代码.请有人帮我这个吗?
编辑:新的
public class SalesFragment extends Fragment {
GridView gridView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View gv = inflater.inflate(R.layout.hot_sales, null);
gridView = (GridView) gv.findViewById(R.id.grid_view);
bindGridview();
return gv;
}
public void bindGridview() {
new MyAsyncTask(getActivity(),gridView).execute("");
}
class MyAsyncTask extends AsyncTask<String, String, String> {
GridView mGridView;
Activity mContext;
Response response;
public MyAsyncTask(Activity context,GridView gview) {
this.mGridView=gview;
this.mContext=context;
}
protected String doInBackground(String... params) {
File file = new File( Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/sample.txt");
if(file.exists()) {
try{
Reader inputStreamReader …
Run Code Online (Sandbox Code Playgroud) android gson android-gridview android-asynctask android-fragments
我正在使用谷歌地图开发一个Android应用程序.目前我可以在我的应用程序中查看地图,但我不知道如何查看应用程序上的当前位置.
这是我的代码:
public class MapsFragment extends Fragment{
MapView m;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// inflat and return the layout
View v = inflater.inflate(R.layout.map_near_me, container, false);
m = (MapView) v.findViewById(R.id.map);
m.onCreate(savedInstanceState);
return v;
}
}
Run Code Online (Sandbox Code Playgroud)
编辑: 和xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.google.android.gms.maps.MapView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这段代码工作正常,我知道'setmylocationenabled'可以帮助在FragmentActivity中启用,但不幸的是我必须将类型用作'Fragment'.我正在使用谷歌api v2.请有人帮忙解决这个问题.
android google-maps android-layout android-mapview google-maps-android-api-2