gpt4 book ai didi

android - 如何使用 onChildClickListener 在 expandablelistview 中提取 child 的值(value)?

转载 作者:行者123 更新时间:2023-11-29 21:45:16 26 4
gpt4 key购买 nike

我有一个动态生成的可扩展 ListView ,子列表包含另一组值,我需要在子列表上设置一个 onChildClickListener,以便通过数据中保存的特定 URL 传递 Web Intent 每个 child 名单。因此,我需要在每个 OnChildClickListener 事件中访问子列表的值。

请帮忙!!PS:如果需要任何进一步的解释或代码,请评论。

    @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;
}

最佳答案

为子点击监听器添加监听器

getExpandableListView().setOnChildClickListener(this);

为点击监听器添加代码。

@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);
}

关于android - 如何使用 onChildClickListener 在 expandablelistview 中提取 child 的值(value)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16007844/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com