Android 从listview获取下一个和上一个详细信息数据

Android 从listview获取下一个和上一个详细信息数据,android,listview,button,next,detail,Android,Listview,Button,Next,Detail,我不知道如何通过单击基于listview的下一个/上一个按钮来创建显示下一个/上一个详细信息数据的函数 这是我想做的截图 ,以显示listview中的下一个/上一个数据 编辑:我有一个listview数据(使用xml解析器),并将数据传递给名为“Detail_toko.class”的新活动: List parameter=new ArrayList(); 添加(新的BasicNameValuePair(“关键字”,“a”)); //添加(新的BasicNameValuePair(“katego

我不知道如何通过单击基于listview的下一个/上一个按钮来创建显示下一个/上一个详细信息数据的函数

这是我想做的截图

,以显示listview中的下一个/上一个数据

编辑:我有一个listview数据(使用xml解析器),并将数据传递给名为“Detail_toko.class”的新活动:

List parameter=new ArrayList();
添加(新的BasicNameValuePair(“关键字”,“a”));
//添加(新的BasicNameValuePair(“kategori”,Category.getSelectedItem().toString());
XMLParser=新的XMLParser();
字符串xml=parser.getXmlFromUrl(URL,参数表);//从URL获取XML
Document doc=parser.getdoElement(xml);//获取DOM元素
NodeList nl=doc.getElementsByTagName(标记详细信息);
//循环通过所有歌曲节点
对于(int i=0;ivalue
put(TAG_ID,parser.getValue(e,TAG_ID));
put(TAG_NAMATOKO,parser.getValue(e,TAG_NAMATOKO));
put(TAG_KATEGORI,parser.getValue(e,TAG_KATEGORI));
map.put(TAG_EMAIL,parser.getValue(e,TAG_EMAIL));
put(TAG_图标,parser.getValue(e,TAG_图标));
//将哈希列表添加到ArrayList
PremiumList.add(地图);
} 
返回null;
}
/**
*将解析的JSON数据更新到ListView中
* */
list=(ListView)findViewById(R.id.ListView);
如果(PremiumList.size()>0)
{
adapter=新LazyAdapterStore(ListPerusahaan.this,PremiumList);
list.setAdapter(适配器);
}
其他的
{
Toast Toast=Toast.makeText(getApplicationContext(),“未找到数据,请输入另一个关键字”,Toast.LENGTH\u SHORT);
toast.setGravity(重力。重心垂直|重力。重心水平,0,0);
toast.show();
}
//单击单个列表行的事件
list.setOnItemClickListener(新的OnItemClickListener(){
@凌驾
public void onItemClick(AdapterView父级、视图、,
内部位置,长id){
//从选定的ListItem获取值
字符串nama_-toko=((TextView)view.findViewById(R.id.nama_-toko)).getText().toString();
字符串kategori=((TextView)view.findviewbyd(R.id.kategori)).getText().toString();
字符串email=((TextView)view.findviewbyd(R.id.email)).getText().toString();
PremiumList=newarraylist();
意向in=新意向(ListPerusahaan.this,Detail_toko.class);
in.putExtra(“PremiumList”,PremiumList);
//in.putStringArrayListExtra(“PremiumList”,PremiumList);
in.putExtra(“位置”,位置);
in.putExtra(“TotalData”,TotalData);
in.putExtra(TAG_NAMATOKO,nama_toko);
in.putExtra(TAG_KATEGORI,KATEGORI);
in.putExtra(标记电子邮件、电子邮件);
星触觉(in);
这是我的LazyAdapterStore代码:

  public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_data_store, null);

    TextView nama_toko = (TextView)vi.findViewById(R.id.nama_toko); // title
    TextView kategori = (TextView)vi.findViewById(R.id.kategori); // title
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image
    TextView email = (TextView)vi.findViewById(R.id.email); // artist name


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


    // Setting all values in listview
    nama_toko.setText(detail.get(ListPerusahaan.TAG_NAMATOKO));
    kategori.setText(detail.get(ListPerusahaan.TAG_KATEGORI));
    email.setText(detail.get(ListPerusahaan.TAG_EMAIL));
    imageLoader.DisplayImage(detail.get(ListPerusahaan.TAG_ICON), thumb_image);
    return vi;

}
public View getView(int位置、视图转换视图、视图组父视图){
视图vi=转换视图;
if(convertView==null)
vi=充气机充气(R.layout.list\u data\u store,空);
TextView-nama_-toko=(TextView)vi.findViewById(R.id.nama_-toko);//标题
TextView kategori=(TextView)vi.findviewbyd(R.id.kategori);//title
ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image);//thumb image
TextView电子邮件=(TextView)vi.findviewbyd(R.id.email);//艺术家姓名
HashMap detail=新的HashMap();
detail=data.get(位置);
//在listview中设置所有值
nama_toko.setText(detail.get(listpurusahaan.TAG_NAMATOKO));
setText(detail.get(listpureusahaan.TAG_kategori));
email.setText(detail.get(listpurusahaan.TAG_email));
imageLoader.DisplayImage(detail.get(ListPerusahaan.TAG_图标)、thumb_图像);
返回vi;
}
编辑:这是我的新活动“Detail_Toko”,用于显示listview项目中的详细数据:

