View Full Version : مشکل با gridview
sahar_mrd69
شنبه 19 اردیبهشت 1394, 10:23 صبح
سلام دوستان من توی پروژم از gridview استفاده کردم حالا میخوام با کلیک روی هر آیتم به activity دیگه بره.از دستور swich استفاده میکنم اما نمیدونم چرا عمل نمیکنه.میخوام به جای نمایش اون tost به اکتیویتی دیگری برود.دقیقا چه کدی رو باید بزنم راهنمایی کنید ممنون میشم
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// Toast.makeText(ProjectsActivity.this, "You Clicked at " + web[ +position], Toast.LENGTH_SHORT).show();
}
});
parniaznet
شنبه 19 اردیبهشت 1394, 10:44 صبح
سلام
وقت بخیر
grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
Intent intent = new Intent(jaekehasti.this, jaekemikhayberi.class);
startActivity(intent);
}
});
sahar_mrd69
شنبه 19 اردیبهشت 1394, 10:49 صبح
خب من الان میخوام با کلیلک روی هر آیتم به یک اکتیویتی خاص بره.ولی این فقط واسه یه اکتیویتی میشه
parniaznet
شنبه 19 اردیبهشت 1394, 10:50 صبح
از دستور if می تونی استفاده کنی از سویچ هم میتونی استفاده کنی :
if (position==1) {
Intent intent = new Intent(MainActivity.this, Register.class);
startActivity(intent);
} else if (position==2) {
Intent intent = new Intent(MainActivity.this, Login.class);
startActivity(intent);
}else if (position==3) {
Intent intent = new Intent(MainActivity.this, Favorites.class);
startActivity(intent);
}else if (position==4) {
Intent intent = new Intent(MainActivity.this, Yaddasht.class);
startActivity(intent);
}else if (position==5) {
Intent intent = new Intent(MainActivity.this, Setting.class);
startActivity(intent);
}else if (position==6) {
Intent intent = new Intent(MainActivity.this, About_us.class);
startActivity(intent);
}else if (position==7) {
Intent intent = new Intent(MainActivity.this, Contact_us.class);
startActivity(intent);
} else {
Toast.makeText(MainActivity.this, "به زودی فعال خواهد شد", Toast.LENGTH_SHORT).show();
}
parniaznet
شنبه 19 اردیبهشت 1394, 10:51 صبح
position بهت میگه رو ایتم چندمی کلیک شده
sahar_mrd69
شنبه 19 اردیبهشت 1394, 10:53 صبح
مرسی.swich چه طور میشه؟
iman0111
شنبه 19 اردیبهشت 1394, 11:05 صبح
سلام به این شکل عمل کن
switch (position) {
case 0:
Intent send = new Intent(context.this,otheractivity.class);
startActivity(send);
break;
case 1:
Intent send = new Intent(context.this,otheractivity.class);
startActivity(send);
break;
case 2:
Intent send = new Intent(context.this,otheractivity.class);
startActivity(send);
break;
case 3:
Intent send = new Intent(context.this,otheractivity.class);
startActivity(send);
break;
default:
break;
}
شرح عمل این دستور به این صورته که براساس مقدار position لیستت کار میکنه مثلا اگه position برابر باشه با 0 توی دستور Switch مقادیر case 0 اجرا میشه و همینطور تا الا اخر
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.