Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/210.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从JSON在Gridview中显示XML的图像和文本_Android_Json_Gridview - Fatal编程技术网

Android 从JSON在Gridview中显示XML的图像和文本

Android 从JSON在Gridview中显示XML的图像和文本,android,json,gridview,Android,Json,Gridview,我试图以2乘2的网格视图显示图像和文本中的数据。我已经可以使用json从xml中获取数据了。下面是我的代码。我已经评论了我试图在girdview中显示它的部分,当这行代码正在运行时,它崩溃了。我做错了什么 public class NewArrivalsFragment extends Fragment { private TextView tv; private Context c; private JSONObject json; private JSONAr

我试图以2乘2的网格视图显示图像和文本中的数据。我已经可以使用json从xml中获取数据了。下面是我的代码。我已经评论了我试图在girdview中显示它的部分,当这行代码正在运行时,它崩溃了。我做错了什么

public class NewArrivalsFragment extends Fragment {
    private TextView tv;
    private Context c;
    private JSONObject json;
    private JSONArray products;
    private List<String> list;
    private GridView gridView;
    private String[] products_array;

public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    c = getActivity();



    View view = inflater.inflate(R.layout.fragment_general, container,
            false);
    tv = (TextView) view.findViewById(R.id.textView1);
    tv.setText(getJSON());

    //gridView = (GridView) view.findViewById(R.id.gridview);

    /*
    GridView gridview = (GridView) view.findViewById(R.id.textView1);
    //gridview.setAdapter(new ImageAdapter(this));

    gridview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
            Toast.makeText(c, "" + position, Toast.LENGTH_SHORT).show();
        }
    });
    */

    return view;
}

private String getJSON() {
    String returnStr = "";
    SQLiteHelper sqliteHelper = new SQLiteHelper(c);
    SQLiteDatabase database = sqliteHelper.getReadableDatabase();       
    Cursor cursor = database.rawQuery("SELECT * FROM "+ MyGlobalConstant.TABLE_JSON +" WHERE " +
            MyGlobalConstant.JSON_NAME +" = 'Product'", null);          
    while (cursor.moveToNext()) {       
        returnStr = cursor.getString(cursor.getColumnIndex(MyGlobalConstant.JSON_DATA));
    }

    cursor.close();
    database.close();


    return returnStr;
}

}
fragment_general.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:textAppearance="?android:attr/textAppearanceLarge" />

</LinearLayout>

使用此选项修改布局

 <?xml version="1.0" encoding="utf-8"?>
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="About Us..."
        android:textAppearance="?android:attr/textAppearanceLarge" />
    <GridView
        android:id="@+id/gridView1"
        android:numColumns="auto_fit"
        android:gravity="center"
        android:columnWidth="50dp"
        android:stretchMode="columnWidth"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

    </LinearLayout>

希望这能帮助…

请发布日志。@Gene Lim也提供您的gridViewxml@nitesh已更新代码这可能会帮助您。。。xml中的GridView在哪里?哦,是的,我也忘了GridView。谢谢@GeneLim Love 2帮助-