@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

  //this must be called BEFORE setContentView
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.detail_toko);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

    call_btn=(Button)findViewById(R.id.call);

    email_btn=(Button)findViewById(R.id.email);

    sms_btn=(Button)findViewById(R.id.sms);

    Next_btn=(Button)findViewById(R.id.Next);

    Prev_btn=(Button)findViewById(R.id.Prev);

    phonenumber=(TextView)findViewById(R.id.telpon);


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

   // @SuppressWarnings("unchecked")
    //ArrayList<HashMap<String, String>> PremiumList = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("PremiumList");


    // Get String values from previous intent
    final String nama_toko = in.getStringExtra(TAG_NAMATOKO);
    final String kategori = in.getStringExtra(TAG_KATEGORI);
    final String email = in.getStringExtra(TAG_EMAIL);

    // Get Int values from previous intent
    final int posisi =  in.getExtras().getInt("position");
    final int Total_data =  in.getExtras().getInt("TotalData");

   /*
    Bundle bundle = in.getExtras(); 
    HashMap<String, String> list = (HashMap<String, String>) bundle.getSerializable("PremiumList");
    list = data.get(currentposition);
    */

    Bundle bundle = in.getExtras();
    HashMap<String, String> list =  (HashMap<String, String>) bundle.getSerializable("PremiumList");
    list = data.get(currentposition);

    // Displaying all values on the screen
    lblPosisi = (TextView) findViewById(R.id.namatoko);
    lbltotaldata = (TextView) findViewById(R.id.nama);
    lblNamatoko = (TextView) findViewById(R.id.nama_toko);
    lblKategori = (TextView) findViewById(R.id.kategori);
    lblEmail = (TextView) findViewById(R.id.textemail);

    lblPosisi.setText(String.valueOf(posisi));
    lbltotaldata.setText(String.valueOf(Total_data));
    lblNamatoko.setText(nama_toko);
    lblKategori.setText(kategori);
    lblEmail.setText(email);


    // Set the int value of currentposition from previous selected listview item
    currentposition = posisi;

    Next_btn.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v){  

          if(currentposition >= Total_data - 1)
          {
              Toast toast= Toast.makeText(getApplicationContext(), "Last Record", Toast.LENGTH_SHORT);  
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
              toast.show();
          }
          else
          {

              currentposition++;
              lblPosisi.setText(String.valueOf(currentposition));
              lblNamatoko.setText(list.get(nama_toko));
              lblKategori.setText(list.get(kategori));
              lblEmail.setText(list.get(email));


          }
        }
      });


    Prev_btn.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v){  

          if(currentposition <= 0)
          {
              Toast toast= Toast.makeText(getApplicationContext(), "First Record", Toast.LENGTH_SHORT);  
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
              toast.show();
          }
          else
          {
              currentposition--;
              lblPosisi.setText(String.valueOf(currentposition));
              lblNamatoko.setText(list.get(nama_toko));
              lblKategori.setText(list.get(kategori));
              lblEmail.setText(list.get(email));
          }


          }
     });
