Tuesday, May 8, 2012

How to send HttpPost of a list item and a spinner and a checkbox collectively

I have a ListView ,checkbox and spinner in one layout , and on different layout i have called the listview item by parsing it from xml. how to send collectively the value of checkbox , spinner and the list view item names by using http post
I want the detail code for explanation.



Here is my activity where i have parsed into xml and declared it into listview



public class Hut extends ListActivity {


static final String URL = "http://192.168.1.112/andro/index.php/androctrl/provider_detail/";

// XML node keys
static final String KEY_ITEM = "element"; // parent node
static final String KEY_ID = "foodjoint_id";
static final String KEY_NAME = "foodjoint_name";
static final String KEY_LAT = "foodjoint_latitude";
static final String KEY_DESC = "foodjoint_description";


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.pizzahut);



ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>>();

XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element

NodeList nl = doc.getElementsByTagName(KEY_ITEM);
// looping through all item nodes <item>
for (int i = 0; i < nl.getLength(); i++) {
// creating new HashMap
HashMap<String, String> map = new HashMap<String, String>();
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
map.put(KEY_ID, parser.getValue(e, KEY_ID));
map.put(KEY_NAME, parser.getValue(e, KEY_NAME));
map.put(KEY_LAT, "Rs." + parser.getValue(e, KEY_LAT));
map.put(KEY_DESC, parser.getValue(e, KEY_DESC));

// adding HashList to ArrayList
menuItems.add(map);
}

// Adding menuItems to ListView
ListAdapter adapter = new SimpleAdapter(this, menuItems,
R.layout.list_item,
new String[] { KEY_NAME, KEY_DESC, KEY_LAT }, new int[] {
R.id.name, R.id.desciption, R.id.cost });

setListAdapter(adapter);

// selecting single ListView item
ListView lv = getListView();





}
//the continue button
public void onClick(View v)
{
Intent personal = new Intent(this, UserPersonal.class);
startActivity(personal);
}


here is my pizzahut.xml where is just my list view and button to submit



<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white" >
<RelativeLayout
android:id="@+id/RelativeLayout1"
android:layout_width="181dp"
android:layout_height="504dp"
android:background="@color/white"
android:gravity="fill"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="216dp"
android:layout_height="483dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true" >

</ListView>






<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="@string/picktime" />

</RelativeLayout>

</ScrollView>


Here is my list_item.xml



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="483dp"
android:orientation="vertical" >

<!-- Name Label -->

<TextView
android:id="@+id/name"
android:layout_width="104dp"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="#dc6800"
android:textSize="16sp"
android:textStyle="bold" />

<!-- Description label -->
<TextView
android:id="@+id/desciption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#acacac"
android:paddingBottom="2dip">
</TextView>
<!-- Linear layout for cost and price Cost: Rs.100 -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Cost Label -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#5d5d5d"
android:gravity="left"
android:textStyle="bold"
android:text="Cost: " >
</TextView>
<!-- Price Label -->
<TextView
android:id="@+id/cost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#acacac"
android:textStyle="bold"
android:gravity="left">
</TextView>

</LinearLayout>

<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox" />


<Spinner
android:id="@+id/spinner1"
android:layout_width="118dp"
android:layout_height="wrap_content" />

</LinearLayout>

</LinearLayout>


whenever i will click on button check [ pizzahut.xml and PizzaHut.java]



i want to HTTPPost menu item name [got from xmlparsing ] , the checkbox value if selected , the spinner value togetherly.please give me the complete explanation.





No comments:

Post a Comment