制作活动touchScreen

时间:2012-06-02 09:10:24

标签: android

在我的应用程序中,我正在显示一个启动画面,我想制作触摸屏并显示下一个活动。我是初学者请帮帮我

package com.integrated.mpr;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SensitiveFinalActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */

    Button startSensitive;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    }
}

5 个答案:

答案 0 :(得分:2)

在oncreate()方法中添加此

LinearLayout layout = (LinearLayout) findViewById(R.id.layout);//In your xml file, main xml  layout android:id="@+id/layout" 
layout.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            Intent i=new Intent(SensitiveFinalActivity.this,YourSecondActivity.class);  
            startActivity(i);
            finish();
           }
 }

此处您的第二个活动是您想要从启动画面进入的活动

答案 1 :(得分:1)

内部onCreate() ::

 LinearLayout layout = (LinearLayout) findViewById(R.id.layout);//In your xml file, main xml layout android:id="@+id/layout" 
 layout.setOnClickListener(this);  

添加onclick方法

@Override
public void onClick(View arg0) {
      Intent intent = new Intent(this, NewActivityToStart.class);
      startActivity(intent);
}

答案 2 :(得分:1)

试试这个,它会在一段时间内显示启动画面或在触摸时退出

Thread mSplashThread = new Thread() {
        @Override
        public void run() {
            try {
                synchronized (this) {
                    // Wait given period of time or exit on touch
                    wait(3000);//ms

                }
            } catch (InterruptedException ex) {
            }
            startActivity(new Intent(getApplicationContext(),
                    YOUR_ACTIVITY.class));
            finish();

        }
    };
    mSplashThread.start();
}

答案 3 :(得分:0)

你是正确的方式。您只需添加onClick方法并开始下一个活动:

@Override
public void onClick(View v) {
  // Start next activity
}

答案 4 :(得分:0)

package com.integrated.mpr;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class SensitiveFinalActivity extends Activity implements OnClickListener {
    /** Called when the activity is first created. */

    Button startSensitive;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    }
    @Override
public void onClick(View v) {
    // TODO Auto-generated method stub
     Intent i=new Intent(this,<NewActivity>.class);
        startActivity(i);
        finish();
}
}