@覆盖
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//必须在setContentView之前调用此函数
requestWindowFeature(Window.FEATURE\u自定义\u标题);
setContentView(右布局详图);
getWindow().setFeatureInt(Window.FEATURE\u CUSTOM\u TITLE,R.layout.Window\u TITLE);
call_btn=(按钮)findviewbyd(R.id.call);
email_btn=(按钮)findviewbyd(R.id.email);
sms_btn=(按钮)findViewById(R.id.sms);
Next_btn=(按钮)findviewbyd(R.id.Next);
Prev_btn=(按钮)findViewById(R.id.Prev);
phonenumber=(TextView)findViewById(R.id.telpon);
//获取意图数据
Intent in=getIntent();
//@SuppressWarnings(“未选中”)
//ArrayList PremiumList=(ArrayList)getIntent().getSerializableExtra(“PremiumList”);
//从先前的意图中获取字符串值
最终字符串nama_toko=in.getStringExtra(TAG_NAMATOKO);
最终字符串kategori=in.getStringExtra(TAG_kategori);
最终字符串email=in.getStringExtra(TAG_email);
//从先前的意图中获取Int值
最终整数posisi
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

  //this must be called BEFORE setContentView
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.detail_toko);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

    call_btn=(Button)findViewById(R.id.call);

    email_btn=(Button)findViewById(R.id.email);

    sms_btn=(Button)findViewById(R.id.sms);

    Next_btn=(Button)findViewById(R.id.Next);

    Prev_btn=(Button)findViewById(R.id.Prev);

    phonenumber=(TextView)findViewById(R.id.telpon);


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

   // @SuppressWarnings("unchecked")
    //ArrayList<HashMap<String, String>> PremiumList = (ArrayList<HashMap<String, String>>) getIntent().getSerializableExtra("PremiumList");


    // Get String values from previous intent
    final String nama_toko = in.getStringExtra(TAG_NAMATOKO);
    final String kategori = in.getStringExtra(TAG_KATEGORI);
    final String email = in.getStringExtra(TAG_EMAIL);

    // Get Int values from previous intent
    final int posisi =  in.getExtras().getInt("position");
    final int Total_data =  in.getExtras().getInt("TotalData");

   /*
    Bundle bundle = in.getExtras(); 
    HashMap<String, String> list = (HashMap<String, String>) bundle.getSerializable("PremiumList");
    list = data.get(currentposition);
    */

    Bundle bundle = in.getExtras();
    HashMap<String, String> list =  (HashMap<String, String>) bundle.getSerializable("PremiumList");
    list = data.get(currentposition);

    // Displaying all values on the screen
    lblPosisi = (TextView) findViewById(R.id.namatoko);
    lbltotaldata = (TextView) findViewById(R.id.nama);
    lblNamatoko = (TextView) findViewById(R.id.nama_toko);
    lblKategori = (TextView) findViewById(R.id.kategori);
    lblEmail = (TextView) findViewById(R.id.textemail);

    lblPosisi.setText(String.valueOf(posisi));
    lbltotaldata.setText(String.valueOf(Total_data));
    lblNamatoko.setText(nama_toko);
    lblKategori.setText(kategori);
    lblEmail.setText(email);


    // Set the int value of currentposition from previous selected listview item
    currentposition = posisi;

    Next_btn.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v){  

          if(currentposition >= Total_data - 1)
          {
              Toast toast= Toast.makeText(getApplicationContext(), "Last Record", Toast.LENGTH_SHORT);  
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
              toast.show();
          }
          else
          {

              currentposition++;
              lblPosisi.setText(String.valueOf(currentposition));
              lblNamatoko.setText(list.get(nama_toko));
              lblKategori.setText(list.get(kategori));
              lblEmail.setText(list.get(email));


          }
        }
      });


    Prev_btn.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v){  

          if(currentposition <= 0)
          {
              Toast toast= Toast.makeText(getApplicationContext(), "First Record", Toast.LENGTH_SHORT);  
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
              toast.show();
          }
          else
          {
              currentposition--;
              lblPosisi.setText(String.valueOf(currentposition));
              lblNamatoko.setText(list.get(nama_toko));
              lblKategori.setText(list.get(kategori));
              lblEmail.setText(list.get(email));
          }


          }
     });
  /********Instead of getting your values like this*******************/
