2017-03-06 25 views
0

私は同じトピックでリンクを訪問しましたが、私の質問には答えません。単純な展開可能なリストビューを使用するだけで、カスタムのExpandableリストビューを作成したくありません。私は正常にmysqlデータベースからデータをフェッチすることができ、トーストメッセージを使用して取得されているすべての値を検証し、また、郵便配達員を使用してPHPスクリプトをテストしました。
今度は、取得可能な値をExpandableListViewに表示します。
これは私がデータベースから値をフェッチする機能を使用していますが、私は値を取得していますが、私はExpandableListViewでそれらの値を印刷することができません
mysqlからデータを取得し、アンドロイドでExpandableListViewにデータを表示

<?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="wrap_content" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/lblListItem" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:textSize="17sp" 
     android:paddingTop="5dp" 
     android:paddingBottom="5dp" 
     android:paddingLeft="?android:attr/expandableListPreferredChildPaddingLeft"/> 

</LinearLayout> 

list_child.xmlファイルです。この機能は、私が最初に名前、電子メールおよび上記の機能からIDの戻りのような子ビューを取得しています拡張可能なリストビューで拡張可能なリストビュー

private void ListData() { 
    listDataHeader = new ArrayList<String>(); 
    listDataChild = new HashMap<String,List<String>>(); 

    //Adding header to expandable list view 
    listDataHeader.add("ABC"); 
    listDataHeader.add("DEF"); 

    //Adding child data 
    List<String> abc = new ArrayList<>(); 
    abc.add(fetchAbc()); 
    List<String> def = new ArrayList<>(); 
    def.add(fetchDef()); 


    //Header child data 
    listDataChild.put(listDataHeader.get(0),abc); 
    listDataChild.put(listDataHeader.get(1),def); 
} 
    private String fetchAbc() { 

    return ("first name : \t"+Name+"\nEmail : \t"+email); 
} 

private String fetchDef() { 

    return ("Id : \t"+id); 
} 

を準備します。しかし、値ではありません。これは

public class ExpandableListAdapter extends BaseExpandableListAdapter { 
    private Context _context; 
    private List<String> _listDataHeader; 
    private HashMap<String,List<String>> _listDataChild; 
    public ExpandableListAdapter(Context context, List<String> listDataHeader, 
           HashMap<String, List<String>> listChildData) { 
     this._context = context; 
     this._listDataHeader = listDataHeader; 
     this._listDataChild = listChildData; 
    } 

    @Override 
    public Object getChild(int groupPosition, int childPosititon) { 
     return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
       .get(childPosititon); 
    } 

    @Override 
    public long getChildId(int groupPosition, int childPosition) { 
     return childPosition; 
    } 

    @Override 
    public View getChildView(int groupPosition, final int childPosition, 
          boolean isLastChild, View convertView, ViewGroup parent) { 

     final String childText = (String) getChild(groupPosition, childPosition); 

     if (convertView == null) { 
      LayoutInflater infalInflater = (LayoutInflater) this._context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.list_item, null); 
     } 

     TextView txtListChild = (TextView) convertView 
       .findViewById(R.id.lblListItem); 

     txtListChild.setText(childText); 
     return convertView; 
    } 

    @Override 
    public int getChildrenCount(int groupPosition) { 
     return this._listDataChild.get(this._listDataHeader.get(groupPosition)) 
       .size(); 
    } 

    @Override 
    public Object getGroup(int groupPosition) { 
     return this._listDataHeader.get(groupPosition); 
    } 

    @Override 
    public int getGroupCount() { 
     return this._listDataHeader.size(); 
    } 

    @Override 
    public long getGroupId(int groupPosition) { 
     return groupPosition; 
    } 

    @Override 
    public View getGroupView(int groupPosition, boolean isExpanded, 
          View convertView, ViewGroup parent) { 
     String headerTitle = (String) getGroup(groupPosition); 
     if (convertView == null) { 
      LayoutInflater infalInflater = (LayoutInflater) this._context 
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      convertView = infalInflater.inflate(R.layout.list_group, null); 
     } 

     TextView lblListHeader = (TextView) convertView 
       .findViewById(R.id.header); 
     lblListHeader.setTypeface(null, Typeface.BOLD); 
     lblListHeader.setText(headerTitle); 

     return convertView; 
    } 

    @Override 
    public boolean hasStableIds() { 
     return false; 
    } 

    @Override 
    public boolean isChildSelectable(int groupPosition, int childPosition) { 
     return true; 
    } 
} 

ありがとうExpandableListAdapterクラスファイルです。

+0

[アンドロイドの動的データと拡張リストビュー(http://stackoverflow.com/questions/17523257/expandable-listview-with-dynamic-data-in-android) –

+0

の可能性の重複Iリンクを確認また、答えは、OPは答えを受け入れていないことに気づくべきです。そして私はカスタムのExpandableリストビューを作成したくないのですが、これは単純なものでこれを実現したいだけです –

答えて

0
private void prepareListData() { 
    listDataHeader = new ArrayList<String>(); 
    listDataChild = new HashMap<String, List<String>>(); 
    url = ip.ip+"loadcourse.php"; 
    StringRequest postRequest = new StringRequest(Request.Method.POST, url, 
      new Response.Listener<String>() { 
       @Override 
       public void onResponse(String response) { 



        try { 
         JSONArray data = new JSONArray(response); 
         for (int i = 0; i < data.length(); i++) { 


          JSONObject c = data.getJSONObject(i); 
          one = c.getString("dname").split(","); 
          two = c.getString("course_name"); 
          listDataHeader.add(String.valueOf(one[0])); 


          JSONArray dt= new JSONArray(two.toString()); 
          List<String> nowShowing = new ArrayList<String>(); 
          for (int j = 0; j < dt.length(); j++) { 


           JSONObject d = dt.getJSONObject(j); 

           three = d.getString("course").split(","); 

           nowShowing.add(String.valueOf(three[0])); 


          } 
          listDataChild.put(listDataHeader.get(i), nowShowing); 










         } 




        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 


        // response 
        Log.d("Response", response); 
       } 
      }, 
      new Response.ErrorListener() { 
       @Override 
       public void onErrorResponse(VolleyError error) { 
        // error 
        Log.d("Error.Response", error.toString()); 
       } 
      } 
    ) { 
     @Override 
     protected Map<String, String> getParams() { 
      Map<String, String> params = new HashMap<String, String>(); 

      params.put("cid",ip.id); 
      return params; 
     } 
    }; 
    queue.add(postRequest); 
関連する問題