Android 如何使用onChildClickListener在expandablelistview中提取子级的值?
我有一个动态生成的可扩展列表视图,子列表包含另一组值,我需要在子列表上设置onChildClickListener,以便通过每个子列表的数据中包含的特定URL传递web意图。因此,我需要在每个OnChildClickListener事件上访问子列表的值 请帮忙!! PS:如果需要任何进一步的解释或代码,请评论Android 如何使用onChildClickListener在expandablelistview中提取子级的值?,android,dynamic,android-intent,expandablelistview,Android,Dynamic,Android Intent,Expandablelistview,我有一个动态生成的可扩展列表视图,子列表包含另一组值,我需要在子列表上设置onChildClickListener,以便通过每个子列表的数据中包含的特定URL传递web意图。因此,我需要在每个OnChildClickListener事件上访问子列表的值 请帮忙!! PS:如果需要任何进一步的解释或代码,请评论 @Override protected void onPostExecute(JSONObject result) { dialog.dismiss
@Override
protected void onPostExecute(JSONObject result)
{
dialog.dismiss();
onPostCreate(new Bundle());
List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
try
{
JSONObject data = result.getJSONObject("data");
else
{
JSONArray jarray = data.getJSONArray("data");
for (int i = 0; i < jarray.length(); i++)
{
JSONObject obj = (JSONObject) jarray.get(i);
String taskId = obj.getString("taskId");
String taskSub = obj.getString("taskSubject");
String v1= "Task Subject :"+taskSub;
Map<String, String> curGroupMap = new HashMap<String, String>();
groupData.add(curGroupMap);
curGroupMap.put(TAG,v1);
List<Map<String, String>> children = new ArrayList<Map<String, String>>();
Map<String, String> curChildMap = new HashMap<String, String>();
children.add(curChildMap);
curChildMap.put(TAG," "+taskId);
childData.add(children);
}
//ADAPTER SETTINGS
mAdapter = new SimpleExpandableListAdapter(
Search.this,
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { TAG },
new int[] { android.R.id.text1},
childData,
android.R.layout.simple_expandable_list_item_2,
new String[] { TAG },
new int[] { android.R.id.text1 }
);
setListAdapter(mAdapter);
getExpandableListView().setOnChildClickListener(Search.this);
}
}
catch (JSONException je)
{
je.printStackTrace();
Log.d(TAG, "Error: " + je.getMessage());
}
}
}
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
int childPosition, long id)
{
Uri webpage = Uri.parse("URL"+taskId);
//I want to add the taskId i am extracting in my dynamic expandable list in the URL, therefore each URL will be unique according to the taskId.
Intent webIntent = new Intent(Intent.ACTION_VIEW, webpage);
PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(webIntent, 0);
boolean isIntentSafe = activities.size() > 0;
if (isIntentSafe)
{
startActivity(webIntent);
}
return true;
}
@覆盖
受保护的void onPostExecute(JSONObject结果)
{
dialog.dismise();
onpostreate(新Bundle());
List groupData=new ArrayList();
List childData=new ArrayList();
尝试
{
JSONObject data=result.getJSONObject(“数据”);
其他的
{
JSONArray jarray=data.getJSONArray(“数据”);
for(int i=0;i0;
如果(isIntentSafe)
{
startActivity(webIntent);
}
返回true;
}
为子对象添加侦听器单击侦听器
getExpandableListView().setOnChildClickListener(this);
为click listener添加代码
@Override
public boolean onChildClick(ExpandableListView parent, View v, int groupPos, int childPos, long id) {
// use groupPosition and childPosition to get the item data from adapter.
return true;
}
在适配器中添加此代码
@Override
//gets the name of each item
public Object getChild(int i, int i1) {
return dataList.get(i).getArrayChildren().get(i1);
}
我想提取特定组和子位置上的值。上面的代码将只返回位置,而我希望值保留在那里。您能否发布代码,说明如何从适配器中提取数据,因为该位正是我特别想要的。现在查看我的答案,我正在编辑它。当您单击子项时,必须通过传递位置值来返回数据。我假设I和i1分别是组和子位置。需要一些关于mParent的帮助,因为如果我试图修复expandablelistview父级,它会抛出一个错误。mParent意味着它是一个类似ArrayList的数据列表,从活动传递到适配器,您希望在expandablelistview中显示的内容。。