0

我想显示来自listviews android的详细信息数据,我做到了......但问题是,我不知道如何通过单击基于listview数据的下一个/上一个按钮来创建一个函数来显示下一个/上一个详细数据.

这是我的第一个活动

    String[] values = new String[] { "Android Example ListActivity", "Adapter implementation", "Simple List View With ListActivity",
          "ListActivity Android", "Android Example", "ListActivity Source Code", "ListView ListActivity Array Adapter", "Android Example ListActivity" };
    // Binding Array to ListAdapter
    this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, values));

    ListView lv = getListView();

    // listening to single list item on click
    lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> parent, View view,
          int position, long id) {

          // selected item 
          String product = ((TextView) view).getText().toString();

          // Launching new Activity on selecting single List Item
          Intent intent = new Intent(getApplicationContext(), SingleListItem.class);
          // sending data to new activity
          intent .putExtra("product", product);
          intent.putExtra("pos",position);
          startActivity(intent);
      }
    });
}

}

这是我的第二个活动,我有详细信息我想从这两个按钮中放置两个按钮的下一个和上一个我想处理我的列表视图数据

    TextView txtProduct = (TextView) findViewById(R.id.product_label);

    Intent intent = getIntent();
    // getting attached intent data
    String product = getIntent().getStringExtra("product");
    int position=getIntent().getIntExtra("pos", 1);
    // displaying selected product name
    txtProduct.setText(" \n"+position+"  \n" +product);
    }
4

1 回答 1

0
//try this way
 String[] values = new String[] { "Android Example ListActivity", "Adapter implementation", "Simple List View With ListActivity",
                "ListActivity Android", "Android Example", "ListActivity Source Code", "ListView ListActivity Array Adapter", "Android Example ListActivity" };
        // Binding Array to ListAdapter
        this.setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, R.id.label, values));

        ListView lv = getListView();

        // listening to single list item on click
        lv.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {

                // selected item
                String product = ((TextView) view).getText().toString();

                // Launching new Activity on selecting single List Item
                Intent intent = new Intent(getApplicationContext(), SingleListItem.class);
                // sending data to new activity
                intent.putExtra("products", values);
                intent.putExtra("pos",position);
                startActivity(intent);
            }
        });



        Intent intent = getIntent();
        // getting attached intent data
        String[] product = getIntent().getStringArrayExtra("product");
        int position=getIntent().getIntExtra("pos", 1);
于 2013-09-19T11:50:40.753 回答