0

我在这个 click_screen 上放置了点击事件

<TextView
        android:id="@+id/textView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:onClick="click_screen" />

另一个活动的 .java 文件 (click_screen)

public void click_screen(View v)
{
    Intent click_screen=new Intent(this, MainActivity.class);
    startActivity(click_screen);
}

MainActivity.java

package com.amcct.amcostapp;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;

public class MainActivity extends Activity 
{

    @SuppressLint("NewApi")
    protected void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

/*  @Override
    public boolean onTouchEvent(MotionEvent event) 
    {
        if (event.getAction() == MotionEvent.ACTION_DOWN) 
        {
            Intent click_screen=new Intent(this, MainActivity.class);
            startActivity(click_screen);
        }

        return super.onTouchEvent(event);
    }*/

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    public void click_screen(View v)
    {
        Intent click_screen=new Intent(this, MainActivity.class);
        startActivity(click_screen);
    }
}

==================================================== =================== .xml 当我点击任何地方时它会在 click_screen 上方生成 ^^

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:onClick="click_screen"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Click_Page"
    android:background="@drawable/img_1" >

</RelativeLayout>

看到这个我的所有文件....

4

5 回答 5

0

尝试设置onClick您的 xml 的父视图。就像是。-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:onClick="click_screen" >

...

</RelativeLayout>

或者只是像这样覆盖onTouchEvent。-Activity

public boolean onTouchEvent(MotionEvent event) {
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        Intent click_screen=new Intent(this, MainActivity.class);
        startActivity(click_screen);
    }

    return super.onTouchEvent(event);
}
于 2013-09-13T17:28:28.423 回答
0
## Please add clickable property ##
 <TextView
    android:id="@+id/textView1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:text="Click Me"
    android:clickable="true" 
    android:onClick="click_screen" />
于 2013-09-13T21:01:31.517 回答
0

您的代码在 MainActivity 中,并且通过意图您再次尝试转到 MainActivity.class?指定您要参加的活动,例如:

Intent click_screen=new Intent(MainActivity.this, nextActivity.class);
    startActivity(click_screen);
于 2013-09-13T19:25:54.473 回答
0

Myabe 你可以试试这个代码,我做 textview.setClickable(true)

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    final TextView textView = (TextView)findViewById(R.id.textView1);
    textView.setClickable(true);
    textView.setOnClickListener(this);
}

@Override
public void onClick(View view) {
    startActivity(new Intent(this, MainActivity.class));
}
于 2013-09-13T18:10:41.727 回答
0

当单击屏幕上的任何位置时,您想移动到不同的活动?那么为什么要在该 textview 上设置 onclick?在顶部相对布局/线性布局上设置 onclick 属性,而不是在 textview 上设置。

于 2013-09-13T18:10:55.670 回答