2016-11-08 11 views
0

私は開発者です。さまざまな名前の&国リストを含むアプリケーションです。私は従業員の名前&を渡したいと思っています。子どものアイテムをクリックすると、別のアクティビティに国名が割り当てられますExpandable ListView入力項目から名前と国を渡すには

設定方法自分のアクティビティでリスナーメソッドをクリックしますか?

package nasir.main.activity; 

import java.util.ArrayList; 

import nasir.adapter.EntryItem; 
import nasir.adapter.MyListAdapter; 
import nasir.adapter.SectionItem; 
import nasir.bd.poem.R; 
import android.app.Activity; 
import android.app.SearchManager; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.ExpandableListView; 
import android.widget.ExpandableListView.OnChildClickListener; 
import android.widget.SearchView; 


public class Employee_List extends Activity implements SearchView.OnQueryTextListener, SearchView.OnCloseListener { 

    Button Collapse; 
    Button Expand; 

    private SearchView search; 
    private MyListAdapter listAdapter; 
    private ExpandableListView myList; 
    private ArrayList<SectionItem> section = new ArrayList<SectionItem>(); 
    ArrayList<EntryItem> items = new ArrayList<EntryItem>(); 
    ExpandableListView expandableList = null; 


    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.poem_list); 


     expandableList = (ExpandableListView) findViewById(R.id.expandableList); 
     Expand = (Button) findViewById(R.id.Expand); 
     Collapse = (Button) findViewById(R.id.Collapse); 

     SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); 
     search = (SearchView) findViewById(R.id.search); 
     search.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); 
     search.setIconifiedByDefault(false); 
     search.setOnQueryTextListener(this); 
     search.setOnCloseListener(this); 

     Collapse.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       int count = listAdapter.getGroupCount(); 
       for (int i = 0; i < count; i++){ 
         myList.collapseGroup(i); 
        } 
       Collapse.setVisibility(View.GONE); 
       Expand.setVisibility(View.VISIBLE); 
      } 
     }); 


     Expand.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       int count = listAdapter.getGroupCount(); 
       for (int i = 0; i < count; i++){ 
         myList.expandGroup(i); 
        } 
       Expand.setVisibility(View.GONE); 
       Collapse.setVisibility(View.VISIBLE); 

      } 
     }); 


     // display the list 
     displayList(); 
     // expand all Groups 
//  expandAll(); 

     collapseAll(); 

    } 



    // method to expand all groups 
    private void expandAll() { 
     int count = listAdapter.getGroupCount(); 
     for (int i = 0; i < count; i++) { 
      myList.expandGroup(i); 
     } 
    } 

    //method to Collapse all groups 
    private void collapseAll() { 
    int count = listAdapter.getGroupCount(); 
    for (int i = 0; i < count; i++){ 
    myList.collapseGroup(i); 
    } 
    } 

    // method to expand all groups 
    private void displayList() { 

     // display the list 
     load_Part_1_Data(); 


     // get reference to the ExpandableListView 
     myList = (ExpandableListView) findViewById(R.id.expandableList); 
     // create the adapter by passing your ArrayList data 
     listAdapter = new MyListAdapter(Poem_List.this, section); 
     // attach the adapter to the list 
     myList.setAdapter(listAdapter); 


     myList.setOnChildClickListener(new OnChildClickListener() { 

      @Override 
      public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2, 
        int arg3, long arg4) { 
       // TODO Auto-generated method stub 
       Intent intent = new Intent(Poem_List.this, Details_Information.class); 
       startActivity(intent); 

       return false; 
      } 
     }); 
    } 




    private void load_Part_1_Data() { 


     items = new ArrayList<EntryItem>(); 
     section.add(new SectionItem(R.drawable.ic_launcher, "", items)); 
     items.add(new EntryItem(R.drawable.ic_launcher, "Margerate Milan", "Computer Operator", getString(R.string.app_name))); 
     items.add(new EntryItem(R.drawable.ic_launcher, "Abraham Jhon", "Salse Man", getString(R.string.app_name))); 

     items = new ArrayList<EntryItem>(); 
     section.add(new SectionItem(R.drawable.blank_image, "", items)); 
     items.add(new EntryItem(R.drawable.ic_launcher, "England", "Europe", getString(R.string.app_name))); 
     items.add(new EntryItem(R.drawable.ic_launcher, "Japan", "Asia", getString(R.string.app_name))); 



    } 



    @Override 
    public boolean onClose() { 
     listAdapter.filterData(""); 
     expandAll(); 
     return true; 
    } 

    @Override 
    public boolean onQueryTextChange(String query) { 
     listAdapter.filterData(query); 
     expandAll(); 
     return true; 
    } 

    @Override 
    public boolean onQueryTextSubmit(String query) { 
     listAdapter.filterData(query); 
     expandAll(); 
     return false; 
    } 

} 

