Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.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
Java 如何在fragment textview中显示列表项名称_Java_Android_Android Fragments_Android Recyclerview - Fatal编程技术网

Java 如何在fragment textview中显示列表项名称

Java 如何在fragment textview中显示列表项名称,java,android,android-fragments,android-recyclerview,Java,Android,Android Fragments,Android Recyclerview,我想在片段文本视图中显示列表项名称。 我该怎么做 这是我的密码: Title.java public class Title extends AppCompatActivity implements OnVersionNameSelectionChangeListener{ private static final String TAG = Title.class.getSimpleName(); String str, arr[]; @Override protected

我想在片段文本视图中显示列表项名称。

我该怎么做

这是我的密码:

  • Title.java

     public class Title extends AppCompatActivity implements          OnVersionNameSelectionChangeListener{
    private static final String TAG = Title.class.getSimpleName();
    
    String str, arr[];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    setContentView(R.layout.activity_title);
    str = getIntent().getExtras().getString("string","defaultValue");
    //Toast.makeText(getApplicationContext(), str , Toast.LENGTH_SHORT).show();
    
    // Check whether the Activity is using the layout verison with the fragment_container
    // FrameLayout and if so we must add the first fragment
    
    if (findViewById(R.id.fragment_container) != null){
    
        // However if we are being restored from a previous state, then we don't
        // need to do anything and should return or we could end up with overlapping Fragments
        if (savedInstanceState != null){
            return;
        }
    
        // Create an Instance of Fragment
        VersionsFragment versionsFragment = new VersionsFragment();
        Bundle bundle = new Bundle();
        bundle.putString("key", str);
        //versionsFragment.setArguments(getIntent().getExtras());
        versionsFragment.setArguments(bundle);
                                                                                        getFragmentManager().beginTransaction().add(R.id.fragment_container, versionsFragment).commit();
    }
    }
    
     @Override
    public void OnSelectionChanged(int versionNameIndex, String[] answer) {
    DescriptionFragment descriptionFragment = (DescriptionFragment) getFragmentManager()
            .findFragmentById(R.id.version_description);
    
    if (descriptionFragment != null){
        // If description is available, we are in two pane layout
        // so we call the method in DescriptionFragment to update its content
        // Bundle args = new Bundle();
        // args.putString("key", str);
        // args.putStringArray("answer", answer );
        //args.putInt(DescriptionFragment.KEY_POSITION,versionNameIndex);
        //descriptionFragment.setArguments(args);
        setArray(answer);
        //setStr(str);
        descriptionFragment.setDescription(versionNameIndex);
    } else {
        DescriptionFragment newDescriptionFragment = new DescriptionFragment();
        Bundle args = new Bundle();
        //args.putString("key", str);
        //args.putStringArray("answer", answer );
        setArray(answer);
        args.putInt(DescriptionFragment.KEY_POSITION,versionNameIndex);
    
        newDescriptionFragment.setArguments(args);
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    
        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the backStack so the User can navigate back
        fragmentTransaction.replace(R.id.fragment_container,newDescriptionFragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
    }
        }
       public String getStr(){
       return str;
        }
    
        public void setArray(String[] s)
        {
           arr = s;
    //Log.d(TAG, "setArray: " + arr[0]);
        }
    
       public String[] getArray(){
       return arr;
       }
       }
    
    public class DescriptionFragment extends Fragment {
    private static final String TAG = DescriptionFragment.class.getSimpleName();
    final static String KEY_POSITION = "position";
    int mCurrentPosition = -1;
    String[] mVersionTitle;
    String[] mVersionDescriptions;
    TextView mVersionTitleTextView;
    TextView mVersionDescriptionTextView;
    
    public DescriptionFragment() {
    
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Title t = (Title) getActivity();
        mVersionDescriptions = t.getArray();
        //Log.d(TAG , "onActivityCreated: " + mVersionDescriptions.length);
    }
    
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
        // If the Activity is recreated, the savedInstanceStare Bundle isn't empty
        // we restore the previous version name selection set by the Bundle.
        // This is necessary when in two pane layout
    
        String strtext = getArguments().getString("title");
    
        if (savedInstanceState != null) {
            mCurrentPosition = savedInstanceState.getInt(KEY_POSITION);
            //Log.d(TAG, "Show last click position: "+ KEY_POSITION);
        }
                View view = inflater.inflate(R.layout.fragment_description, container, false);
                mVersionTitleTextView = (TextView) view.findViewById(R.id.textView_Title);
                mVersionTitleTextView.setText(strtext);
                mVersionDescriptionTextView = (TextView) view.findViewById(R.id.version_description);
                return view;
    }
    
    
    @Override
    public void onStart() {
        super.onStart();
        Bundle args = new Bundle();
        args = getArguments();
    
    
        if (args != null) {
            // Set description based on argument passed in
          //  setTitle(args.getInt(KEY_POSITION));
            setDescription(args.getInt(KEY_POSITION));
    
        } else if (mCurrentPosition != -1) {
            // Set description based on savedInstanceState defined during onCreateView()
           // setTitle(mCurrentPosition);
            setDescription(mCurrentPosition);
        }
    }
    
    public void setDescription(int descriptionIndex) {
        Title t = (Title) getActivity();
       // mVersionTitle = t.getArray();
        mVersionDescriptions = t.getArray();
        //mVersionTitleTextView.setText(mVersionTitle[descriptionIndex]);
        mVersionDescriptionTextView.setText(mVersionDescriptions[descriptionIndex]);
        mCurrentPosition = descriptionIndex;
        Log.d(TAG, "onSaveInstanceState: " + mCurrentPosition);
    }
    
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    
        // Save the current description selection in case we need to recreate the fragment
        outState.putInt(KEY_POSITION, mCurrentPosition);
        //Log.d(TAG, "onSaveInstanceState: " + mCurrentPosition);
          }
        }
    
      public class VersionsFragment extends ListFragment {
      private static final String TAG = VersionsFragment.class.getSimpleName();
      String[] title = new String[0];
      String[] description = new String[0];
      String table=new String();
      public VersionsFragment() {
      }
    
    
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    
    String myValue = this.getArguments().getString("key");
    
    Title q = (Title) getActivity();
    table = q.getStr();
    //Log.d(TAG, "onActivityCreated: " + table);
    
    if(table.equals("Paragraph Writing"))
        table="paragraph";
    else if(table.equals("Story Writing"))
        table="story";
    table = table.toLowerCase();
    new MyTask().execute();
    }
    
    class MyTask extends AsyncTask<String, Integer, String[]> {
    
    @Override
    protected String[] doInBackground(String... params) {
        String[] versionName = new String[0];
        ArrayList<String> scripts = new ArrayList<String>();
        ArrayList<String> scripts2 = new ArrayList<String>();
        try {
            //Log.d(VersionsFragment.class.getSimpleName(),"http://192.168.1.105/android/phpcall.php?table="+table );
            URL url = new URL("http://192.168.1.6/ps/phpcall.php?table="+table);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            String strJson = "";
            String line;
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((line = br.readLine()) != null) {
                strJson += line;
            }
            //Log.d(VersionsFragment.class.getSimpleName(), "JSON string =" + strJson);
            JSONArray jArray = new JSONArray(strJson);
            //JSONObject jsonObj = new JSONObject(strJson);
            // Getting JSON Array node
            //JSONArray jArray = jsonObj.getJSONArray(strJson);
    
            for (int i = 0; i < jArray.length(); i++) {
    
                JSONObject jObject = jArray.getJSONObject(i);
    
                String name = jObject.getInt("id") + ". " + jObject.getString("title");
                scripts.add(name);
    
                Bundle bundle = new Bundle();
                bundle.putString("title", name);
                // set Fragmentclass Arguments
                DescriptionFragment fragobj = new DescriptionFragment();
                fragobj.setArguments(bundle);
    
                String name2 = jObject.getString("description");
                scripts2.add(name2);
            }
            versionName = scripts.toArray(new String[scripts.size()]);
           // title = scripts.toArray(new String[scripts.size()]);
            description = scripts2.toArray(new String[scripts.size()]);
    
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return versionName;
    }
    
    protected void onPostExecute(String[] result){
        //for(int i=0;i<result.length;i++)
            //Log.d(VersionsFragment.class.getSimpleName(), result[i]);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, result);
        setListAdapter(adapter);
    }
    }
    
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
    OnVersionNameSelectionChangeListener listener = (OnVersionNameSelectionChangeListener) getActivity();
    listener.OnSelectionChanged(position,description);
        }
    }
    
  • DescriptionFragment.java

     public class Title extends AppCompatActivity implements          OnVersionNameSelectionChangeListener{
    private static final String TAG = Title.class.getSimpleName();
    
    String str, arr[];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    setContentView(R.layout.activity_title);
    str = getIntent().getExtras().getString("string","defaultValue");
    //Toast.makeText(getApplicationContext(), str , Toast.LENGTH_SHORT).show();
    
    // Check whether the Activity is using the layout verison with the fragment_container
    // FrameLayout and if so we must add the first fragment
    
    if (findViewById(R.id.fragment_container) != null){
    
        // However if we are being restored from a previous state, then we don't
        // need to do anything and should return or we could end up with overlapping Fragments
        if (savedInstanceState != null){
            return;
        }
    
        // Create an Instance of Fragment
        VersionsFragment versionsFragment = new VersionsFragment();
        Bundle bundle = new Bundle();
        bundle.putString("key", str);
        //versionsFragment.setArguments(getIntent().getExtras());
        versionsFragment.setArguments(bundle);
                                                                                        getFragmentManager().beginTransaction().add(R.id.fragment_container, versionsFragment).commit();
    }
    }
    
     @Override
    public void OnSelectionChanged(int versionNameIndex, String[] answer) {
    DescriptionFragment descriptionFragment = (DescriptionFragment) getFragmentManager()
            .findFragmentById(R.id.version_description);
    
    if (descriptionFragment != null){
        // If description is available, we are in two pane layout
        // so we call the method in DescriptionFragment to update its content
        // Bundle args = new Bundle();
        // args.putString("key", str);
        // args.putStringArray("answer", answer );
        //args.putInt(DescriptionFragment.KEY_POSITION,versionNameIndex);
        //descriptionFragment.setArguments(args);
        setArray(answer);
        //setStr(str);
        descriptionFragment.setDescription(versionNameIndex);
    } else {
        DescriptionFragment newDescriptionFragment = new DescriptionFragment();
        Bundle args = new Bundle();
        //args.putString("key", str);
        //args.putStringArray("answer", answer );
        setArray(answer);
        args.putInt(DescriptionFragment.KEY_POSITION,versionNameIndex);
    
        newDescriptionFragment.setArguments(args);
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    
        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the backStack so the User can navigate back
        fragmentTransaction.replace(R.id.fragment_container,newDescriptionFragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
    }
        }
       public String getStr(){
       return str;
        }
    
        public void setArray(String[] s)
        {
           arr = s;
    //Log.d(TAG, "setArray: " + arr[0]);
        }
    
       public String[] getArray(){
       return arr;
       }
       }
    
    public class DescriptionFragment extends Fragment {
    private static final String TAG = DescriptionFragment.class.getSimpleName();
    final static String KEY_POSITION = "position";
    int mCurrentPosition = -1;
    String[] mVersionTitle;
    String[] mVersionDescriptions;
    TextView mVersionTitleTextView;
    TextView mVersionDescriptionTextView;
    
    public DescriptionFragment() {
    
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Title t = (Title) getActivity();
        mVersionDescriptions = t.getArray();
        //Log.d(TAG , "onActivityCreated: " + mVersionDescriptions.length);
    }
    
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
        // If the Activity is recreated, the savedInstanceStare Bundle isn't empty
        // we restore the previous version name selection set by the Bundle.
        // This is necessary when in two pane layout
    
        String strtext = getArguments().getString("title");
    
        if (savedInstanceState != null) {
            mCurrentPosition = savedInstanceState.getInt(KEY_POSITION);
            //Log.d(TAG, "Show last click position: "+ KEY_POSITION);
        }
                View view = inflater.inflate(R.layout.fragment_description, container, false);
                mVersionTitleTextView = (TextView) view.findViewById(R.id.textView_Title);
                mVersionTitleTextView.setText(strtext);
                mVersionDescriptionTextView = (TextView) view.findViewById(R.id.version_description);
                return view;
    }
    
    
    @Override
    public void onStart() {
        super.onStart();
        Bundle args = new Bundle();
        args = getArguments();
    
    
        if (args != null) {
            // Set description based on argument passed in
          //  setTitle(args.getInt(KEY_POSITION));
            setDescription(args.getInt(KEY_POSITION));
    
        } else if (mCurrentPosition != -1) {
            // Set description based on savedInstanceState defined during onCreateView()
           // setTitle(mCurrentPosition);
            setDescription(mCurrentPosition);
        }
    }
    
    public void setDescription(int descriptionIndex) {
        Title t = (Title) getActivity();
       // mVersionTitle = t.getArray();
        mVersionDescriptions = t.getArray();
        //mVersionTitleTextView.setText(mVersionTitle[descriptionIndex]);
        mVersionDescriptionTextView.setText(mVersionDescriptions[descriptionIndex]);
        mCurrentPosition = descriptionIndex;
        Log.d(TAG, "onSaveInstanceState: " + mCurrentPosition);
    }
    
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    
        // Save the current description selection in case we need to recreate the fragment
        outState.putInt(KEY_POSITION, mCurrentPosition);
        //Log.d(TAG, "onSaveInstanceState: " + mCurrentPosition);
          }
        }
    
      public class VersionsFragment extends ListFragment {
      private static final String TAG = VersionsFragment.class.getSimpleName();
      String[] title = new String[0];
      String[] description = new String[0];
      String table=new String();
      public VersionsFragment() {
      }
    
    
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    
    String myValue = this.getArguments().getString("key");
    
    Title q = (Title) getActivity();
    table = q.getStr();
    //Log.d(TAG, "onActivityCreated: " + table);
    
    if(table.equals("Paragraph Writing"))
        table="paragraph";
    else if(table.equals("Story Writing"))
        table="story";
    table = table.toLowerCase();
    new MyTask().execute();
    }
    
    class MyTask extends AsyncTask<String, Integer, String[]> {
    
    @Override
    protected String[] doInBackground(String... params) {
        String[] versionName = new String[0];
        ArrayList<String> scripts = new ArrayList<String>();
        ArrayList<String> scripts2 = new ArrayList<String>();
        try {
            //Log.d(VersionsFragment.class.getSimpleName(),"http://192.168.1.105/android/phpcall.php?table="+table );
            URL url = new URL("http://192.168.1.6/ps/phpcall.php?table="+table);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            String strJson = "";
            String line;
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((line = br.readLine()) != null) {
                strJson += line;
            }
            //Log.d(VersionsFragment.class.getSimpleName(), "JSON string =" + strJson);
            JSONArray jArray = new JSONArray(strJson);
            //JSONObject jsonObj = new JSONObject(strJson);
            // Getting JSON Array node
            //JSONArray jArray = jsonObj.getJSONArray(strJson);
    
            for (int i = 0; i < jArray.length(); i++) {
    
                JSONObject jObject = jArray.getJSONObject(i);
    
                String name = jObject.getInt("id") + ". " + jObject.getString("title");
                scripts.add(name);
    
                Bundle bundle = new Bundle();
                bundle.putString("title", name);
                // set Fragmentclass Arguments
                DescriptionFragment fragobj = new DescriptionFragment();
                fragobj.setArguments(bundle);
    
                String name2 = jObject.getString("description");
                scripts2.add(name2);
            }
            versionName = scripts.toArray(new String[scripts.size()]);
           // title = scripts.toArray(new String[scripts.size()]);
            description = scripts2.toArray(new String[scripts.size()]);
    
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return versionName;
    }
    
    protected void onPostExecute(String[] result){
        //for(int i=0;i<result.length;i++)
            //Log.d(VersionsFragment.class.getSimpleName(), result[i]);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, result);
        setListAdapter(adapter);
    }
    }
    
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
    OnVersionNameSelectionChangeListener listener = (OnVersionNameSelectionChangeListener) getActivity();
    listener.OnSelectionChanged(position,description);
        }
    }
    
  • versionFragment.java

     public class Title extends AppCompatActivity implements          OnVersionNameSelectionChangeListener{
    private static final String TAG = Title.class.getSimpleName();
    
    String str, arr[];
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    setContentView(R.layout.activity_title);
    str = getIntent().getExtras().getString("string","defaultValue");
    //Toast.makeText(getApplicationContext(), str , Toast.LENGTH_SHORT).show();
    
    // Check whether the Activity is using the layout verison with the fragment_container
    // FrameLayout and if so we must add the first fragment
    
    if (findViewById(R.id.fragment_container) != null){
    
        // However if we are being restored from a previous state, then we don't
        // need to do anything and should return or we could end up with overlapping Fragments
        if (savedInstanceState != null){
            return;
        }
    
        // Create an Instance of Fragment
        VersionsFragment versionsFragment = new VersionsFragment();
        Bundle bundle = new Bundle();
        bundle.putString("key", str);
        //versionsFragment.setArguments(getIntent().getExtras());
        versionsFragment.setArguments(bundle);
                                                                                        getFragmentManager().beginTransaction().add(R.id.fragment_container, versionsFragment).commit();
    }
    }
    
     @Override
    public void OnSelectionChanged(int versionNameIndex, String[] answer) {
    DescriptionFragment descriptionFragment = (DescriptionFragment) getFragmentManager()
            .findFragmentById(R.id.version_description);
    
    if (descriptionFragment != null){
        // If description is available, we are in two pane layout
        // so we call the method in DescriptionFragment to update its content
        // Bundle args = new Bundle();
        // args.putString("key", str);
        // args.putStringArray("answer", answer );
        //args.putInt(DescriptionFragment.KEY_POSITION,versionNameIndex);
        //descriptionFragment.setArguments(args);
        setArray(answer);
        //setStr(str);
        descriptionFragment.setDescription(versionNameIndex);
    } else {
        DescriptionFragment newDescriptionFragment = new DescriptionFragment();
        Bundle args = new Bundle();
        //args.putString("key", str);
        //args.putStringArray("answer", answer );
        setArray(answer);
        args.putInt(DescriptionFragment.KEY_POSITION,versionNameIndex);
    
        newDescriptionFragment.setArguments(args);
        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
    
        // Replace whatever is in the fragment_container view with this fragment,
        // and add the transaction to the backStack so the User can navigate back
        fragmentTransaction.replace(R.id.fragment_container,newDescriptionFragment);
        fragmentTransaction.addToBackStack(null);
        fragmentTransaction.commit();
    }
        }
       public String getStr(){
       return str;
        }
    
        public void setArray(String[] s)
        {
           arr = s;
    //Log.d(TAG, "setArray: " + arr[0]);
        }
    
       public String[] getArray(){
       return arr;
       }
       }
    
    public class DescriptionFragment extends Fragment {
    private static final String TAG = DescriptionFragment.class.getSimpleName();
    final static String KEY_POSITION = "position";
    int mCurrentPosition = -1;
    String[] mVersionTitle;
    String[] mVersionDescriptions;
    TextView mVersionTitleTextView;
    TextView mVersionDescriptionTextView;
    
    public DescriptionFragment() {
    
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        Title t = (Title) getActivity();
        mVersionDescriptions = t.getArray();
        //Log.d(TAG , "onActivityCreated: " + mVersionDescriptions.length);
    }
    
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    
        // If the Activity is recreated, the savedInstanceStare Bundle isn't empty
        // we restore the previous version name selection set by the Bundle.
        // This is necessary when in two pane layout
    
        String strtext = getArguments().getString("title");
    
        if (savedInstanceState != null) {
            mCurrentPosition = savedInstanceState.getInt(KEY_POSITION);
            //Log.d(TAG, "Show last click position: "+ KEY_POSITION);
        }
                View view = inflater.inflate(R.layout.fragment_description, container, false);
                mVersionTitleTextView = (TextView) view.findViewById(R.id.textView_Title);
                mVersionTitleTextView.setText(strtext);
                mVersionDescriptionTextView = (TextView) view.findViewById(R.id.version_description);
                return view;
    }
    
    
    @Override
    public void onStart() {
        super.onStart();
        Bundle args = new Bundle();
        args = getArguments();
    
    
        if (args != null) {
            // Set description based on argument passed in
          //  setTitle(args.getInt(KEY_POSITION));
            setDescription(args.getInt(KEY_POSITION));
    
        } else if (mCurrentPosition != -1) {
            // Set description based on savedInstanceState defined during onCreateView()
           // setTitle(mCurrentPosition);
            setDescription(mCurrentPosition);
        }
    }
    
    public void setDescription(int descriptionIndex) {
        Title t = (Title) getActivity();
       // mVersionTitle = t.getArray();
        mVersionDescriptions = t.getArray();
        //mVersionTitleTextView.setText(mVersionTitle[descriptionIndex]);
        mVersionDescriptionTextView.setText(mVersionDescriptions[descriptionIndex]);
        mCurrentPosition = descriptionIndex;
        Log.d(TAG, "onSaveInstanceState: " + mCurrentPosition);
    }
    
    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
    
        // Save the current description selection in case we need to recreate the fragment
        outState.putInt(KEY_POSITION, mCurrentPosition);
        //Log.d(TAG, "onSaveInstanceState: " + mCurrentPosition);
          }
        }
    
      public class VersionsFragment extends ListFragment {
      private static final String TAG = VersionsFragment.class.getSimpleName();
      String[] title = new String[0];
      String[] description = new String[0];
      String table=new String();
      public VersionsFragment() {
      }
    
    
     @Override
     public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
    
    String myValue = this.getArguments().getString("key");
    
    Title q = (Title) getActivity();
    table = q.getStr();
    //Log.d(TAG, "onActivityCreated: " + table);
    
    if(table.equals("Paragraph Writing"))
        table="paragraph";
    else if(table.equals("Story Writing"))
        table="story";
    table = table.toLowerCase();
    new MyTask().execute();
    }
    
    class MyTask extends AsyncTask<String, Integer, String[]> {
    
    @Override
    protected String[] doInBackground(String... params) {
        String[] versionName = new String[0];
        ArrayList<String> scripts = new ArrayList<String>();
        ArrayList<String> scripts2 = new ArrayList<String>();
        try {
            //Log.d(VersionsFragment.class.getSimpleName(),"http://192.168.1.105/android/phpcall.php?table="+table );
            URL url = new URL("http://192.168.1.6/ps/phpcall.php?table="+table);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            String strJson = "";
            String line;
            BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
            while ((line = br.readLine()) != null) {
                strJson += line;
            }
            //Log.d(VersionsFragment.class.getSimpleName(), "JSON string =" + strJson);
            JSONArray jArray = new JSONArray(strJson);
            //JSONObject jsonObj = new JSONObject(strJson);
            // Getting JSON Array node
            //JSONArray jArray = jsonObj.getJSONArray(strJson);
    
            for (int i = 0; i < jArray.length(); i++) {
    
                JSONObject jObject = jArray.getJSONObject(i);
    
                String name = jObject.getInt("id") + ". " + jObject.getString("title");
                scripts.add(name);
    
                Bundle bundle = new Bundle();
                bundle.putString("title", name);
                // set Fragmentclass Arguments
                DescriptionFragment fragobj = new DescriptionFragment();
                fragobj.setArguments(bundle);
    
                String name2 = jObject.getString("description");
                scripts2.add(name2);
            }
            versionName = scripts.toArray(new String[scripts.size()]);
           // title = scripts.toArray(new String[scripts.size()]);
            description = scripts2.toArray(new String[scripts.size()]);
    
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return versionName;
    }
    
    protected void onPostExecute(String[] result){
        //for(int i=0;i<result.length;i++)
            //Log.d(VersionsFragment.class.getSimpleName(), result[i]);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, result);
        setListAdapter(adapter);
    }
    }
    
    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
    OnVersionNameSelectionChangeListener listener = (OnVersionNameSelectionChangeListener) getActivity();
    listener.OnSelectionChanged(position,description);
        }
    }
    
    public类VersionsFragment扩展了ListFragment{
    私有静态最终字符串标记=VersionsFragment.class.getSimpleName();
    字符串[]标题=新字符串[0];
    字符串[]说明=新字符串[0];
    字符串表=新字符串();
    公共版本片段(){
    }
    @凌驾
    已创建ActivityState上的公共无效(Bundle savedInstanceState){
    super.onActivityCreated(savedInstanceState);
    String myValue=this.getArguments().getString(“键”);
    标题q=(标题)getActivity();
    table=q.getStr();
    //Log.d(标记“onActivityCreated:+表);
    如果(表等于(“段落写作”))
    表=“段落”;
    else if(表equals(“故事写作”))
    table=“故事”;
    table=table.toLowerCase();
    新建MyTask().execute();
    }
    类MyTask扩展了AsyncTask{
    @凌驾
    受保护字符串[]doInBackground(字符串…参数){
    String[]versionName=新字符串[0];
    ArrayList脚本=新建ArrayList();
    ArrayList scripts2=新的ArrayList();
    试一试{
    //Log.d(VersionsFragment.class.getSimpleName(),”http://192.168.1.105/android/phpcall.php?table=“+表格);
    URL=新URL(“http://192.168.1.6/ps/phpcall.php?table=“+表格);
    HttpURLConnection conn=(HttpURLConnection)url.openConnection();
    字符串strJson=“”;
    弦线;
    BufferedReader br=新的BufferedReader(新的InputStreamReader(conn.getInputStream());
    而((line=br.readLine())!=null){
    strJson+=线路;
    }
    //Log.d(VersionsFragment.class.getSimpleName(),“JSON字符串=“+strJson”);
    JSONArray jArray=新JSONArray(strJson);
    //JSONObject jsonObj=新的JSONObject(strJson);
    //获取JSON数组节点
    //JSONArray jArray=jsonObj.getJSONArray(strJson);
    for(int i=0;i