Android Webview和Expandablelistview的子元素
我使用一个带有父元素和子元素的ExpandableListView,我会在webview活动中抛出son发送给我的un'intent。当然,webview加载的url对于所有figli.Grazie应该是相同的 这是主要的活动, 公共类MainActivity扩展了AppCompatActivity{Android Webview和Expandablelistview的子元素,android,Android,我使用一个带有父元素和子元素的ExpandableListView,我会在webview活动中抛出son发送给我的un'intent。当然,webview加载的url对于所有figli.Grazie应该是相同的 这是主要的活动, 公共类MainActivity扩展了AppCompatActivity{ private WebView mWebView; @Override protected void onCreate(Bundle savedInstanceState) { supe
private WebView mWebView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// INI AGREGADO
mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setLoadWithOverviewMode(true);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setBuiltInZoomControls(true);
mWebView.setWebViewClient(new com.example.m_bua.superapp.org.donboscoapp.MyAppWebViewClient());
// Url que carga la app (webview)
mWebView.loadUrl("https://drive.google.com/folderview? id=0B009g1A1bhY7cDZlR2k0c0VYck0");
// Forzamos el webview para que abra los enlaces internos dentro de la la APP
mWebView.setWebViewClient(new WebViewClient());
// FIN AGREGADO
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
// INI AGREGADO
@Override
// Detectar cuando se presiona el botón de retroceso
public void onBackPressed() {
if(mWebView.canGoBack()) {
mWebView.goBack();
} else {
super.onBackPressed();
}
}
//Inserisco il menu' overflow
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
//Inserisco la selezione dell'item sul menù overflow e lancio l'intent sull'item//
@Override
public boolean onOptionsItemSelected(MenuItem item){
int id = item.getItemId();
if (id == R.id.primo) {
Intent intent = new Intent (this, com.example.m_bua.superapp.org.donboscoapp.MainActivityList.class);
startActivity(intent);
return true;
}
return super.onOptionsItemSelected(item);
}
}
我的主要活动列表
public class MainActivityList extends Activity {
private ExpandableListView mExpandableListView;
private List<GroupEntity> mGroupCollection;
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
/**
* Called when the activity is first created.
*/
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
prepareResource();
initPage();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client = new GoogleApiClient.Builder(this).addApi(AppIndex.API).build();
}
private void prepareResource() {
mGroupCollection = new ArrayList<GroupEntity>();
GroupEntity GA = new GroupEntity();{
GA.Name = "Tornei Pulcini 2005" ;
GroupEntity GB = new GroupEntity();
GB.Name="Tornei Pulcini 2006 ";
GroupEntity GC = new GroupEntity();
GC.Name="Tornei Pulcini 2007 ";
GroupEntity GD = new GroupEntity();
GD.Name="Tornei Piccoli Amici 2008 ";
GroupEntity GE = new GroupEntity();
GE.Name="Tornei Piccoli Amici 2009 ";
GroupItemEntity Primo2005 = GA.new GroupItemEntity();{
Primo2005.Name = "Nessun Torneo In Evidenza";
GA.GroupItemCollection.add(Primo2005);
GroupItemEntity Primo2006 = GB.new GroupItemEntity();
Primo2006.Name = "Nessun Torneo In Evidenza";
GB.GroupItemCollection.add(Primo2006);
GroupItemEntity Primo2007 = GC.new GroupItemEntity();
Primo2007.Name = "Nessun Torneo In Evidenza";
GC.GroupItemCollection.add(Primo2007);
GroupItemEntity Primo2008 = GD.new GroupItemEntity();
Primo2008.Name = "Torneo Pianazze";
GD.GroupItemCollection.add(Primo2008);
GroupItemEntity Primo2009 = GE.new GroupItemEntity();
Primo2009.Name = "Nessun Torneo In Evidenza";
GE.GroupItemCollection.add(Primo2009);
}
mGroupCollection.add(GA);
mGroupCollection.add(GB);
mGroupCollection.add(GC);
mGroupCollection.add(GD);
mGroupCollection.add(GE);
}
}
private void initPage() {
mExpandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
ExpandableListAdapter adapter = new ExpandableListAdapter(this,
mExpandableListView, mGroupCollection);
mExpandableListView.setAdapter(adapter);
}
@Override
public void onStart() {
super.onStart();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
client.connect();
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"MainActivityList Page", // TODO: Define a title for the content shown.
// TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android- app://com.example.m_bua.superapp.org.donboscoapp/http/host/path")
);
AppIndex.AppIndexApi.start(client, viewAction);
}
@Override
public void onStop() {
super.onStop();
// ATTENTION: This was auto-generated to implement the App Indexing API.
// See https://g.co/AppIndexing/AndroidStudio for more information.
Action viewAction = Action.newAction(
Action.TYPE_VIEW, // TODO: choose an action type.
"MainActivityList Page", // TODO: Define a title for the content shown. // TODO: If you have web page content that matches this app activity's content,
// make sure this auto-generated web page URL is correct.
// Otherwise, set the URL to null.
Uri.parse("http://host/path"),
// TODO: Make sure this auto-generated app deep link URI is correct.
Uri.parse("android-app://com.example.m_bua.superapp.org.donboscoapp/http/host/path")
);
AppIndex.AppIndexApi.end(client, viewAction);
client.disconnect();
}
}
公共类MainActivityList扩展活动{
私有可扩展列表视图mExpandableListView;
私人名单收集;
/**
*注意:这是自动生成的,用于实现应用程序索引API。
*看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
*/
私人谷歌客户;
/**
*在首次创建活动时调用。
*/
@凌驾
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
prepareResource();
initPage();
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
client=new GoogleApiClient.Builder(this.addApi(AppIndex.API).build();
}
私有void prepareResource(){
mGroupCollection=新的ArrayList();
GroupEntity GA=新的GroupEntity(){
GA.Name=“托尔内普尔奇尼2005”;
GroupEntity GB=新的GroupEntity();
GB.Name=“Tornei Pulcini 2006”;
GroupEntity GC=新的GroupEntity();
GC.Name=“Tornei Pulcini 2007”;
GroupEntity GD=新的GroupEntity();
GD.Name=“Tornei Piccoli Amici 2008”;
GroupEntity GE=新的GroupEntity();
GE.Name=“Tornei Piccoli Amici 2009”;
GroupItemEntity Primo2005=GA.new GroupItemEntity(){
Primo2005.Name=“证据中的Nessun Torneo”;
GA.GroupItemCollection.add(Primo2005);
GroupItemEntity Primo2006=GB.new GroupItemEntity();
Primo2006.Name=“证据中的Nessun Torneo”;
GB.GroupItemCollection.add(Primo2006);
GroupItemEntity Primo2007=GC.new GroupItemEntity();
Primo2007.Name=“证据中的Nessun Torneo”;
GC.GroupItemCollection.add(Primo2007);
GroupItemEntity Primo2008=GD.new GroupItemEntity();
Primo2008.Name=“Torneo Pianazze”;
GD.GroupItemCollection.add(Primo2008);
GroupItemEntity Primo2009=GE.new GroupItemEntity();
Primo2009.Name=“证据中的Nessun Torneo”;
GE.GroupItemCollection.add(Primo2009);
}
mGroupCollection.add(GA);
mGroupCollection.add(GB);
mGroupCollection.add(GC);
mGroupCollection.add(GD);
mGroupCollection.add(通用电气);
}
}
私有void initPage(){
mExpandableListView=(ExpandableListView)findViewById(R.id.ExpandableListView);
ExpandableListAdapter=新的ExpandableListAdapter(此,
mExpandableListView,mGroupCollection);
setAdapter(适配器);
}
@凌驾
public void onStart(){
super.onStart();
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
client.connect();
Action viewAction=Action.newAction(
Action.TYPE\u视图,//TODO:选择一种操作类型。
“MainActivityList页面”//TODO:为显示的内容定义标题。
//TODO:如果您的网页内容与此应用程序活动的内容匹配,
//确保此自动生成的网页URL正确无误。
//否则,请将URL设置为null。
解析http://host/path"),
//TODO:确保此自动生成的应用程序深度链接URI正确。
解析app://com.example.m_bua.superapp.org.donboscoapp/http/host/path")
);
AppIndex.AppIndexApi.start(客户端,viewAction);
}
@凌驾
公共void onStop(){
super.onStop();
//注意:这是自动生成的,用于实现应用程序索引API。
//看https://g.co/AppIndexing/AndroidStudio 了解更多信息。
Action viewAction=Action.newAction(
Action.TYPE\u视图,//TODO:选择一种操作类型。
“MainActivityList页面”//TODO:为显示的内容定义标题//TODO:如果您的网页内容与此应用程序活动的内容匹配,
//确保此自动生成的网页URL正确无误。
//否则,请将URL设置为null。
解析http://host/path"),
//TODO:确保此自动生成的应用程序深度链接URI正确。
解析-app://com.example.m_bua.superapp.org.donboscoapp/http/host/path")
);
AppIndex.AppIndexApi.end(客户端,viewAction);
client.disconnect();
}
}
我的可扩展列表适配器
public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context mContext;
private ExpandableListView mExpandableListView;
private List<GroupEntity> mGroupCollection;
private int[] groupStatus;
public ExpandableListAdapter(Context pContext,
ExpandableListView pExpandableListView,
List<GroupEntity> pGroupCollection) {
mContext = pContext;
mGroupCollection = pGroupCollection;
mExpandableListView = pExpandableListView;
groupStatus = new int[mGroupCollection.size()];
setListEvent();
}
private void setListEvent() {
mExpandableListView
.setOnGroupExpandListener(new OnGroupExpandListener() {
@Override
public void onGroupExpand(int arg0) {
// TODO Auto-generated method stub
groupStatus[arg0] = 1;
}
});
mExpandableListView
.setOnGroupCollapseListener(new OnGroupCollapseListener() {
@Override
public void onGroupCollapse(int arg0) {
// TODO Auto-generated method stub
groupStatus[arg0] = 0;
}
});
}
@Override
public String getChild(int arg0, int arg1) {
// TODO Auto-generated method stub
return mGroupCollection.get(arg0).GroupItemCollection.get(arg1).Name;
}
@Override
public long getChildId(int arg0, int arg1) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getChildView(int arg0, int arg1, boolean arg2, View arg3,
ViewGroup arg4) {
// TODO Auto-generated method stub
ChildHolder childHolder;
if (arg3 == null) {
arg3 = LayoutInflater.from(mContext).inflate(
R.layout.list_group_item, null);
childHolder = new ChildHolder();
childHolder.title = (TextView) arg3.findViewById(R.id.item_title);
arg3.setTag(childHolder);
}else {
childHolder = (ChildHolder) arg3.getTag();
}
childHolder.title.setText(mGroupCollection.get(arg0).GroupItemCollection.get(arg1).Name);
return arg3;
}
@Override
public int getChildrenCount(int arg0) {
// TODO Auto-generated method stub
return mGroupCollection.get(arg0).GroupItemCollection.size();
}
@Override
public Object getGroup(int arg0) {
// TODO Auto-generated method stub
return mGroupCollection.get(arg0);
}
@Override
public int getGroupCount() {
// TODO Auto-generated method stub
return mGroupCollection.size();
}
@Override
public long getGroupId(int arg0) {
// TODO Auto-generated method stub
return arg0;
}
@Override
public View getGroupView(int arg0, boolean arg1, View arg2, ViewGroup arg3) {
// TODO Auto-generated method stub
GroupHolder groupHolder;
if (arg2 == null) {
arg2 = LayoutInflater.from(mContext).inflate(R.layout.list_group,
null);
groupHolder = new GroupHolder();
groupHolder.img = (ImageView) arg2.findViewById(R.id.tag_img);
groupHolder.title = (TextView) arg2.findViewById(R.id.group_title);
arg2.setTag(groupHolder);
} else {
groupHolder = (GroupHolder) arg2.getTag();
}
if (groupStatus[arg0] == 0) {
groupHolder.img.setImageResource(R.drawable.group_down);
} else {
groupHolder.img.setImageResource(R.drawable.group_up);
}
groupHolder.title.setText(mGroupCollection.get(arg0).Name);
return arg2;
}
class GroupHolder {
ImageView img;
TextView title;
}
class ChildHolder {
TextView title;
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}
@Override
public boolean isChildSelectable(int arg0, int arg1) {
// TODO Auto-generated method stub
return true;
}
}
公共类ExpandableListAdapter扩展了BaseExpandableListAdapter{
私有上下文;
私有可扩展列表视图mExpandableListView;
私人名单收集;
私有int[]组状态;
公共ExpandableListAdapter(上下文pContext,
ExpandableListView PEExpandableListView,
列表(集合){
mContext=pContext;
mGroupCollection=pGroupCollection;
mExpandableListView=pExpandableListView;
groupStatus=newint[mGroupCollection.size()];
setListEvent();
}
私有void setListEvent(){
mExpandableListView
.setOnGroupExpandListener(新OnGroupExpandListener(){
@凌驾
public void onGroupExpand(int arg0){
//TODO自动生成的方法存根
groupStatus[arg0]=1;
}
});
mExpandableListView
.setOnGroupCollapseListener(新OnGroupCollapseListener(){
@凌驾
公共无效组折叠(int arg0){
//TODO自动生成的方法存根
groupStatus[arg0]=0;
}
});
}
@凌驾
公共字符串getChild(int arg0,int arg1){
//TODO自动生成的方法存根
返回mGroupCollection.get(arg0).GroupItemCollection.get(arg1).Name;
}
@凌驾
公共长getChildId(int arg0,in