[สอบถาม] การ Intent หน้าจาก Listview ไปหน้าอื่นๆ [Android]
Code (Android-Java)
lisView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> myAdapter, View myView, int position, long mylng) {
// Show on new activity
Intent newActivity = new Intent(ListUpdateActivity.this,UpdateActivity.class);
newActivity.putExtra("MemID", MebmerList.get(position).get("MemberID").toString());
startActivity(newActivity);
}
});
Android Edit Update Data in SQLite Database (Android SQLite)
Date :
2014-03-01 11:04:44
By :
mr.win
เอาโค้ด listView คุณมาแปะไว้ครับ จะช่วย guide ให้ครับ
Date :
2014-03-01 14:10:20
By :
tutordroid.com
Code (JavaScript)
package com.harvestmoon;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
public class ActivityForm2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form2);
final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
/*** Rows 1 ***/
map = new HashMap<String, String>();
map.put("ImageID", "ข้าวโพดอ่อน");
map.put("ImageDesc", "30 บาท/ซอง");
map.put("ImagePath", "corn");
MyArrList.add(map);
/*** Rows 2 ***/
map = new HashMap<String, String>();
map.put("ImageID", "ฝักแฝง ");
map.put("ImageDesc", "25 บาท/ซอง");
map.put("ImagePath", "feng");
MyArrList.add(map);
/*** Rows 3 ***/
map = new HashMap<String, String>();
map.put("ImageID", "ฝักทอง ");
map.put("ImageDesc", "50 บาท/ซอง");
map.put("ImagePath", "fuck");
MyArrList.add(map);
/*** Rows 4 ***/
map = new HashMap<String, String>();
map.put("ImageID", "โพระหา ");
map.put("ImageDesc", "35 บาท/ซอง");
map.put("ImagePath", "ho");
MyArrList.add(map);
/*** Rows 5 ***/
map = new HashMap<String, String>();
map.put("ImageID", "กระเพรา ");
map.put("ImageDesc", "40 บาท/ซอง");
map.put("ImagePath", "kra");
MyArrList.add(map);
/*** Rows 6 ***/
map = new HashMap<String, String>();
map.put("ImageID", "พริกขี้หนู ");
map.put("ImageDesc", "15 บาท/ซอง");
map.put("ImagePath", "prik");
MyArrList.add(map);
/*** Rows 7 ***/
map = new HashMap<String, String>();
map.put("ImageID", "มะเขือเปราะ ");
map.put("ImageDesc", "45 บาท/ซอง");
map.put("ImagePath", "proue");
MyArrList.add(map);
/*** Rows 8 ***/
map = new HashMap<String, String>();
map.put("ImageID", "ผัดสลัด ");
map.put("ImageDesc", "20 บาท/ซอง");
map.put("ImagePath", "salad");
MyArrList.add(map);
// listView1
final ListView lstView1 = (ListView)findViewById(R.id.listView1);
lstView1.setAdapter(new ImageAdapter(this,MyArrList));
lstView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
}
});
}
public class ImageAdapter extends BaseAdapter
{
private Context context;
private ArrayList<HashMap<String, String>> MyArr = new ArrayList<HashMap<String, String>>();
public ImageAdapter(Context c, ArrayList<HashMap<String, String>> list)
{
// TODO Auto-generated method stub
context = c;
MyArr = list;
}
public int getCount() {
// TODO Auto-generated method stub
return MyArr.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.activity_column, null);
}
// ColImage
ImageView imageView = (ImageView) convertView.findViewById(R.id.ColImgPath);
imageView.getLayoutParams().height = 100;
imageView.getLayoutParams().width = 100;
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
int ResID = context.getResources().getIdentifier(MyArr.get(position).get("ImagePath"), "drawable", context.getPackageName());
imageView.setImageResource(ResID);
// ColPosition
TextView txtPosition = (TextView) convertView.findViewById(R.id.ColImgID);
txtPosition.setPadding(10, 0, 0, 0);
txtPosition.setText("ชื่อ : " + MyArr.get(position).get("ImageID"));
// ColPicname
TextView txtPicName1 = (TextView) convertView.findViewById(R.id.ColImgDesc);
txtPicName1.setPadding(50, 0, 0, 0);
txtPicName1.setText("ราคา : " + MyArr.get(position).get("ImageDesc"));
return convertView;
}
}
}
Date :
2014-03-02 00:15:34
By :
reason01
put ชื่อคลาสเข้าไปใน Rows1-2-3-4...
ใน lstView1.setOnItemClickListener ก็ Intent ชื่อคลาสที่กดครับ
Date :
2014-03-02 11:20:09
By :
tutordroid.com
แล้วจะดึงไปใช้ใน Intent ยังไงหรอครับ ผมงงจริงๆ
รบกวนหน่อยนะครับ ไม่รู้จริงๆ
Date :
2014-03-02 18:56:46
By :
reason01
Code (Android-Java)
map.put("Class","1");
lstView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
if(MyArrList.get(position).get("ClassName").equal("1")){
Intent i = new Intent(คลาสปัจจุบัน.this, ชื่อคลาสที่จะไป.class);
startActivity(i);
}
}
});
ลองดูครับ ประมาณนี้แหละ
ประวัติการแก้ไข 2014-03-02 22:37:39
Date :
2014-03-02 22:35:18
By :
tutordroid.com
ตอบความคิดเห็นที่ : 8 เขียนโดย : tutordroid.com เมื่อวันที่ 2014-03-02 22:35:18
รายละเอียดของการตอบ ::
Code (JavaScript)
package com.harvestmoon;
import java.util.ArrayList;
import java.util.HashMap;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
public class ActivityForm2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_form2);
final ArrayList<HashMap<String, String>> MyArrList = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map;
/*** Rows 1 ***/
map = new HashMap<String, String>();
map.put("ImageID", "ข้าวโพดอ่อน");
map.put("ImageDesc", "30 บาท/ซอง");
map.put("ImagePath", "corn");
map.put("Class", "1");
MyArrList.add(map);
/*** Rows 2 ***/
map = new HashMap<String, String>();
map.put("ImageID", "ฝักแฝง ");
map.put("ImageDesc", "25 บาท/ซอง");
map.put("ImagePath", "feng");
map.put("Class", "2");
MyArrList.add(map);
/*** Rows 3 ***/
map = new HashMap<String, String>();
map.put("ImageID", "ฝักทอง ");
map.put("ImageDesc", "50 บาท/ซอง");
map.put("ImagePath", "fuck");
map.put("Class", "3");
MyArrList.add(map);
/*** Rows 4 ***/
map = new HashMap<String, String>();
map.put("ImageID", "โพระหา ");
map.put("ImageDesc", "35 บาท/ซอง");
map.put("ImagePath", "ho");
map.put("Class", "4");
MyArrList.add(map);
/*** Rows 5 ***/
map = new HashMap<String, String>();
map.put("ImageID", "กระเพรา ");
map.put("ImageDesc", "40 บาท/ซอง");
map.put("ImagePath", "kra");
map.put("Class", "5");
MyArrList.add(map);
/*** Rows 6 ***/
map = new HashMap<String, String>();
map.put("ImageID", "พริกขี้หนู ");
map.put("ImageDesc", "15 บาท/ซอง");
map.put("ImagePath", "prik");
map.put("Class", "6");
MyArrList.add(map);
/*** Rows 7 ***/
map = new HashMap<String, String>();
map.put("ImageID", "มะเขือเปราะ ");
map.put("ImageDesc", "45 บาท/ซอง");
map.put("ImagePath", "proue");
map.put("Class", "7");
MyArrList.add(map);
/*** Rows 8 ***/
map = new HashMap<String, String>();
map.put("ImageID", "ผัดสลัด ");
map.put("ImageDesc", "20 บาท/ซอง");
map.put("ImagePath", "salad");
map.put("Class", "8");
MyArrList.add(map);
// listView1
final ListView lstView1 = (ListView)findViewById(R.id.listView1);
lstView1.setAdapter(new ImageAdapter(this,MyArrList));
lstView1.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v,int position, long id) {
if(MyArrList.get(position).get("ClassName").equals("1")){
Intent newActivity = new Intent(ActivityForm2.this,Corn.class);
startActivity(newActivity);
}
else if(MyArrList.get(position).get("ClassName").equals("2")){
Intent newActivity = new Intent(ActivityForm2.this,Feng.class);
startActivity(newActivity);
}
else if(MyArrList.get(position).get("ClassName").equals("3")){
Intent newActivity = new Intent(ActivityForm2.this,Fuck.class);
startActivity(newActivity);
}
else if(MyArrList.get(position).get("ClassName").equals("4")){
Intent newActivity = new Intent(ActivityForm2.this,Ho.class);
startActivity(newActivity);
}
else if(MyArrList.get(position).get("ClassName").equals("5")){
Intent newActivity = new Intent(ActivityForm2.this,Kra.class);
startActivity(newActivity);
}
else if(MyArrList.get(position).get("ClassName").equals("6")){
Intent newActivity = new Intent(ActivityForm2.this,Chilli.class);
startActivity(newActivity);
}
else if(MyArrList.get(position).get("ClassName").equals("7")){
Intent newActivity = new Intent(ActivityForm2.this,Proue.class);
startActivity(newActivity);
}
else if(MyArrList.get(position).get("ClassName").equals("8")){
Intent newActivity = new Intent(ActivityForm2.this,Salad.class);
startActivity(newActivity);
}
}
});
}
public class ImageAdapter extends BaseAdapter
{
private Context context;
private ArrayList<HashMap<String, String>> MyArr = new ArrayList<HashMap<String, String>>();
public ImageAdapter(Context c, ArrayList<HashMap<String, String>> list)
{
// TODO Auto-generated method stub
context = c;
MyArr = list;
}
public int getCount() {
// TODO Auto-generated method stub
return MyArr.size();
}
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = inflater.inflate(R.layout.activity_column, null);
}
// ColImage
ImageView imageView = (ImageView) convertView.findViewById(R.id.ColImgPath);
imageView.getLayoutParams().height = 100;
imageView.getLayoutParams().width = 100;
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
int ResID = context.getResources().getIdentifier(MyArr.get(position).get("ImagePath"), "drawable", context.getPackageName());
imageView.setImageResource(ResID);
// ColPosition
TextView txtPosition = (TextView) convertView.findViewById(R.id.ColImgID);
txtPosition.setPadding(10, 0, 0, 0);
txtPosition.setText("ชื่อ : " + MyArr.get(position).get("ImageID"));
// ColPicname
TextView txtPicName1 = (TextView) convertView.findViewById(R.id.ColImgDesc);
txtPicName1.setPadding(50, 0, 0, 0);
txtPicName1.setText("ราคา : " + MyArr.get(position).get("ImageDesc"));
return convertView;
}
}
}
ประมาณนี้หรอครับ แต่เวลาคลิกแล้วมันขึ้น unfortable
Date :
2014-03-03 15:53:18
By :
reason01
Code (Android-Java)
if(MyArrList.get(position).get("Class").equals("1")){
}
แล้วก็ New Class Corn.java, Feng.java, Fuck.java ครับ
Date :
2014-03-03 21:45:25
By :
tutordroid.com
ใช้ Intent เหมือนกัน โดย put data เข้าไปด้วยครับ ตัวอย่างในเว็บนี้มีครับ
Date :
2014-03-05 23:56:05
By :
tutordroid.com
รบกวนหน่อยนะค่ะ อยากทราบว่าถ้าเราออกแบบหน้าจอแบบนี้ แล้วต้องการกด
listView ที่ 1 แล้วให้ไปแสดงผลอีก Activity นึง และ กด listView ที่ 2 3 4.... ก็ให้ไปอีก Activity นึง จะต้องใส่โค้ดแบบไหนค่ะ อ่านกระทู้อื่นแล้วเค้างง คัยรู้บอกหน่อยนร่าา
Date :
2014-11-04 14:36:00
By :
mmmm
Load balance : Server 05