String nama_toko = in.getStringExtra(TAG_NAMATOKO);
String kategori = in.getStringExtra(TAG_KATEGORI);
String email = in.getStringExtra(TAG_EMAIL);
  //The  method setvalue would be quite useful for you where you will pass the int j parameter to get appropriate values. If next button is clicked increment the j if previous button is clicked decrement it. and then display your values asusual.
// Displaying all values on the screen
lblNamatoko = (TextView) findViewById(R.id.namatoko);
lblKategori = (TextView) findViewById(R.id.kategori);
lblEmail = (TextView) findViewById(R.id.textemail);

lblNamatoko.setText(nama_toko);
lblKategori.setText(kategori);
lblEmail.setText(email);
 HashMap<String, String> detail = new HashMap<String, String>();
    detail = data.get(currentPosition);


// Setting all values in listview
nama_toko = detail.get(ListPerusahaan.TAG_NAMATOKO);
kategori = detail.get(ListPerusahaan.TAG_KATEGORI);
email = detail.get(ListPerusahaan.TAG_EMAIL);
 PremiumList = new ArrayList<HashMap<String, String>>();
 HashMap<String, String> list = null;
 int currentposition = 0;
 int  Total_data =0;

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

  //this must be called BEFORE setContentView
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.detail_toko);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

    call_btn=(Button)findViewById(R.id.call);

    email_btn=(Button)findViewById(R.id.email);

    sms_btn=(Button)findViewById(R.id.sms);

    Next_btn=(Button)findViewById(R.id.Next);

    Prev_btn=(Button)findViewById(R.id.Prev);

    phonenumber=(TextView)findViewById(R.id.telpon);

// Displaying all values on the screen
    lblPosisi = (TextView) findViewById(R.id.namatoko);
    lbltotaldata = (TextView) findViewById(R.id.nama);
    lblNamatoko = (TextView) findViewById(R.id.nama_toko);
    lblKategori = (TextView) findViewById(R.id.kategori);
    lblEmail = (TextView) findViewById(R.id.textemail);

    // getting intent data
   Bundle bundle = getIntent().getExtras();
// Get Int values from previous intent
    currentposition =  bundle.getInt("position");
      Total_data =  bundle.getInt("TotalData");
    list =  (HashMap<String, String>) bundle.get("PremiumList");
    setView();
    Next_btn.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v){  
        if(currentposition >= Total_data - 1)
          {
              Toast toast= Toast.makeText(getApplicationContext(), "Last Record", Toast.LENGTH_SHORT);  
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
              toast.show();
          }
          else
          {
             currentposition++;
             setView();
          }
        }
      });


    Prev_btn.setOnClickListener(new Button.OnClickListener(){
      public void onClick(View v){  

          if(currentposition <= 0)
          {
              Toast toast= Toast.makeText(getApplicationContext(), "First Record", Toast.LENGTH_SHORT);  
              toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
              toast.show();
          }
          else
          {
              currentposition--;
              setView();
          }
        }
     });

     private void setView()
     {
     if(list != null && list.size() > currentposition)
     {
     HashMap<String, String> detail = new HashMap<String, String>();
    detail = list.get(currentposition);
     lblPosisi.setText(String.valueOf(currentposition));
    lbltotaldata.setText(String.valueOf(Total_data));
    lblNamatoko.setText(detail.get(ListPerusahaan.TAG_NAMATOKO));
    lblKategori.setText(detail.get(ListPerusahaan.TAG_KATEGORI));
    lblEmail.setText(detail.get(ListPerusahaan.TAG_EMAIL));
    }
    }