Not Getting Listview Selected Item To Next Activity Using Json Android?
Solution 1:
Here is how you can modify your php code to get only required sub menu items. In the code I assume there is menu_type field in your main_menu_items table. Replace it with the actual field name.
<?phpinclude ('config.php');
$id = $_GET['id'];
/* assuming main_menu_items table has field "menu_type" */$stmt = $mysqli->prepare("SELECT * FROM main_menu_items WHERE menu_type=?");
$stmt->bind_param("i", $id)
/*now only submenu items of given type will be selected*/$sql = mysqli_query($conn, $stmt);
$arr = array();
$i=0;
while($result = mysqli_fetch_array($sql))
{
$arr[$i]['id']= $result['id'];
$arr[$i]['name']= $result['name'];
$arr[$i]['image']=$result['image'];
$i++;
}
echo json_encode($arr);
?>
In your SubMenu activity you need to read the Id value from extras and pass it to the php webpage as a parameter. For that you need to replace this code line:
jsonarray = JsonFunctions
.getJSONfromURL("http://cloud.granddubai.com/broccoli/menu_typeitem.php");
with the following:
jsonarray = JsonFunctions
.getJSONfromURL("http://cloud.granddubai.com/broccoli/menu_typeitem.php?id=" + getIntent.getStringExtra("id"));
Also don't forget to pass the type id to the second activity as sohan shetty suggested in his answer.
Solution 2:
Since you are passing selected id to next activity , So get your passed id through intent in SubMenu activity and do api call with that id to get your relevant response and upate your listview
Edited
Pass your selected id to SubMenu activity inside onItemClick like this
@Override
publicvoidonItemClick(AdapterView<?> parent, View view, int position, long id) {
// getting values from selected ListItem
HashMap<String, String> selected = contactList.get(position);
String selectedId= selected.get("id");
Intent in = new Intent(getApplicationContext(), SubMenu.class);
// sending pid to next activityin.putExtra("id",selectedId);
startActivityForResult(in, 100);
Toast.makeText(getApplicationContext(),"Toast" +type_items ,Toast.LENGTH_LONG).show();
}
});
Now get your selectedId throug extras like this in submenu activity and request server to get respective response
StringSelectedId= getIntent.getStringExtra("id");
Post a Comment for "Not Getting Listview Selected Item To Next Activity Using Json Android?"