EMPLOYEE_LISTアクティビティでMyListAdapter.Class

package nasir.adapter; 

import java.util.ArrayList; 

import nasir.bd.poem.R; 
import nasir.main.activity.Details_Information; 
import android.content.Context; 
import android.content.Intent; 
import android.os.Bundle; 
import android.util.Log; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.view.ViewGroup; 
import android.widget.BaseExpandableListAdapter; 
import android.widget.ImageView; 
import android.widget.TextView; 

public class MyListAdapter extends BaseExpandableListAdapter { 


    private Context context; 
    private ArrayList<SectionItem> continentList; 
    private ArrayList<SectionItem> originalList; 

    public MyListAdapter(Context context, ArrayList<SectionItem> continentList) { 
     this.context = context; 
     this.continentList = new ArrayList<SectionItem>(); 
     this.continentList.addAll(continentList); 
     this.originalList = new ArrayList<SectionItem>(); 
     this.originalList.addAll(continentList); 
    } 

    @Override 
    public Object getChild(int groupPosition, int childPosition) { 
     ArrayList<EntryItem> countryList = continentList.get(groupPosition).getSectionList(); 
     return countryList.get(childPosition); 
    } 

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

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

     final EntryItem country = (EntryItem) getChild(groupPosition, childPosition); 
     if (view == null) { 
      LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      view = layoutInflater.inflate(R.layout.child_row, null); 
     } 

     ImageView Rank = (ImageView) view.findViewById(R.id.Rank); 
     TextView Poem = (TextView) view.findViewById(R.id.Poem); 
     TextView Poetry = (TextView) view.findViewById(R.id.Poetry); 


     Rank.setImageResource(country.getRank()); 
     Poem.setText(country.getPoem().trim()); 
     Poetry.setText(country.getPoetry().trim()); 

     view.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View v) { 

      Intent intent = new Intent(context, Details_Information.class); 
      Bundle bundle=new Bundle(); 
      intent.putExtras(bundle); 
      intent.putExtra("header", country.getDetails_Doc()); 
      context.startActivity(intent); 

     } 
    }); 

     return view; 
    } 


    @Override 
    public int getChildrenCount(int groupPosition) { 

     ArrayList<EntryItem> countryList = continentList.get(groupPosition).getSectionList(); 
     return countryList.size(); 

    } 

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

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

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

    @Override 
    public View getGroupView(int groupPosition, boolean isLastChild, View view, ViewGroup parent) { 

     SectionItem continent = (SectionItem) getGroup(groupPosition); 
     if (view == null) { 
      LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      view = layoutInflater.inflate(R.layout.group_row, null); 
     } 

     TextView heading = (TextView) view.findViewById(R.id.heading); 
     heading.setText(continent.getName().trim()); 

     ImageView Group_icon = (ImageView) view.findViewById(R.id.Group_Icon); 
     Group_icon.setImageResource(continent.getIcon()); 

     return view; 
    } 

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

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

    public void filterData(String query) { 

     query = query.toLowerCase(); 
     Log.v("MyListAdapter", String.valueOf(continentList.size())); 
     continentList.clear(); 

     if (query.isEmpty()) { 
      continentList.addAll(originalList); 
     } else { 

      for (SectionItem continent : originalList) { 

       ArrayList<EntryItem> countryList = continent.getSectionList(); 
       ArrayList<EntryItem> newList = new ArrayList<EntryItem>(); 
       for (EntryItem country : countryList) { 
        if (country.getPoem().toLowerCase().contains(query) || country.getPoetry().toLowerCase().contains(query)) { 
         newList.add(country); 
        } 
       } 
       if (newList.size() > 0) { 
        SectionItem nContinent = new SectionItem(continent.getIcon(), continent.getName(), newList); 
        continentList.add(nContinent); 
       } 
      } 
     } 

     Log.v("MyListAdapter", String.valueOf(continentList.size())); 
     notifyDataSetChanged(); 

    } 

} 

答えて

0

、あなたはChildClickListener

myList.setOnChildClickListener(new OnChildClickListener() { 

      @Override 
      public boolean onChildClick(ExpandableListView arg0, View arg1, int arg2, 
        int arg3, long arg4) { 
       // TODO Auto-generated method stub 
       //Here You can access the child data by 
       final EntryItem country = (EntryItem) listAdapter .getChild(arg2, arg3); 
       //From here you can pass the data through Intent 

       ... 

       return false; 
      } 
     }); 
+0

多くの多くのおかげで弟から取得する子のインデックスとグループを介してデータにアクセスすることができます。 正しく動作します。 –

+0

その兄弟を聞いてうれしいです:-) –

関連する問題