我想要发生的是当我点击我的可扩展列表视图中的一个项目时,它会显示一个新活动。 例如,我的可扩展列表视图中有一个名称列表(paul,john,mark,james,luke),当我点击#james时,新开放的活动包含有关#james的信息。
/*********************************CategoryScreen.java*************/
package filipiknows.open;
import filipiknows.open.R;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.ExpandableListView.OnGroupClickListener;
public class CategoryScreen extends Activity {
ELAdapter listAdapter;
ExpandableListView expListView;
List<String> listDataHeader;
HashMap<String, List<String>> listDataChild;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.category);
// get the listview
expListView = (ExpandableListView) findViewById(R.id.lvExp);
// preparing list data
prepareListData();
listAdapter = new ELAdapter(this, listDataHeader, listDataChild);
// setting list adapter
expListView.setAdapter(listAdapter);
// Listview Group click listener
expListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v,
int groupPosition, long id) {
// Toast.makeText(getApplicationContext(),
// "Group Clicked " + listDataHeader.get(groupPosition),
// Toast.LENGTH_SHORT).show();
return false;
}
});
// Listview on child click listener
expListView.setOnChildClickListener(new OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
return false;
}
});
}
private void prepareListData() {
listDataHeader = new ArrayList<String>();
listDataChild = new HashMap<String, List<String>>();
// Adding child data
listDataHeader.add("Phillippines Heroes");
listDataHeader.add("Presidents");
listDataHeader.add("Culture and Tradition");
listDataHeader.add("Tourist Spots");
listDataHeader.add("Filipino Dishes");
listDataHeader.add("Traditional Customes");
listDataHeader.add("Traditional Games");
// Adding child data
List<String> PhillippinesHeroes = new ArrayList<String>();
PhillippinesHeroes.add("Dr. Jose Rizal");
PhillippinesHeroes.add("Andres Bonifacio");
PhillippinesHeroes.add("General Gregorio del Pilar");
PhillippinesHeroes.add("General Emilio Aguinaldo");
PhillippinesHeroes.add("Apolinario Mabini");
PhillippinesHeroes.add("Father Mariano Gomez");
PhillippinesHeroes.add("Father Father Jose Burgos ");
PhillippinesHeroes.add("Father Father Jacinto Zamora");
PhillippinesHeroes.add("Trece Martirez");
PhillippinesHeroes.add("Emilio Jacinto");
PhillippinesHeroes.add("General Antonio Luna");
PhillippinesHeroes.add("Melchora Aquino");
PhillippinesHeroes.add("Graciano Lopez-Jaena");
PhillippinesHeroes.add("Panday Pira");
PhillippinesHeroes.add("Mariano Ponce");
PhillippinesHeroes.add("Gregoria de Jesus");
PhillippinesHeroes.add("Fernando Ma. Guerrero");
PhillippinesHeroes.add("Felipe Agoncillo");
PhillippinesHeroes.add("Juan Luna");
PhillippinesHeroes.add("Rafael Palma");
PhillippinesHeroes.add("Marcelo H. Del Pilar");
PhillippinesHeroes.add("Pedro Paterno");
PhillippinesHeroes.add("Leona Florentino");
PhillippinesHeroes.add("Isabelo delos Reyes");
PhillippinesHeroes.add("Artemio Ricarte");
PhillippinesHeroes.add("Jose Palma");
PhillippinesHeroes.add("Rajah Lakandola");
PhillippinesHeroes.add("Rajah Soliman");
PhillippinesHeroes.add("Leonor Rivera");
PhillippinesHeroes.add("Marcela Mariño Agoncillo");
PhillippinesHeroes.add("Galicano Apacible");
PhillippinesHeroes.add("Jose Ma. Panganiban");
PhillippinesHeroes.add("Diego Silang");
PhillippinesHeroes.add("Maria Josefa Gabriela Silang");
PhillippinesHeroes.add("Lapu-Lapu");
PhillippinesHeroes.add("Francisco Baltazar");
PhillippinesHeroes.add("Epifanio delos Santos");
PhillippinesHeroes.add("Francisco Dagohoy");
PhillippinesHeroes.add("Teresa Magbanua");
PhillippinesHeroes.add("Trinidad Tecson");
PhillippinesHeroes.add("Agueda Esteban");
PhillippinesHeroes.add("Julian Felipe");
PhillippinesHeroes.add("Marina Dizon");
PhillippinesHeroes.add("General Francisco Makabulos");
List<String> Presidents = new ArrayList<String>();
Presidents.add("Emilio Aguinaldo");
Presidents.add("Manuel L. Quezon");
Presidents.add("José P. Laurel");
Presidents.add("Sergio S. Osmeña");
Presidents.add("Manuel A. Roxas");
Presidents.add("Elpidio R. Quirino");
Presidents.add("Ramón F. Magsaysay");
Presidents.add("Carlos P. García");
Presidents.add("Diosdado P. Macapagal");
Presidents.add("Ferdinand E. Marcos");
Presidents.add("Corazón C. Aquino");
Presidents.add("Fidel V. Ramos");
Presidents.add("Joseph Ejército Estrada");
Presidents.add("Gloria Macapagal Arroyo");
Presidents.add("Benigno S. Aquino III");
List<String> CultureAndTradition = new ArrayList<String>();
CultureAndTradition.add("");
CultureAndTradition.add("");
CultureAndTradition.add("");
CultureAndTradition.add("");
CultureAndTradition.add("");
CultureAndTradition.add("");
List<String> TouristSpots = new ArrayList<String>();
TouristSpots.add("Manila");
TouristSpots.add("Bohol");
TouristSpots.add("Boracay");
TouristSpots.add("baguio");
TouristSpots.add("Cagayan");
TouristSpots.add("Cagayan De Oro");
TouristSpots.add("Camiguin");
TouristSpots.add("Cebu");
TouristSpots.add("Davao City");
TouristSpots.add("Ilocos Norte");
TouristSpots.add("Negros Oriental");
TouristSpots.add("Puerto Prencesa");
TouristSpots.add("Zambales");
List<String> FilipinoDishes = new ArrayList<String>();
FilipinoDishes.add("Adobo");
FilipinoDishes.add("Balut");
FilipinoDishes.add("Lechon");
FilipinoDishes.add("Sisig");
FilipinoDishes.add("Crispy Pata");
FilipinoDishes.add("Chicken Inasal");
FilipinoDishes.add("Pansit Palabok");
FilipinoDishes.add("Bulalo");
FilipinoDishes.add("Arroz Caldo");
FilipinoDishes.add("Kare-Kare");
FilipinoDishes.add("Sinigang");
FilipinoDishes.add("Dinuguan at puto");
FilipinoDishes.add("Laing");
FilipinoDishes.add("Pinakbet");
FilipinoDishes.add("Bicol Express");
FilipinoDishes.add("Tinola");
FilipinoDishes.add("Halo-Halo");
FilipinoDishes.add("Taho");
FilipinoDishes.add("Turon");
FilipinoDishes.add("Longaniza");
FilipinoDishes.add("Lumpiang Sariwa");
List<String> TraditionalCustomes = new ArrayList<String>();
TraditionalCustomes.add("Barong Tagalog");
TraditionalCustomes.add("Mestiza");
TraditionalCustomes.add("Maria Clara");
TraditionalCustomes.add("Kimona");
TraditionalCustomes.add("Igorot");
TraditionalCustomes.add("Muslim Attire");
TraditionalCustomes.add("Malong");
TraditionalCustomes.add("B’LAAN");
TraditionalCustomes.add("Bagobo")
TraditionalCustomes.add("T’BOLI");
TraditionalCustomes.add("Mandaya");
TraditionalCustomes.add("Maranaw");
TraditionalCustomes.add("Yakan");
TraditionalCustomes.add("Ifugao");
TraditionalCustomes.add("Kalinga");
TraditionalCustomes.add("GA’DANG");
TraditionalCustomes.add("Bontoc");
TraditionalCustomes.add("Samal");
TraditionalCustomes.add("Ibaloi");
TraditionalCustomes.add("Aetas");
TraditionalCustomes.add("Pulangiyen");
TraditionalCustomes.add("Matigsalug");
List<String> TraditionalGames = new ArrayList<String>();
TraditionalGames.add("Tumbang Preso");
TraditionalGames.add("Luksong-Baka");
TraditionalGames.add("Luksong-tinik");
TraditionalGames.add("Piko");
TraditionalGames.add("Agawan Base");
TraditionalGames.add("Bahay-Bahayan");
TraditionalGames.add("Chinese Garter");
TraditionalGames.add("Holen");
TraditionalGames.add("Jack 'n' Poy");
TraditionalGames.add("Langit-Lupa");
TraditionalGames.add("Pitik-Bulag");
TraditionalGames.add("Sawsaw-Suka");
TraditionalGames.add("Sipa");
TraditionalGames.add("Taguan");
TraditionalGames.add("Takip-Silim");
TraditionalGames.add("Ten-Twenty");
TraditionalGames.add("Tinikling");
TraditionalGames.add("Ubusan Lahi");
TraditionalGames.add("Teks");
// Header at Child data
listDataChild.put(listDataHeader.get(0), PhillippinesHeroes);
listDataChild.put(listDataHeader.get(1), Presidents);
listDataChild.put(listDataHeader.get(2), CultureAndTradition);
listDataChild.put(listDataHeader.get(3), TouristSpots);
listDataChild.put(listDataHeader.get(4), FilipinoDishes);
listDataChild.put(listDataHeader.get(5), TraditionalCustomes);
listDataChild.put(listDataHeader.get(6), TraditionalGames);
}
}
/ **********扩展Listview适配器(ELAdapter.java)************************* ****************** /
package filipiknows.open;
import filipiknows.open.R;
import java.util.HashMap;
import java.util.List;
import android.content.Context;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.TextView;
public class ELAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<String> _listDataHeader; // header titles
// child data in format of header title, child title
private HashMap<String, List<String>> _listDataChild;
public ELAdapter(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.lblListHeader);
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;
}
}
答案 0 :(得分:0)
由于我不完全确定你要做什么,这就是id如何开始一个带有textview的活动,它显示了被点击的人文本。
ClickListener的实现
@Override
public boolean onChildClick(ExpandableListView parent, View v,int groupPosition, int childPosition, long id) {
// TODO Auto-generated method stub
Intent i = new Intent(this, DetailsActivity.class);
i.putExtra("Name", listDataChild.get(this.listDataHeader.get(groupPosition)).get(childPosititon));
startActivity(i);
return true;
}
显示文字的简单活动
public class DetailsActivity extends Activity {
TextView tv;
public View onCreate(SavedInstanceState bundle) {
tv = new TextView(this);
return tv;
}
public void onResume() {
super.onResume();
tv.setText(getIntent().getStringExtra("Name", "SomeDefaultValue"));
}
}
这应该说明如何做到这一点,如果你不能适应你的需要,你可能想看一个教程:)