1

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

这是我已解析为 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 ],复选框值(如果选中),微调器值一起。请给我完整的解释。

4

1 回答 1

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");
        }
于 2012-05-08T06:07:42.843 回答