 |
Android รบกวนสอบถามขอคำปรึกษา เรื่อง การใช้ while loop เพื่อเช็ค ข้อมูลที่ซ้ำกันใน listview หน่อยค่ะ |
|
 |
|
|
 |
 |
|
สวัสดีค่ะ คือหนูต้องการใช้ while loop เพื่อเช็ค ข้อมูลที่ซ้ำกันใน listview หน่อยค่ะ
ทำพอดีว่าทำโปรเจคจบเกี่ยวกับ การต่อสายรถ สองแถว นะค่ะ รบกวนทุกๆคน ช่วยให้คำปรึกษา คำแนะนำ ด้วยนะคะ
________---------------------_________
*****โค้ด หน้านี้****** เป็นหน้าที่ใช้เพื่อเช็คข้อมูลทั้ง 2 listview ว่ามี ปลายทางไหน ที่ต้องต่อสายรถ นะคะ
Code (Android-Java)
try {
//ปลายทาง
mCursor = mDb.rawQuery("select bus.name,bus.id_bus, place.name_place, bus.picture from bus left join place_bus on place_bus.id_bus = bus.id_bus left join place on place_bus.id_place = place.id_place where name_place =" + "\"" + message + "\"", null);//" + "\"" + message + "\""
final ArrayList<String> dirArray = new ArrayList<String>();
final ArrayList<String> dirArray3 = new ArrayList<String>();
mCursor.moveToFirst();
while (mCursor.isAfterLast() == false) {
dirArray.add("ee " + mCursor.getString(mCursor.getColumnIndex(MyDatabase.COL_NAMEB)));
dirArray3.add(mCursor.getString(mCursor.getColumnIndex(MyDatabase.COL_ID_BUS)));
mCursor.moveToNext();
}
if (dirArray.size()==0) {
Toast.makeText(context, "ไม่มีข้อมูลในฐานข้อมูล", Toast.LENGTH_SHORT).show();
textView.setText("****"+dirArray);
}
final ArrayAdapter<String> adapterDir = new ArrayAdapter<String>(getApplicationContext()
, android.R.layout.simple_list_item_1, dirArray);
listView1.setAdapter(adapterDir);
listView1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent newActivity = new Intent(getApplicationContext(), Detil_say1.class);
newActivity.putExtra("ID_BUS", dirArray3.get(position));
startActivity(newActivity);
}
});
//select bus.name, place.name_place from bus left join place_bus on place_bus.id_bus = bus.id_bus left join place on place_bus.id_place = place.id_place where
// name_place =
//check ต้นทาง
mCursor1 = mDb.rawQuery("select bus.name, place.name_place from bus left join place_bus on place_bus.id_bus = bus.id_bus left join place on place_bus.id_place = place.id_place where name_place = " + "\"" + Name + "\"", null);
final ArrayList<String> dirArray1 = new ArrayList<String>();
final ArrayList<String> dirArray2 = new ArrayList<String>();//id ไปหน้า map เพื่อเปิดแผนที่
mCursor1.moveToFirst();
while (mCursor1.isAfterLast() == false) {
dirArray1.add("ww" + mCursor1.getString(mCursor1.getColumnIndex(MyDatabase.COL_NAMEB)));
dirArray2.add(mCursor1.getString(mCursor1.getColumnIndex(MyDatabase.COL_ID_BUS)));
mCursor1.moveToNext();
}
if (dirArray1.size() == 0) {
Toast.makeText(context, "ไม่มีข้อมูลในฐานข้อมูล", Toast.LENGTH_SHORT).show();
textView.setText("ต้นทาง");
}
final ArrayAdapter<String> adapterDir1 = new ArrayAdapter<String>(getApplicationContext()
, android.R.layout.simple_list_item_1, dirArray1);
listView2.setAdapter(adapterDir1);
listView2.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent newActivity = new Intent(getApplicationContext(), Detil_say2.class);
newActivity.putExtra("id_bus", dirArray2.get(position));
startActivity(newActivity);
}
});
} catch (Exception e) {
//Toast.makeText(context, "No Data", Toast.LENGTH_SHORT).show();
}
Tag : Java, Ms SQL Server 2005, Android
|
|
 |
 |
 |
 |
Date :
2015-04-03 14:19:33 |
By :
Z_zoo |
View :
1258 |
Reply :
6 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ดูแล้วงง ครับ แต่ถ้าอยากเอาข้อมูลซ้ำกัน เขียนบน Query เลยครับ ใช้พวก GROUP BY ครับ
|
 |
 |
 |
 |
Date :
2015-04-03 20:01:29 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ขอบคุณค่ะ
แล้วพอจะมีวิธีแนะนำ เรื่องการ ต่อสายรถ บ้างไหมค่ะ
|
 |
 |
 |
 |
Date :
2015-04-04 13:26:57 |
By :
Z_zoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต่อผ่านอะไรครับ USB ?
|
 |
 |
 |
 |
Date :
2015-04-04 19:50:19 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
อ่อไม่ใช่แบบนั้นคะ พอดีว่าหนูทำโปรเจคจบ เป็นแอพพลิเคชั่นตัวหนึ่งที่รองรับบนสมาร์ทโฟน คือเมื่อผู้ใช้กรอกปลายทาง แล้วแอพฯ จะแสดงมาให้ผู้ใช้ ได้ทราบว่า ปลายที่ผู้ใช้ ต้องการจะไป มีการต่อสายรถหรือไม่ ถ้ามีจะแสดง สายรถที่ต้องต่อมาให้นะคะ ตอนนี้หนูสามารถแสดง ต้นทาง และปลายทางได้แล้ว แต่เหลือนำปลายทาง มาเช็ค ว่าจะต้องต่อสายรถหรือไหม รบกวนพี่แนะนำวิธีการให้หน่อยคะ ขอบคุณคะ
|
 |
 |
 |
 |
Date :
2015-04-05 22:10:13 |
By :
Z_zoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ข้อมูลสายรถ มาจากไหนครับ 
|
 |
 |
 |
 |
Date :
2015-04-06 07:34:28 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ต่อยอดจากรุ่นพี่ค่ะ ข้อมูลก็เอาต่อจากของพี่เลยคะ แต่ก็มีบางส่วนบางสาย ที่ไปขอมาจาก ขนส่ง คะ
|
 |
 |
 |
 |
Date :
2015-04-06 09:47:39 |
By :
Z_zoo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|