View Full Version : نحوه ساخت Next برای صفحات کتاب با لمس صفحه
meysam jahedi
یک شنبه 09 آذر 1393, 11:04 صبح
سلام
با دستوراتی که در دو Button در یک کتاب موبایل گذاشتم کاربر با کلیک روی این دو باتون به صفحه قبل و بعد میره ، حالا چطور میشه با تاچ کردن بشه این دستورات رو اجرا کرد و صفحه کتاب رو جلو و عقب برد ؟ با لمس به سمت راست به صفحه عقب و با لمس به چپ به صفحه بعدی هدایت بشه
meysam jahedi
یک شنبه 09 آذر 1393, 13:37 عصر
کلا کسی نظری نداره؟
alireza74
یک شنبه 09 آذر 1393, 14:21 عصر
فکر میکنم هنگام ساخت پروژه باید از اکتیویتی Tabbed activity استفاده کنی
alireza74
یک شنبه 09 آذر 1393, 14:31 عصر
بفرما.اینم از کد:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListen er;
import android.view.Menu;
import android.view.MotionEvent;
public class MainActivity extends Activity {
private GestureDetector gestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gestureDetector = new GestureDetector(new SwipeGestureDetector());
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return super.onTouchEvent(event);
}
private void onLeftSwipe() {
Intent i = new Intent(getApplicationContext(),Left.class);
startActivity(i);
finish();
// Do something
}
private void onRightSwipe() {
Intent i = new Intent(getApplicationContext(),Right.class);
startActivity(i);
finish();
// Do something
}
// Private class for gestures
private class SwipeGestureDetector
extends SimpleOnGestureListener {
// Swipe properties, you can change it to make the swipe
// longer or shorter and speed
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 200;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
try {
float diffAbs = Math.abs(e1.getY() - e2.getY());
float diff = e1.getX() - e2.getX();
if (diffAbs > SWIPE_MAX_OFF_PATH)
return false;
// Left swipe
if (diff > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
MainActivity.this.onLeftSwipe();
// Right swipe
} else if (-diff > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
MainActivity.this.onRightSwipe();
}
} catch (Exception e) {
Log.e("YourActivity", "Error on gestures");
}
return false;
}
}
meysam jahedi
یک شنبه 09 آذر 1393, 14:57 عصر
در
private void onLeftSwipe() {
Intent i = new Intent(getApplicationContext(),Left.class);
startActivity(i);
finish();
// Do something
}
private void onRightSwipe() {
Intent i = new Intent(getApplicationContext(),Right.class);
startActivity(i);
finish();
// Do something
}
نوشتن
Intent i = new Intent(getApplicationContext(),Left.class);
startActivity(i);
finish();
برای چیه ؟
من جاشون پیام toast گذاشتم اما اصلا جواب نداد
alireza74
یک شنبه 09 آذر 1393, 17:00 عصر
Intent i = new Intent(getApplicationContext(),Left.class);
Intent i = new Intent(getApplicationContext(),Right.class);
در اینجا بجای Left و Right باید اسم کلاس خودتون رو بزارید.
اینم پروژش هست .داخل اکلیپس ایمپورت کنید.
http://app-play.ir/sl.rar
dalmif
یک شنبه 09 آذر 1393, 18:23 عصر
واقعا تشکر حق شماست.
ممنونم
meysam jahedi
یک شنبه 09 آذر 1393, 20:32 عصر
Intent i = newIntent(getApplicationContext(),Left.class);
Intent i = newIntent(getApplicationContext(),Right.class);
در اینجا بجای Left و Right باید اسم کلاس خودتون رو بزارید.
اینم پروژش هست .داخل اکلیپس ایمپورت کنید.
http://app-play.ir/sl.rar
جای اینکه این کلاس ها رو باز کنه ، میتونم دستورات برای نمایش صفحات عقب و جلو کتاب رو وارد کنم؟
نمیدونم چرا دستوراتی که توی دکمه های Next و Pre گذاشتم و باهاشون page های کتاب رو عقب جلو میکنم ، توی این دستورات میزارم اتفاقی نمیفته
meysam jahedi
یک شنبه 09 آذر 1393, 21:52 عصر
بفرما.اینم از کد:
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListen er;
import android.view.Menu;
import android.view.MotionEvent;
public class MainActivity extends Activity {
private GestureDetector gestureDetector;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gestureDetector = new GestureDetector(new SwipeGestureDetector());
}
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return super.onTouchEvent(event);
}
private void onLeftSwipe() {
Intent i = new Intent(getApplicationContext(),Left.class);
startActivity(i);
finish();
// Do something
}
private void onRightSwipe() {
Intent i = new Intent(getApplicationContext(),Right.class);
startActivity(i);
finish();
// Do something
}
// Private class for gestures
private class SwipeGestureDetector
extends SimpleOnGestureListener {
// Swipe properties, you can change it to make the swipe
// longer or shorter and speed
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 200;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
public boolean onFling(MotionEvent e1, MotionEvent e2,
float velocityX, float velocityY) {
try {
float diffAbs = Math.abs(e1.getY() - e2.getY());
float diff = e1.getX() - e2.getX();
if (diffAbs > SWIPE_MAX_OFF_PATH)
return false;
// Left swipe
if (diff > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
MainActivity.this.onLeftSwipe();
// Right swipe
} else if (-diff > SWIPE_MIN_DISTANCE
&& Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
MainActivity.this.onRightSwipe();
}
} catch (Exception e) {
Log.e("YourActivity", "Error on gestures");
}
return false;
}
}
واقعا ممنون
ببینید من وقتی صفحات کتاب رو نشون میدم ، در پایین صفحه دوتا دکمه دارم که با دستورات زیر page رو عوض میکنم :
public class matn extends Activity{
private mydatabase mydata;
private SQLiteDatabase mydb;
private String NAME;
private String FASL;
private int page1;
private int page2=1;
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.matn);
mydata=new mydatabase(this);
Bundle ex=getIntent().getExtras();
NAME=ex.getString("name");
FASL=ex.getString("fasl");
page1=Integer.parseInt(ex.getString("page"));
refresh3(page2);
btnnext.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(page2==page1){
Toast.makeText(getApplicationContext(),"صفحه آخر", Toast.LENGTH_SHORT).show();
}else{
page2++;
refresh3(page2);
}
}
});//end btnnext
btnpre.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if(page2==1){
Toast.makeText(getApplicationContext(),"صفحه اول", Toast.LENGTH_SHORT).show();
}else{
page2--;
refresh3(page2);
}
}
});//end btnpre
}//end oncreate
public void refresh3(int p){
mydb=mydata.getReadableDatabase();
Cursor cr=mydb.rawQuery("select * from tbl where fasl='"+FASL+"'and name='"+NAME+"'and page="+p, null);
cr.moveToFirst();
mydb.close();
txtname.setText(NAME);
txtmatn.setText(cr.getString(2).toString());
txtpage.setText(" صفحه"+page2+"از "+page1);
}//end refresh3
حالا میخوام دستوراتی که تو دکمه های btnnext و btnpre گذاشتم رو تو دستوراتی که دوستمون جناب alireza74 (http://barnamenevis.org/member.php?346189-alireza74) گذاشتن جایگزین کنم که با لمس صفحه دستوراتم اجرا بشن ،
چجوری باید بنویسم ؟ چه تغییراتی باید تو دستورات خودم بدم ، آخه وقتی دستوراتی که تو دکمه های btnnext و btnpre گذاشتم رو میبرم اونجا هیچ اتفاقی نمیفته
meysam jahedi
یک شنبه 09 آذر 1393, 22:56 عصر
Intent i = newIntent(getApplicationContext(),Left.class);
Intent i = newIntent(getApplicationContext(),Right.class);
در اینجا بجای Left و Right باید اسم کلاس خودتون رو بزارید.
اینم پروژش هست .داخل اکلیپس ایمپورت کنید.
http://app-play.ir/sl.rar
نمونه برنامه ای که گذاشتی رو ایمپورت کردم به درستی جواب داد ، اما نمیدونم چرا دستوراتی که نوشتید رو توی یکی از اکتیویتی هام مینویسم زمانی که اجرا میکنم هیچ اتفاقی نمیفته انگار ن انگار :گیج:
خب مگه چه فرقی میکنه که اون دستورات اونجا اجرا نمیشه
meysam jahedi
سه شنبه 11 آذر 1393, 17:08 عصر
هیچکس نمیدونه چرا؟
meysam jahedi
جمعه 21 آذر 1393, 19:59 عصر
:گریه::گریه::گریه:
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.