如何集合发送列表项的HttpPost以及微调器和复选框

时间:2012-05-07 10:05:34

标签: android listview checkbox http-post spinner

我在一个布局中有一个ListView,复选框和微调器,在不同的布局上,我通过从xml解析它来调用listview项。如何使用http post集体发送checkbox,spinner和列表视图项名称的值 我想要详细解释代码。

这是我的活动,我已经解析成xml并将其声明为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);
        }

这是我的pizzahut.xml,其中只是我的列表视图和提交按钮

<?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>

这是我的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>

每当我点击按钮检查[pizzahut.xml和PizzaHut.java]

我希望HTTPPost菜单项名称[从xmlparsing获取],复选框值如果选中,则微调器值合在一起。请给我完整的解释。

1 个答案:

答案 0 :(得分:0)

从上面的代码中我发现您从XML解析中获得了标题,描述和成本价值。您可以从XML获取此值并通过以下代码将其传递给您的其他活动

list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

                HashMap<String, String> data = menuItems.get(position);

                String title = data.get("foodjoint_name");
                String description = data.get("foodjoint_description");
                String price = data.get("foodjoint_latitude");


                Intent personal = new Intent(this, UserPersonal.class);
            startActivity(personal);
                in.putExtra("title", title);
                in.putExtra("descp", description);
                in.putExtra("DURATION", pubdate);
                in.putExtra("URL", imagename);
                startActivity(personal);

            }
        }); 

在其他活动中,您可以通过以下代码

来检索此内容
Bundle extras = getIntent().getExtras(); 
        if(extras !=null)
        {
            Title = extras.getString("title");
            Description = extras.getString("descp");
            ImageUrl = extras.getString("URL");
        }