0

嗨,我写了一个 xml 解析示例。这里我必须从 mysql 数据库中获取数据信息并成功显示在 android 模拟器中。这是我的代码:

    public class CustomizedListView extends Activity {
// All static variables
static final String URL = "http://192.168.1.168/xcart432pro/orderdetails.xml";
// XML node keys
static final String KEY_SONG = "Order"; // parent node
static final String KEY_ID = "orderid";
static final String KEY_TITLE = "orderid";
static final String KEY_ARTIST = "payment_method";
static final String KEY_DURATION = "total";


ListView list;
    LazyAdapter adapter;

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


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

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

    NodeList nl = doc.getElementsByTagName(KEY_SONG);
    // looping through all song nodes <song>
    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_TITLE, parser.getValue(e, KEY_TITLE));
        map.put(KEY_ARTIST, parser.getValue(e, KEY_ARTIST));
        map.put(KEY_DURATION, parser.getValue(e, KEY_DURATION));

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


    list=(ListView)findViewById(R.id.list);

    // Getting adapter by passing xml data ArrayList
    adapter=new LazyAdapter(this, songsList);        
    list.setAdapter(adapter);


    // Click event for single list row
    list.setOnItemClickListener(new OnItemClickListener() {

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

            String Orderid= ((TextView) view.findViewById(R.id.title)).getText().toString();
            String Price = ((TextView) view.findViewById(R.id.duration)).getText().toString();

            String Description = ((TextView) view.findViewById(R.id.artist)).getText().toString();

            // Starting new intent
            Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);

             in.putExtra(KEY_TITLE, Orderid);
            in.putExtra(KEY_DURATION, Price);
            in.putExtra(KEY_ARTIST, Description);
            startActivity(in);                  
        }
    });     
}   
     }

dis 是我的 singlemenuitem.java 类是:

    public class SingleMenuItemActivity  extends Activity {

// XML node keys

static final String KEY_TITLE = "orderid";
static final String KEY_ARTIST = "payment_method";
static final String KEY_DURATION = "total";
@Override

    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.single_list_item);

    // getting intent data
    Intent in = getIntent();

    // Get XML values from previous intent
    String product = in.getStringExtra(KEY_DURATION);
    String login = in.getStringExtra(KEY_TITLE);
    String description = in.getStringExtra(KEY_ARTIST);

    // Displaying all values on the screen
    TextView lblName = (TextView) findViewById(R.id.name_label);

    TextView lblPName = (TextView) findViewById(R.id.cost_label);
    TextView lblDesc = (TextView) findViewById(R.id.description_label);

    lblName.setText(login);

    lblPName.setText(product);
    lblDesc.setText(description);
    }


    }

在这里我必须成功显示在android模拟器上。但我希望仅在第一页显示 orderid 和 payment_method。然后它移动到下一页意味着必须显示该特定 id 的总数。请给我解决方案。我该怎么做。我希望我的输出是: 在此处输入图像描述

如果我点击 13 表示特定订单总额仅显示在下一个活动中。

在此处输入图像描述

怎么办。请帮帮我。

4

2 回答 2

1

我得到了答案。如果您需要通过添加 andorid:visibility="gone" 到 xml 文件中的描述标签来隐藏“描述”字段。这样提交的描述将出现在列表视图中,但不可见。

于 2012-08-07T04:28:32.417 回答
0
 Intent in = new Intent(getApplicationContext(), SingleMenuItemActivity.class);

         in.putExtra("KEY_TITLE", Orderid);
        in.putExtra("KEY_DURATION", Price);
        in.putExtra("KEY_ARTIST", Description);
        startActivity(in);

单菜单项.java

            product = getIntent().getExtras().getString("KEY_TITLE");
            login = getIntent().getExtras().getString("KEY_DURATION");
            description = getIntent().getExtras().getInt("KEY_ARTIST");      
于 2012-08-04T04:48:07.417 回答