|
 |
|
Android รบกวนสอบถามเรื่อง ช่องค้นหา ใน listview ค้นหาเจอเรียบร้อยแต่เรียก intent ขึ้นมา ขึ้นแค่คราสเดียวครับ |
|
 |
|
|
 |
 |
|
คือค้นหาได้แล้ว แต่ติดอยู่ที่ว่า พอค้นหาเสร็จ เข้าอันไหนก็จะขึ้นแต่ park.class อย่างเดียวครับไม่ทราบว่าติดตรงไหน ช่วยหน่อยนะครับ
ขอบคุณทุกคำตอบครับผม
Code (Android-Java)
package com.example.bangkoktravel;
import java.util.ArrayList;
import android.os.Bundle;
import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.app.Activity;
import android.content.Intent;
public class Main extends Activity {
EditText editText1;
ListView listView1;
ArrayList<String> arr_list;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
arr_list = new ArrayList<String>();
arr_list.add("สวนสาธารณะร่มรื่น");
arr_list.add("ห้างสรรพสินค้าแหล่งช้อปปิ้ง");
arr_list.add("ร้านอาหารสุดหรูบนโรงแรม");
arr_list.add("พิพิธภัณฑ์แหล่งความรู้");
arr_list.add("วัดวาอาราม");
arr_list.add("ตลาดน่าท่องเที่ยว");
listView1 = (ListView)findViewById(R.id.listView1);
listView1.setAdapter(new ArrayAdapter(this
, android.R.layout.simple_list_item_1, arr_list));
listView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0
, View arg1, int arg2, long arg3) {
Intent intent;
switch(arg2) {
case 0 :
intent = new Intent(getApplicationContext()
, Park.class);
startActivity(intent);
break;
case 1 :
intent = new Intent(getApplicationContext()
, Store.class);
startActivity(intent);
break;
case 2 :
intent = new Intent(getApplicationContext()
, Hotel.class);
startActivity(intent);
break;
case 3 :
intent = new Intent(getApplicationContext()
, Museum.class);
startActivity(intent);
break;
case 4 :
intent = new Intent(getApplicationContext()
, Temple.class);
startActivity(intent);
break;
case 5 :
intent = new Intent(getApplicationContext()
, Market.class);
startActivity(intent);
break;
}
editText1 = (EditText)findViewById(R.id.editText1);
editText1.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable arg0) {
ArrayList<String> src_list =
new ArrayList<String>();
int textlength = editText1.getText().length();
for(int i = 0 ; i < arr_list.size() ; i++){
try {
if(editText1.getText().toString()
.equalsIgnoreCase(arr_list.get(i)
.subSequence(0, textlength)
.toString())){
src_list.add(arr_list.get(i));
}
} catch (Exception e) { }
}
listView1.setAdapter(new ArrayAdapter(Main.this
, android.R.layout.simple_list_item_1
, src_list));
}
public void beforeTextChanged(CharSequence s, int start
, int count, int after) { }
public void onTextChanged(CharSequence s, int start
, int before, int count) { }
});
}
});
}
}
Tag : Java, Android, Mobile

|
|
 |
 |
 |
 |
Date :
2014-06-20 19:44:43 |
By :
maytoey |
View :
1353 |
Reply :
4 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอภาพประกอบครับ
|
 |
 |
 |
 |
Date :
2014-06-21 08:59:00 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
http://upload.sodazaa.com/share.php?id=9492_53A599CD
|
 |
 |
 |
 |
Date :
2014-06-21 21:31:48 |
By :
mie_jintana_1020 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|

ตัวอย่างหน้าค้นหาค่ะ ปัญหาเหมือนกันเลยนะ
|
 |
 |
 |
 |
Date :
2014-06-21 21:34:07 |
By :
mie_jintana_1020 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ลอง debug ดูแล้วยังครับว่าค่า arg2 ที่ส่งเข้ามาที่ method onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3)
มีค่าเป็นอะไร
อีกทีก็ลองเปลี่ยนจาก switch(arg2) เป็น switch (arg1.getId()) ดูครับ
|
 |
 |
 |
 |
Date :
2014-06-24 18:31:47 |
By :
binary.prep |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|