1
我有一個可擴展的列表視圖,它是動態生成的,子列表包含另一組值,我需要在子列表上設置一個onChildClickListener,以便通過每個數據中保存的特定URL傳遞一個Web intent子列表。因此,我需要訪問每個OnChildClickListener事件上的子列表的值。如何使用onChildClickListener提取expandablelistview中的子值?
請幫忙!! 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;
}
我想提取在特定羣體和孩子位置上的價值添加此代碼。上面的代碼將返回位置,而我想要在那裏保存值。 –
你可以發佈關於如何從適配器中提取數據的代碼,因爲該位是我特別尋找的。 –
現在看看我的答案我現在編輯它。您必須在點擊子項時通過傳遞位置值來返回數據。 –