我是Android新手。我想在可展開的listview子項被點擊時開始一個活動。我已經尋找了幾個小時試圖找到一個解決方案,但我沒有找到任何適當的解決方案。有人請爲此問題提供代碼。如何在可展開列表視圖(手風琴)子項單擊時啓動活動
package com.demo.spry.acordion1;
import java.util.ArrayList;
import android.app.ExpandableListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ExpandableListView;
import android.widget.ExpandableListView.OnChildClickListener;
import android.widget.Toast;
public class MainActivity extends ExpandableListActivity implements
OnChildClickListener {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ExpandableListView expandbleLis = getExpandableListView();
expandbleLis.setDividerHeight(2);
expandbleLis.setGroupIndicator(null);
expandbleLis.setClickable(true);
setGroupData();
setChildGroupData();
adapter.setInflater((LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE), this);
expandableList.setAdapter(adapter);
adapter.notifyDataSetChanged();
expandableList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
Intent myIntent = new Intent(MainActivity.this, Main5Activity.class);
MainActivity.this.startActivity(myIntent);
return false;
}
});
public void setGroupData() {
groupItem.add("Car Details");
groupItem.add("Appointment Details");
/* groupItem.add("Manufacturer");
groupItem.add("Extras");*/
}
ArrayList<String> groupItem = new ArrayList<String>();
ArrayList<Object> childItem = new ArrayList<Object>();
public void setChildGroupData() {
/**
* Add Data For TecthNology
*/
ArrayList<String> child = new ArrayList<String>();
child.add("Java");
child.add("Drupal");
child.add(".Net Framework");
child.add("PHP");
childItem.add(child);
/**
* Add Data For Mobile
*/
child = new ArrayList<String>();
child.add("Android");
child.add("Window Mobile");
child.add("iPHone");
child.add("Blackberry");
childItem.add(child);
}
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
Toast.makeText(MainActivity.this, "Clicked On Child",
Toast.LENGTH_SHORT).show();
return true;
}
}
你的代碼在哪裏??? –
你可以在谷歌找到它 –
你必須發佈你的代碼才能得到正確的答案。 – Firefog