リストビューに基づいて次/前のボタンをクリックして次/前の詳細データを表示する関数を作成する方法がわかりません。
これは私がやりたいスクリーンショットです
マイ詳細データアクティビティ、リストビューから次/前のデータを表示する
編集:私はリストビューデータを持っており(xmlパーサーを使用)、データを「Detail_toko.class」と呼ばれる新しいアクティビティに渡します:
List<NameValuePair> paramemeter = new ArrayList<NameValuePair>();
paramemeter.add(new BasicNameValuePair("keyword", "a"));
// paramemeter.add(new BasicNameValuePair("kategori",Category.getSelectedItem().toString()));
XMLParser parser = new XMLParser();
String xml = parser.getXmlFromUrl(URL, paramemeter); // getting XML from URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(TAG_DETAIL);
// 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(TAG_ID, parser.getValue(e, TAG_ID));
map.put(TAG_NAMATOKO, parser.getValue(e, TAG_NAMATOKO));
map.put(TAG_KATEGORI, parser.getValue(e, TAG_KATEGORI));
map.put(TAG_EMAIL, parser.getValue(e, TAG_EMAIL));
map.put(TAG_ICON, parser.getValue(e, TAG_ICON));
// adding HashList to ArrayList
PremiumList.add(map);
}
return null;
}
/**
* Updating parsed JSON data into ListView
* */
list=(ListView)findViewById(R.id.listview);
if(PremiumList.size() > 0)
{
adapter=new LazyAdapterStore(ListPerusahaan.this, PremiumList);
list.setAdapter(adapter);
}
else
{
Toast toast= Toast.makeText(getApplicationContext(), "No data found, enter another keyword", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL|Gravity.CENTER_HORIZONTAL, 0, 0);
toast.show();
}
// Click event for single list row
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// getting values from selected ListItem
String nama_toko = ((TextView) view.findViewById(R.id.nama_toko)).getText().toString();
String kategori = ((TextView) view.findViewById(R.id.kategori)).getText().toString();
String email = ((TextView) view.findViewById(R.id.email)).getText().toString();
PremiumList = new ArrayList<HashMap<String, String>>();
Intent in = new Intent(ListPerusahaan.this, Detail_toko.class);
in.putExtra("PremiumList", PremiumList);
//in.putStringArrayListExtra( "PremiumList", PremiumList );
in.putExtra("position", position);
in.putExtra("TotalData", TotalData);
in.putExtra(TAG_NAMATOKO, nama_toko);
in.putExtra(TAG_KATEGORI, kategori);
in.putExtra(TAG_EMAIL, email);
startActivity(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;
}
編集:そして、これはリストビューアイテムからの詳細データを表示するための私の新しいアクティビティ「Detail_Toko」です:
@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));
}
}
});
問題は、「Detail_toko」アクティビティの次/前のボタンをクリックして、リストビューから次/前の詳細データを表示する関数を作成する方法がわからないことです。誰か助けてください...
少し早いですがお礼を